#include using namespace std; #include"CursWin.h" const int width = 20; const int height = 20; int main(){ CursWin outwin(0,0,height+1,width+1); int array[height][width]; int temp[height][width]; int count; for(int i =0; i < height; i++){ for(int j =0; j < width; j++){ array[i][j] = rand()%2; // 0 or 1 temp[i][j] = 0; // start temp with all zeros } } while(1==1){ // print an array for(int i =0; i < height; i++){ for(int j =0; j < width; j++){ outwin << Cmove(i,j) << array[i][j]; } } // create the temp array for(int i = 1; i < height; i++){ for(int j = 1; j < width; j++){ // need to count neighbors count = 0; count += array[i-1][j-1]; count += array[i][j-1]; // ... if(count == 3){ temp[i][j] = 1; } if(count == 2){ temp[i][j] = array[i][j]; } if(count != 3 && count != 2){ temp[i][j] = 0; } } } // copy back to the original array for(int i = 0; i < height; i++){ for(int j = 0; j < width; j++){ array[i][j] = temp[i][j]; } } outwin << cflush; } int x; outwin >> x; }