//acadlife.cpp //(c) 1997, Oguz Yetkin //physics 505 //revised 2/1998 for phys499 // //Implements "academic life" where cells interact with "colleagues" //otherwise, rules are the same as life (unless otherwise specified) // //Game of life, and other good stuff //#include "graph.h" #include //will have to use borland c++ graphics directly :( //for getpixel and putpixel #include #include #include #include //for exit #include const int GEN=2; //number of generations to keep+ 1 reserved layer //(the GENth layer) for neighbor index //const int I=70; //const int J=70; const int I=40; const int J=30; const int NEIGHBORS_PER_CELL=8; //we are no longer limited by geometry #define NUM_CELLS I * J const int offset=20; //offset to plot struct point{ int i; int j; }; struct neighlist{ point list[NEIGHBORS_PER_CELL]; }; //const int ITER=300; //remains unchanged in academic life inline int fate(int value,int num_neighbors); //return 0 or 1 inline int count_neighbor(neighlist neighbors[NUM_CELLS], int array[GEN+1][I][J], int i, int j,int gen); //assume I and J there int main(int argc, char** argv){ int world[GEN+1][I][J]; //2 2-d arrays in a 3-d array //the extra layer (layer 3) is for neighbor index int world2[GEN+1][I][J]; //parallel universe neighlist neighbors[NUM_CELLS]; //virtual "neighbors" can be anywhere //on the grid (more like colleagues) //neighlist neighbors2[NUM_CELLS]; long int neighboridx; int gen=0; //either 0 or 1 int iter=0; int curr_generation=0; int maxcolor; long int i,j,k,m,n,o; //for iterating up to millions char ch; cout<<"\nAcadLife 1.0, by Oguz Yetkin, oguz@writeme.com"; cout<<"\npress q to stop the program"; cout<<"\nThis is a non-straighforward implementation of LIFE,"; cout<<"\nThe code is probably on"; cout<<"\nhttp://www.cs.wisc.edu/~yetkin/code\n"<>iter; int maxx,maxy; //initialize graphics //************************************ int driver=DETECT; int mode; registerbgidriver(EGAVGA_driver); //int maxx, maxy; //will be 640x480 //**************INIT GRAPHICS********************** initgraph(&driver, &mode, ""); //driver linked in //mode=CGAC0; //initgraph(&driver, &mode,"h:\\borlandc\\bgi"); maxx=getmaxx(); maxy=getmaxy(); maxcolor=getmaxcolor(); //cout<