Advertisement
EzicMan

mazegen(NOT WORKING)

Jun 8th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. struct cell{
  8.     bool hasRW;
  9.     bool hasBW;
  10.     int cellID;
  11.     cell(int cellID){
  12.         hasRW = true;
  13.         hasBW = false;
  14.         this->cellID = cellID;
  15.     }
  16. };
  17.  
  18. vector<vector<cell>> field;
  19. vector<int> idcount;
  20. vector<int> bottomcount;
  21.  
  22. void draw(int x, int y){
  23.     cout << " ";
  24.     for(int i = 0; i < 2*x - 1; i++){
  25.         cout << "_";
  26.     }
  27.     for(int j = 0; j < y; j++){
  28.         cout << endl << "|";
  29.         for(int i = 0; i < x; i++){
  30.             if(field[j][i].hasRW && field[j][i].hasBW){
  31.                 cout << "_|";
  32.             }else if(field[j][i].hasRW){
  33.                 cout << " |";
  34.             }else if(field[j][i].hasBW){
  35.                 cout << "_ ";
  36.             }else{
  37.                 cout << "  ";
  38.             }
  39.         }
  40.         for(int i = 0; i < x; i++){
  41.             cout << " " << field[j][i].cellID << " ";
  42.         }
  43.     }
  44. }
  45.  
  46. void gen(int x, int y){
  47.     for(int j = 0; j < y; j++){
  48.         vector<cell> stroka;
  49.         for(int i = 0; i < x; i++){
  50.             idcount[i] = 0;
  51.             bottomcount[i] = 0;
  52.         }
  53.         if(j == 0){
  54.             for(int i = 0; i < x; i++){
  55.                 cell temp(i);
  56.                 idcount[i]++;
  57.                 stroka.push_back(temp);
  58.             }
  59.         }else{
  60.             stroka = field[j-1];
  61.             for(int i = 0; i < x; i++){
  62.                 stroka[i].hasRW = false;
  63.                 if(stroka[i].hasBW){
  64.                     stroka[i].cellID = -1;
  65.                     stroka[i].hasBW = false;
  66.                 }
  67.             }
  68.             stroka[x-1].hasRW = true;
  69.             int max = stroka[0].cellID;
  70.             for(int i = 0; i < x; i++){
  71.                 if(stroka[i].cellID == -1){
  72.                     stroka[i].cellID = max + 1;
  73.                     idcount[stroka[i].cellID]++;
  74.                     max += 1;
  75.                 }
  76.             }
  77.         }
  78.         for(int i = 0; i < x - 1; i++){
  79.             if(rand() % 2 == 0 && stroka[i+1].cellID != stroka[i].cellID){
  80.                 stroka[i].hasRW = false;
  81.                 stroka[i+1].cellID = stroka[i].cellID;
  82.                 idcount[stroka[i].cellID]++;
  83.             }else{
  84.                 stroka[i].hasRW = true;
  85.             }
  86.             if(rand() % 2 == 0 && idcount[stroka[i].cellID] > bottomcount[stroka[i].cellID] + 1){
  87.                 stroka[i].hasBW = true;
  88.                 bottomcount[stroka[i].cellID]++;
  89.             }
  90.         }
  91.         stroka[x-1].hasRW = true;
  92.         if(rand() % 2 == 0 && idcount[stroka[x-1].cellID] > bottomcount[stroka[x-1].cellID] + 1){
  93.             stroka[x-1].hasBW = true;
  94.             bottomcount[stroka[x-1].cellID]++;
  95.         }
  96.         field.push_back(stroka);
  97.     }
  98.     for(int i = 0; i < x; i++){
  99.         field[y-1][i].hasBW = true;
  100.     }
  101.     /*for(int i = 0; i < x - 1; i++){
  102.         if(field[y-1][i].cellID != field[y-1][i+1].cellID){
  103.             field[y-1][i].hasRW = false;
  104.             field[y-1][i+1].cellID = field[y-1][i].cellID;
  105.         }
  106.     }*/
  107. }
  108.  
  109. int main(){
  110.     srand(time(NULL));
  111.     int x, y;
  112.     cin >> x >> y;
  113.     idcount.resize(x);
  114.     bottomcount.resize(x);
  115.     gen(x,y);
  116.     draw(x,y);
  117.     return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement