/* Game of life, 2d console mode Based on John Conway's coolness. Thx to inspirational Complexity and Stephen by eozl, July 27, 2003 tangledweb.ath.cx/files/source/c/gameoflife.c */ /*** INCLUDES ****/ #include #include #include /*** DEFINES ***/ #define SPANV 35 #define SPANH 60 #define ASC0 48 // ascii value for 0, for stoi() /*** PROTOTYPES ***/ void print (short arr[SPANV][SPANH]); void seed (short arr[SPANV][SPANH], int k); int surround (short arr[SPANV][SPANH], int x, int y); int stoi (char *c); /*** FUNCTIONS ***/ int main(int argc, char *argv[]) { short game [SPANV][SPANH]; short gamed[SPANV][SPANH]; int i,j,k,iter,maxiter; /* COMMAND LINE STF */ static char cmdhelp[]= "Program usage: [-?] this help [-m VALUE] maximum iterations (default 125) \n"; short badflag=0, m=0 ,h=0; // bools for args short printedhelp=0; // so we dont print help multiple times... if (argc>1) { // if there are any args for (i=1;i= (SPANV - 1)) bottom=1; if (y<=0) left=1; if (y>= (SPANH - 1)) right=1; //printf("top %d, bottom %d, left %d, right %d\n\n",top,bottom,left,right); //return -1; int n=0; //comments n,s,w,e=north/south/west/east etc. //nw. check here only if its not top and not left if (!top && !left) { if (arr[x-1][y-1]) {n++;} } if (!top) { if (arr[x-1][y]) //n {n++;} } if (!top && !right) { if (arr[x-1][y+1]) //ne {n++;} } if (!left) { if (arr[x][y-1]) //w {n++;} } if (!right) { if (arr[x][y+1]) //e {n++;} } if(!bottom && !left){ if (arr[x+1][y-1]) {n++;} } if (!bottom) { if (arr[x+1][y]) {n++;} } if (!bottom && !right) { if (arr[x+1][y+1]) {n++;} } return n; } // seed the virgin board with start spark void seed(short arr[SPANV][SPANH], int k) { int i; switch (k) { case 1: // 3 vertical dots arr[SPANV/2][SPANH/2]=1; arr[SPANV/2+1][SPANH/2]=1; arr[SPANV/2-1][SPANH/2]=1; break; case 2: //test deal arr[SPANV/2][SPANH/2]=1; arr[SPANV/2][SPANH/2+1]=1; arr[SPANV/2+1][SPANH/2]=1; arr[SPANV/2+1][SPANH/2+1]=1; arr[SPANV/2+1][SPANH/2+2]=1; break; case 3: //"r-pentomino" arr[SPANV/2][SPANH/2]=1; arr[SPANV/2+1][SPANH/2]=1; arr[SPANV/2-1][SPANH/2]=1; arr[SPANV/2][SPANH/2-1]=1; arr[SPANV/2-1][SPANH/2+1]=1; break; case 4: //horiz line of __ length for (i=SPANH/2-12;i