// Game of Life, ASCII // Paul Kominsky, summer 2005 #include #include #include using namespace std; int neighbors(vector > table, int ic, int jc) { int N = table.size(); int M = table[0].size(); int ilo=max(ic-1, 0); int jlo=max(jc-1, 0); int ihi=min(ic+1, N-1); int jhi=min(jc+1, M-1); int sum = 0; for (int i=ilo; i<=ihi; i=i+1) { for (int j=jlo; j<=jhi; j=j+1) { sum = sum + table[i][j]; } } return sum - table[ic][jc]; } vector > updateCells(vector > cells) { int N = cells.size(); int M = cells[0].size(); vector > updated(N, M); for (int i=0; i > table, int ng) { system("clear"); cout << "--- " << ng << " ---" << endl; int i=0, j=0; while (i> N >> M; double probOne; cout << " What initial probability of ones? "; cin >> probOne; int numGen; cout << " How many generations? "; cin >> numGen; int seed; cout << " Random seed value? "; cin >> seed; srand(seed); vector > table(N,M); // fill 2D vector with random zeros and ones int i,j; i=0; while (i > tablenew(N,M); int k=0; while (k