Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct cell
  5. {
  6.     bool full;
  7.     int near;
  8.     int generation;
  9.  
  10.     cell()
  11.         :full(false), near(0), generation(0) { };
  12.     cell(bool full)
  13.         :full(full), near(0), generation(0) { };
  14.  
  15.     void NearCellStatusChanged(bool status)
  16.     {
  17.         if (status == true)
  18.             near++;
  19.         else near--;
  20.  
  21.         if (near == 3)
  22.         {
  23.             full = true;
  24.             generation++;
  25.         }
  26.     }
  27.     void change_status(bool full_, cell c[][100], int row, int col) //
  28.     {
  29.         full = full_;
  30.         for (int q = -1; q < 2; q++)
  31.         {
  32.             for (int q2 = -1; q2 < 2; q2++)
  33.             {
  34.                 if (q == 0 && q2 == 0) //this element
  35.                     q2++;
  36.                 c[row + q][col + q2].NearCellStatusChanged(full_);
  37.             }
  38.  
  39.         }
  40.     }
  41.     void delete_check(cell cells[][100], int row, int col)
  42.     {
  43.         if (this->near < 2 || this->near > 3)
  44.         {
  45.             //this->change_status(false, cells, row, col);
  46.             temp_mas_add(row, col);
  47.             this->full = false;
  48.         }
  49.     }
  50.  
  51.     void temp_mas_add(int row, int col)
  52.     {
  53.         temp_row[i] = row;
  54.         temp_col[i] = col;
  55.         i++;
  56.     }
  57.  
  58.     static int i;
  59.     static int temp_row[100];
  60.     static int temp_col[100];
  61. };
  62.  
  63. void update(cell c[][100])
  64. {
  65.     for (int q = 0; q < cell::i; q++)
  66.     {
  67.         c[cell::temp_row[q]][cell::temp_col[q]].change_status(false, c, cell::temp_row[q], cell::temp_col[q]);
  68.     }
  69.     cell::i = 0;
  70. }
  71.  
  72. int main()
  73. {
  74.     int row[100], col[100];
  75.     cell cells[100][100];
  76.     int i = 0;
  77.     for (i; cin; i++)
  78.     {
  79.         cout << "row: ";
  80.         cin >> row[i];
  81.         cout << "col: ";
  82.         cin >> col[i];
  83.         cout << endl;
  84.         if (row[i] >= 0 && col[i] >= 0) cells[row[i]][col[i]].change_status(true, cells, row[i], col[i]);
  85.     }
  86.     i--;
  87.     int temp[100];
  88.     for (int q = 0; q < i; q++)
  89.     {
  90.         cells[row[q]][col[q]].delete_check(cells, row[q], col[q]);
  91.     }
  92.     update(cells);
  93.    
  94.     /*
  95.     for (int q = -1; q < i; i++) //pseudo draw
  96.     {
  97.         for (int j = -1; j < i; j++)
  98.         {
  99.             if (cells[row[q]][col[j]].full == true)
  100.                 draw;
  101.         }
  102.     }
  103.     */
  104.  
  105.  
  106.  
  107.  
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement