Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct cell
- {
- bool full;
- int near;
- int generation;
- cell()
- :full(false), near(0), generation(0) { };
- cell(bool full)
- :full(full), near(0), generation(0) { };
- void NearCellStatusChanged(bool status)
- {
- if (status == true)
- near++;
- else near--;
- if (near == 3)
- {
- full = true;
- generation++;
- }
- }
- void change_status(bool full_, cell c[][100], int row, int col) //
- {
- full = full_;
- for (int q = -1; q < 2; q++)
- {
- for (int q2 = -1; q2 < 2; q2++)
- {
- if (q == 0 && q2 == 0) //this element
- q2++;
- c[row + q][col + q2].NearCellStatusChanged(full_);
- }
- }
- }
- void delete_check(cell cells[][100], int row, int col)
- {
- if (this->near < 2 || this->near > 3)
- {
- //this->change_status(false, cells, row, col);
- temp_mas_add(row, col);
- this->full = false;
- }
- }
- void temp_mas_add(int row, int col)
- {
- temp_row[i] = row;
- temp_col[i] = col;
- i++;
- }
- static int i;
- static int temp_row[100];
- static int temp_col[100];
- };
- void update(cell c[][100])
- {
- for (int q = 0; q < cell::i; q++)
- {
- c[cell::temp_row[q]][cell::temp_col[q]].change_status(false, c, cell::temp_row[q], cell::temp_col[q]);
- }
- cell::i = 0;
- }
- int main()
- {
- int row[100], col[100];
- cell cells[100][100];
- int i = 0;
- for (i; cin; i++)
- {
- cout << "row: ";
- cin >> row[i];
- cout << "col: ";
- cin >> col[i];
- cout << endl;
- if (row[i] >= 0 && col[i] >= 0) cells[row[i]][col[i]].change_status(true, cells, row[i], col[i]);
- }
- i--;
- int temp[100];
- for (int q = 0; q < i; q++)
- {
- cells[row[q]][col[q]].delete_check(cells, row[q], col[q]);
- }
- update(cells);
- /*
- for (int q = -1; q < i; i++) //pseudo draw
- {
- for (int j = -1; j < i; j++)
- {
- if (cells[row[q]][col[j]].full == true)
- draw;
- }
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement