//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 // //version 2: self-neighbor not allowed 2/18/1998 //#include "graph.h" #include //will have to use borland c++ graphics directly :( //for getpixel and putpixel #include #include #include #include //for exit #include #include //for sound //change to 1 in order to make it legal for self to be a neighbor //#define SELF_NEIGHBOR 0 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 void dump(int world[GEN+1][I][J],int gen); //dump as text int main(int argc, char** argv){ int self_neighbor_legal=0; 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 randx, randy, thisx, thisy; //temp variables to hold randomly generated values int maxcolor; long int i,j,k,m,n,o; //for iterating up to millions char ch; cout<<"\nAcadLife 2.0, by Oguz Yetkin, oguz@writeme.com"; cout<<"\npress q to stop the program"; cout<<"\nThis is a non-straighforward implementation of LIFE,"; cout<<"\nthis version (2.0), can preclude self as a neighbor"; cout<<"\nThe code is probably on"; cout<<"\nhttp://www.cs.wisc.edu/~yetkin/code/life\n"<>iter; cout<<"\nare self-neighbors legal? (y/n) "; cin>>ch; if(ch=='y'){ self_neighbor_legal=1; }else{ self_neighbor_legal=0; } 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<