/*=======================DO NOT REMOVE UNDER PENALTY OF ME====================== ================================================================================ |--------------------------|==================================================== |John Conway's Game of Life|==================================================== |--------------------------|==================================================== |Programmed in RobotC by John Parks A.K.A The_System_Programmer|================ ==============================================================================*/ int width=60,height=40; int world[60][40]; int nextworld[60][40]; int worldnieghbors[60][40]; int nieghbors,LIFE=0,w,h,x,y,RUN=1,gener=0,blif; task main(){ eraseDisplay(); nxtDisplayCenteredTextLine(0,"The SIMPLE Game"); nxtDisplayCenteredTextLine(1,"of Life"); //=====GENERATE THE FIRST WORLD===== for(h=2;h<=height-3;++h){ for(w=2;w<=width-3;++w){ world[w][h]=random[1]; nextworld[w][h]=random[1]; } } //========A WHOLE NEW WORLD======== for(h=1;h<=height-2;++h){ for(w=1;w<=width-2;++w){ nxtEraseRect(w+18,h+1,w+18,h+1); if(nextworld[w][h]==1){nxtFillRect(w+18,h+1,w+18,h+1);} }} //=====END OF A WHOLE NEW WORLD===== while(RUN==1){ ++gener; nxtDisplayCenteredTextLine(2,"S: %0i - %0i",nieghbors,gener); for(h=0;h<=height-2;++h){ for(w=0;w<=width-2;++w){ world[w][h]=nextworld[w][h]; }} for(h=1;h<=height-2;++h){ for(w=1;w<=width-2;++w){ //=============CHECK FOR FRIENDS============== nieghbors=0; for(x=-1;x<=1;++x){ for(y=-1;y<=1;++y){ if(world[w+x][h+y]==1)++nieghbors; } } if(world[w][h]==1)worldnieghbors[w][h]=nieghbors-1; else worldnieghbors[w][h]=nieghbors; //==========END OF CHECK FOR FRIENDS=========== nxtDisplayCenteredTextLine(2,"F: %0i - %0i",nieghbors,gener); } } //=============SET UP LIFE============== for(h=1;h<=height-2;++h){ for(w=1;w<=width-2;++w){ LIFE=0; if(world[w][h]==1&&worldnieghbors[w][h]==2)LIFE=1; if(worldnieghbors[w][h]==3)LIFE=1; nextworld[w][h]=LIFE; nxtDisplayCenteredTextLine(2,"L: %0i - %0i",nieghbors,gener); } } //==========END OF SET UP LIFE=========== //========A WHOLE NEW WORLD======== for(h=1;h<=height-2;++h){ for(w=1;w<=width-2;++w){ nxtEraseRect(w+18,h,w+18,h); if(nextworld[w][h]==1){nxtFillRect(w+18,h,w+18,h);} nxtDisplayCenteredTextLine(2,"D: %0i - %0i",nieghbors,gener); }} //=====END OF A WHOLE NEW WORLD===== while(nNxtButtonPressed==3){} while(nNxtButtonPressed==1||nNxtButtonPressed==2){ nxtDisplayCenteredTextLine(0,"The SIMPLE Game"); nxtDisplayCenteredTextLine(1,"of Life"); //=====GENERATE A NEW WORLD===== for(h=0;h<=height-2;++h){ for(w=0;w<=width-2;++w){ world[w][h]=random[1]; nextworld[w][h]=random[1]; } } } } while(nNxtButtonPressed!=3){} }