//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 //version 3: neighbors are symmetric //#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; }; class neighlist{ public: point list[NEIGHBORS_PER_CELL]; int curr_neighbors; neighlist(){curr_neighbors=0;}; }; //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; //new in version 3 int assigned_neighbors=0; //must not exceed NUM_CELLS*NUM_NEIGHBORS 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; int maxx, maxy; long int i,j,k,m,n,o; //for iterating up to millions char ch; //initialize graphics //************************************ int driver=DETECT; int mode; if(registerbgidriver(EGAVGA_driver)<0){ cout<<"\nunable to register grafx driver!!!"<>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; //zero out worlds //cout<<"\ngrafx init..."; for(gen=0;gen