#include "SDL/SDL.h" #include #include // fuck maybe when they flip over 255 i should breed them to a random square // keys to let user toggle: // dna phase // ca phase // breeding (opposed to splitting) // get DNA loading in! // CA is pretty hard so now gives add 1 energy, ok? // views: // actions (needs a new grid to store em) // age? (add lifetime array then, too) // sexiness (% operands > 8) * 2.55 < do this still // skip counters // generation count (highestgen-lowestgen)/((gen-lowestgen)+1) // dna IP // // read how to set the palette // why is avggen wrong /* * Set the pixel at (x, y) to the given value * NOTE: The surface must be locked before calling this! */ void putpixel(SDL_Surface *surface, int x, int y, Uint8 pixel) { // int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ // Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * 1; // switch(1) { // case 1: *p = pixel; // break; return; /* case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } */ } void fillcell(SDL_Surface *surface, int cellw, int cellh, int x, int y, int xspace, int yspace, int yoff, Uint8 color) { int xstart = (cellw+xspace)*x; int xend = (cellw+xspace)*(x+1)-xspace; int ystart = ((cellh+yspace)*y)+yoff; int yend = ((cellh+yspace)*(y+1)-yspace)+yoff; int j; int i; unsigned int randomdivisor = RAND_MAX/255.0f; // printf ("%i\n", color); for (j = ystart; j < yend; j++) { for (i = xstart; i < xend; i++) { putpixel(surface, i, j, color); } } if ( SDL_MUSTLOCK(surface) ) { SDL_UnlockSurface(surface); } } void drawgrid(SDL_Surface *surface, Uint8 **DNA, Uint8 *grid, int gridrows, int gridcols, int cellw, int cellh, int xspace, int yspace, int screenwidth, int screenheight, int DNA_View_Cell_Size_Divisor, int DNA_Length, int view, int viewdata1, int viewdata2, int * viewdata3, Uint8 * viewdata4) { int i; int j; for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { // printf ("draw %i,%i,%i",i,j,*grid); if (view == 0) { fillcell(surface, cellw, cellh, j, i, xspace, yspace, 0, *grid); grid += 1; } else if (view > 0) { // generations, stuns int c; if (view == 1 | view == 4) { // integer tables c = ((int) 255.0f*(((float)(*viewdata3)-(float)viewdata1)/(((float)viewdata2-(float)viewdata1)+1.0f))); viewdata3 += 1; } else if (view == 2 || view == 3) { // uint8 tables c = ((int) 255.0f*(((float)(*viewdata4)-(float)viewdata1)/(((float)viewdata2-(float)viewdata1)+1.0f))); viewdata4 += 1; } if (c > 255) { c = 255; } // if (view == 2 && c > 0) { printf ("graph individual of stun count %i as color %i. low = %i high = %i \n", *viewdata4, c, viewdata1, viewdata2); } fillcell(surface, cellw, cellh, j, i, xspace, yspace, 0, c); } } } int t = DNA_Length/((gridcols*DNA_View_Cell_Size_Divisor)-3)+1; int dnactr=0; Uint8 *somedna = *DNA; for (i = gridrows; i < gridrows+t; i++) { for (j = 0; j < (gridcols*DNA_View_Cell_Size_Divisor)-3; j++) { // printf("debug: draw dna %i,%i\n", j, i-gridrows); fillcell(surface, cellw/DNA_View_Cell_Size_Divisor, cellh/DNA_View_Cell_Size_Divisor, j, i-gridrows, xspace, yspace, gridrows*(cellh+yspace), *somedna); somedna++; dnactr++; if (dnactr >= DNA_Length) { break; } } if (dnactr >= DNA_Length) { break; } } /* Update just the part of the display that we've changed */ SDL_UpdateRect(surface, 0, 0, screenwidth-1, screenheight-1); } void loadcrit (int dnalength, int popsize, Uint8 **DNA, int *generations, char *fn) { int i; int j; int q = (random()/(RAND_MAX/256))%4; Uint8 loaddna[dnalength]; printf("Attempting to load from ./ca-ga.load.dna\n"); FILE*iff=fopen(fn,"r"); for (i = 0; i < dnalength; i++) { loaddna[i] = getc(iff); } fclose(iff); printf( "DNA loaded\n"); int many = 0; for (i = 0; i < popsize; i++) { q++; if (q == 4) { // printf("Load one to pop offset #%i\n", i); q = 0; *generations = 1000; Uint8 *somedna = *DNA; for (j=0;j 0; soughtgen--) { while (*generations != soughtgen && offs < popsize) { //printf("debug: skipping animal of gen %i not of %i\n", *generations, soughtgen); generations++; offs++; } if (offs >= popsize) { generations-=popsize; offs = 0; } else {break;} } if (soughtgen>0) { // DNA+=(dnalength*offs); pre malloc? DNA+=offs; Uint8 *somedna = *DNA; printf ("Succeeds at population offset %i with critter of generation #%i\n", offs, soughtgen); int c; printf ("Write "); for (c = 0; c < dnalength; c++) { putc((char) somedna[c], of); // DNA++; } printf ("succeeded\n"); } else { printf ("wtf i couldn't find any DNA over generation -1\n"); } fclose(of); } int main(int argc, char *argv[]) { FILE*rand=fopen("/dev/urandom","r"); srand(getc(rand)); srandom(getc(rand)); fclose(rand); // printf("cat /dev/urandom to stdin to start it\n"); int CA_on = 1; int DNA_on = 1; int sex_on = 1; int view = 0; // int drawevery = 60; // int drawevery = 13; int autosaveevery = 100000; // if 50 cycles is one second this is about an // an hour unsigned int randomdivisor = RAND_MAX/255.0f; int drawevery = 1; int exitafter = 0; int biteAmount = 7; // energy moved int freeGiveBonus = 5; // int gridrows = 170; // int gridcols = 213; // you get weird ropes around this ratio // fuck with it, maybe smaller and they // knot up and shit // int gridrows = 70; // ok // int gridcols = 110; // int gridrows = 52; // also ok // int gridrows = 66; // int gridrows = 104; // int gridcols = 142; int gridrows = 111; int gridcols = 142; // make it fit int screenwidth = 1280; int screenheight = 1024; // int minspacingx = 2; // int minspacingy = 2; int minspacingx = 1; int minspacingy = 1; // int mutantrate = 9; // 1/n offspring will be mutated. minimum is 1 (100%) // int remutaterate = 4; // 2/n chance of repeat mutations int mutantrate = 11; // 1/n offspring will be mutated. minimum is 1 (100%) int remutaterate = 3; // 2/n chance of repeat mutations int sexoperandpersistance = 4; // frames of sim time (cumulative so 3 is high) // int DNA_Length = 16384; // even numbers only ok, over 256 is ok (offset takes 2 bytes randomness) // int DNA_Length = 4096; int DNA_Length = 8192; // hm int DNA_View_Cell_Size_Divisor = 2; // or use 2 most of the time // it crashed for me at 3 one time printf("init dna\n"); Uint8 **DNA[gridcols][gridrows]; Uint8 **dnaptr = &DNA; int DNA_IP[gridcols][gridrows]; int generations[gridcols][gridrows]; Uint8 skips[gridcols][gridrows]; Uint8 newskips[gridcols][gridrows]; // DNA: // 1 byte, 1 byte // byte 1: suck/give/wait // byte 2: direction // if sucking puts a cell under 0 copy dna to it // with mutations int drawsbetweenscoreoutput = 1000; int c = 0; int i = 0; int j = 0; printf ("load dna\n"); for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { DNA_IP[j][i] = 0; skips[j][i] = 0; newskips[j][i] = 0; generations[j][i] = 0; DNA[j][i] = malloc(DNA_Length); Uint8 *thisdna = DNA[j][i]; for (c = 0; c <= DNA_Length; c++) { thisdna[c] = (random()/randomdivisor)%4; c++; thisdna[c] = (random()/randomdivisor)%16; } } } printf ("random dna ready\n"); Uint8 *thisdna = &DNA; printf ("%i\n", (int) thisdna[0]); printf ("%i\n", (int) (random()/RAND_MAX)); int cellwidth = (screenwidth/gridcols)-minspacingx; int cellheight = (screenheight/(gridrows+((DNA_Length/DNA_View_Cell_Size_Divisor)/(gridcols*DNA_View_Cell_Size_Divisor))+1))-minspacingy; int xspace = minspacingx+((screenwidth-(gridcols*(cellwidth+minspacingx))) / gridcols); int yspace = minspacingy+((screenheight-((gridrows+((DNA_Length/DNA_View_Cell_Size_Divisor)/(gridcols*DNA_View_Cell_Size_Divisor))+1)*(cellheight+minspacingy))) / (gridrows+(DNA_Length/gridcols)+1)); printf ("screenwidth %i\nscreenheight %i\ngridX %i\ngridY %i\ncellwidth %i\ncellheight %i\nxspace %i\nyspace %i\n", screenwidth, screenheight, gridcols, gridrows, cellwidth, cellheight, xspace, yspace); Uint8 grid[gridcols][gridrows]; // int tctr=0; printf ("get grid\n"); for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { // grid[j][i] = (j*i)*4; // interesting seed grid[j][i] = (random()/randomdivisor); // grid[j][i] = tctr; tctr++; if(tctr>255){tctr=0;} // printf ("grid[%i][%i] = %i\n", j, i, grid[j][i]); if (grid[j][i] > 256) { grid[j][i] = 0; } // grid[j][i] = 30; } } printf("Initializing SDL.\n"); /* Initialize defaults, Video and Audio */ if((SDL_Init(SDL_INIT_VIDEO)<0)) { printf("Could not initialize SDL: %s.\n", SDL_GetError()); exit(-1); } printf("SDL initialized.\n"); /* Clean up on exit */ atexit(SDL_Quit); SDL_Event event; /* * Initialize the display in a 640x480 8-bit palettized mode, * requesting a software surface */ SDL_Surface *screen; screen = SDL_SetVideoMode(screenwidth, screenheight, 8, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %ix%ix8 video mode: %s\n", screenwidth, screenheight, SDL_GetError()); exit(1); } Uint8 tgrid[gridcols][gridrows]; for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { tgrid[j][i] = grid[j][i]; } } Uint8 dnarun[gridcols][gridrows]; for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { dnarun[j][i] = grid[j][i]; } } Uint8 sexctr[gridcols][gridrows]; for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { sexctr[j][i] = 0; } } int t = 0; int tt = 0; // no float avggen = 0; int y = 0; int gridlastx = gridcols-1; int gridlasty = gridrows-1; int up; int down; int left; int right; int cycles=0; int highgen = -1; int lowgen = -1; int lowgeninpop = -1; int highestgen = -1; int skipsctr = 0; int pokes = 0; int gives = 0; int bites = 0; int kills = 0; int breeds = 0; int splits = 0; int autosavectr = 0; int viewdata1; int viewdata2; int *viewdata3; Uint8 *viewdata4; for (t = 0; t < 100; t++) { drawgrid(screen, DNA, *grid, gridrows, gridcols, cellwidth, cellheight, xspace, yspace, screenwidth, screenheight, DNA_View_Cell_Size_Divisor, DNA_Length, view, 0, 0, 0, 0); } //printf("intro draw\n"); } t = 0; printf("\nHit 'h' in the window for options\n"); int reverseEvaluation = 0; signed int inc; int startx; int starty; int lastx; int lasty; while(1) { // live int run; int i; int j; signed int z; z = (signed int) (unsigned int) gridcols/2; signed int y; y = (signed int) (unsigned int) gridrows/2; /* Poll for events. SDL_PollEvent() returns 0 when there are no */ /* more events on the event queue, our while loop will exit when */ /* that occurs. */ while( SDL_PollEvent( &event ) ){ /* We are only worried about SDL_KEYDOWN and SDL_KEYUP events */ switch( event.type ){ case SDL_KEYDOWN: /* Check the SDLKey values and move change the coords */ switch( event.key.keysym.sym ){ case SDLK_SLASH: printf(""); case SDLK_h: printf ("(( Key help\n\ (V) to toggle views\n\ (D) to toggle DNA\n\ (C) to toggle CA\n\ (S) to toggle sex\n\ (X) to export a DNA\n\ (L) to load some DNA\n\ (Q) to export & quit\n"); break; case SDLK_d: if (DNA_on) {DNA_on=0;printf("DNA run suspended! D to resume\n"); } else {DNA_on=1;printf("DNA run enabled. Thank you\n");} break; case SDLK_c: if (CA_on) {CA_on=0;printf("CA run suspended! C to resume\n"); } else {CA_on=1;printf("CA run enabled. Good luck\n");} break; case SDLK_s: if (sex_on) {sex_on=0;printf("Sex disallowed, S to resume\n"); } else {sex_on=1;printf("The reproductive suppression field has been disabled\n");} break; case SDLK_v: if (view == 0) {view=1;printf("Generation count view on, V to switch\n");} else if (view == 1) {view=2;printf("Stun view on, V to switch\n");} else if (view == 2) {view=3;printf("Breed mood view on, V to switch\n");} else if (view == 3) {view=4;printf("DNA IP view on, V to switch\n");} else if (view == 4) {view=0;printf("Normal view resumed, V to switch\n");} break; case SDLK_x: savecrit(highgen, DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.best.dna"); savecrit(avggen, DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.average.dna"); break; case SDLK_q: savecrit(highgen, DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.best.dna"); savecrit(avggen, DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.average.dna"); printf("Free DNA\n"); for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { Uint8 *temp = DNA[gridcols][gridrows]; // free(&temp); } } printf("Shutdown\n"); return 0; break; case SDLK_l: printf("Load ca-ga.load.dna\n"); loadcrit(DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.load.dna"); break; default: break; } break; case SDL_KEYUP: break; default: break; } } highgen = -1; avggen = 0; if (reverseEvaluation > 0) { startx = gridlastx; lastx = 0; inc = -1; starty = gridlasty; lasty = 0; reverseEvaluation = 0; } else { startx = 0; lastx = gridlastx+1; inc = 1; starty = 0; lasty = gridlasty+1; reverseEvaluation = 1; } for (run = 0; run < 2; run++) { // eval in reverse half the time // to get rid of the 'wind' from // not using enough temp grids to // make all the actions fair // in both directions // all the time for (i = starty; i != lasty; i+=inc) { for (j = startx; j != lastx; j+=inc) { signed int newcell; if (run == 0) { // dna run // newskips[j][i] = 0; if (DNA_on) { newcell = grid[j][i]; newcell *= .97; // fade dnarun[j][i] = newcell; if (sexctr[j][i]>0) { sexctr[j][i]--; } if (skips[j][i] > 7) { // printf("skip"); skipsctr++; // skip makes goto's now, like direction sense sorta DNA_IP[j][i] += (skips[j][i]%8)*2; while (DNA_IP[j][i] >= DNA_Length) {DNA_IP[j][i] -= DNA_Length;} newskips[j][i] = skips[j][i] - 8; } else { if (skips[j][i] > 0) { newskips[j][i] = 0; } Uint8 *thisdna = DNA[j][i]; Uint8 op = thisdna[DNA_IP[j][i]]; Uint8 arg = thisdna[DNA_IP[j][i]+1]; DNA_IP[j][i]+=2; if (DNA_IP[j][i] >= DNA_Length) { DNA_IP[j][i] = 0; } int destx = 0; int desty = 0; if (op != 0) { if (i == 0) { up = gridlasty; } else { up = i-1; } if (i == gridlasty) { down = 0; } else { down = i+1; } if (j == 0) { left = gridlastx; } else { left = j-1; } if (j == gridlastx) { right = 0; } else { right = j+1; } while (arg > 7) { arg -= 8; sexctr[j][i] += sexoperandpersistance; } if (arg == 0) { destx = left; desty = up; } else if (arg == 1) { destx = j; desty = up; } else if (arg == 2) { destx = right; desty = up; } else if (arg == 3) { destx = left; desty = i; } else if (arg == 4) { destx = right; desty = i; } else if (arg == 5) { destx = left; desty = down; } else if (arg == 6) { destx = j; desty = down; } else if (arg == 7) { destx = right; desty = down; } if (op == 1) { // give dnarun[destx][desty] += biteAmount+freeGiveBonus; newcell -= biteAmount; if (newcell < 0) { newcell = 0; } gives += 1; } else if (op == 2) { // suck // signed int w = (signed int) grid[destx][desty]; signed int w = (signed int) dnarun[destx][desty]; w -= biteAmount; newcell += biteAmount; if (w < 0) { // kill & breed dnarun[destx][desty] = newcell + biteAmount; // recolor DNA_IP[destx][desty] = 0; // reboot sexctr[destx][desty] = 0; skips[destx][desty] = 0; int mutant = (random()/randomdivisor) % mutantrate; // n% are mutants //breedorsplit = (random()/randomdivisor) % 2; // half the time breed // half the time split if (sexctr[j][i]>0 && sex_on) { // mingle (slow!) generations[destx][desty] = ((generations[j][i] + generations[destx][desty])/2)+1; breeds += 1; int r = 0; char b = (random()/randomdivisor); for (c = 0; c < DNA_Length; c++) { if (b&1) { // parent Uint8 *newdna = DNA[destx][desty]; newdna[c] = thisdna[c]; // printf ("2\n"); } // else { // DNA[destx][desty][c] = thisdna[c]; // keeps its own byte // printf ("1\n"); // } } b>>1; r++; if (r == 8) { r = 0; b = (random()/randomdivisor); } } else { // split // printf ("3\n"); generations[destx][desty] = generations[j][i]; splits += 1; for (c = 0; c < DNA_Length; c++) { Uint8 *newdna = DNA[destx][desty]; newdna[c] = thisdna[c]; } } if (mutant == 0) { generations[destx][desty]++; int first = 1; int oporarg = (random()/randomdivisor)%2; // damn a whole byte of randomness for this int limit; if (oporarg > 0) { limit = 24; } else { limit = 4; } while (((random()/randomdivisor)%remutaterate < 2) || first) { first = 0; int offset = ( ( ( (int)(random()/randomdivisor) )*256 )+(int)(random()/randomdivisor) ) % (DNA_Length/2); int c = ((random()/randomdivisor)%limit)%16; thisdna[offset*2 + oporarg] = c; } } kills += 1; } else { // no kill just bite dnarun[destx][desty] = w; } bites += 1; } else if (op == 3) { // poke newskips[destx][desty] += arg+1; pokes += 1; } } else { // no-op, vulnerable to poke newskips[j][i] += 7; } // unindented poke skip check ends } newcell += (signed int) ((signed int) grid[j][i] - (signed int) dnarun[j][i]); if (newcell < 0) { newcell == 1; } dnarun[j][i] = newcell; if (highgen < generations[j][i]) {highgen = generations[j][i];} avggen += (float) generations[j][i]; if (lowgeninpop > generations[j][i]) {lowgeninpop = generations[j][i]; lowgen = generations[j][i];} // end DNA run } else { // if DNA_on is off newcell = grid[j][i]; // newcell *= .97; // no fade dnarun[j][i] = newcell; } } else { // CA run skips[j][i] = newskips[j][i]; // newskips[j][i] = 0; newcell = dnarun[j][i]; if (CA_on) { newcell *= .97; // fade if (newcell > 255) { newcell = 0; } // newcell += 5; // what is this rule /* newcell += 1-(abs((signed int)(i-y))/(gridcols/7)); newcell += 1-(abs((signed int)(j-z))/(gridcols/7)); newcell -= dnarun[gridcols/2+1][gridrows/2]/64; newcell -= dnarun[gridcols/2+1][gridrows/2+1]/64; newcell -= dnarun[gridcols/2][gridrows/2]/64; newcell -= dnarun[gridcols/2][gridrows/2+1]/64; newcell += dnarun[gridlastx][gridlasty]/64; newcell += dnarun[0][0]/64; newcell += dnarun[0][gridlasty]/64; newcell += dnarun[gridlastx][0]/64; newcell += dnarun[gridcols-(gridcols/4)][gridrows/4]/64; newcell -= dnarun[gridcols/4][gridrows/4]/64; newcell += dnarun[gridcols-(gridcols/4)][gridrows-(gridrows/4)]/64; newcell -= dnarun[gridcols/4][gridrows-(gridrows/4)]/64; */ // wilder if you use modulos not divides. but you can seek homeostasis instead, using the above code if you want newcell += (-3)*(abs((signed int)(i-y))/(gridcols/5)); newcell += (-3)*(abs((signed int)(j-z))/(gridcols/5)); newcell -= dnarun[gridcols/2+1][gridrows/2]%4; newcell -= dnarun[gridcols/2+1][gridrows/2+1]%4; newcell -= dnarun[gridcols/2][gridrows/2]%4; newcell -= dnarun[gridcols/2][gridrows/2+1]%4; newcell += dnarun[gridlastx][gridlasty]%4; newcell += dnarun[0][0]%4; newcell += dnarun[0][gridlasty]%4; newcell += dnarun[gridlastx][0]%4; newcell += dnarun[gridcols-(gridcols/4)][gridrows/4]%4; newcell -= dnarun[gridcols/4][gridrows/4]%4; newcell += dnarun[gridcols-(gridcols/4)][gridrows-(gridrows/4)]%4; newcell -= dnarun[gridcols/4][gridrows-(gridrows/4)]%4; // end if (i == 0) { up = gridlasty; } else { up = i-1; } if (i == gridlasty) { down = 0; } else { down = i+1; } if (j == 0) { left = gridlastx; } else { left = j-1; } if (j == gridlastx) { right = 0; } else { right = j+1; } if (dnarun[left][up] < newcell) { newcell--; } else { newcell++; } if (dnarun[left][i] < newcell) { newcell--; } else { newcell++; } if (dnarun[left][down] < newcell) { newcell--; } else { newcell++; } if (dnarun[right][up] < newcell) { newcell--; } else { newcell++; } if (dnarun[right][i] < newcell) { newcell--; } else { newcell++; } if (dnarun[right][down] < newcell) { newcell--; } else { newcell++; } if (dnarun[j][up] < newcell) { newcell--; } else { newcell++; } if (dnarun[j][down] < newcell) { newcell--; } else { newcell++; } if (newcell > 255) { newcell = 0; } else if (newcell < 0) { // oops but cool // newcell = 255; newcell = 1; } } else {} // if CA off tgrid[j][i] = newcell; } } } } lowgeninpop = highgen; // eh for (i = 0; i < gridrows; i++) { for (j = 0; j < gridcols; j++) { grid[j][i] = tgrid[j][i]; } } if (highgen > highestgen) { highestgen = highgen; } avggen /= (gridcols*gridrows); t++; if (t == drawevery) { if (view == 1) { viewdata1 = lowgen; viewdata2 = highgen; viewdata3 = &generations; viewdata4 = 0; } else if (view == 2) { viewdata1 = 0; viewdata2 = 96; viewdata3 = 0; viewdata4 = &skips; } else if (view == 3) { viewdata1 = 0; viewdata2 = sexoperandpersistance*5; viewdata3 = 0; viewdata4=&sexctr; } else if (view == 4) { viewdata1 = 0; viewdata2 = DNA_Length; viewdata3 = &DNA_IP; viewdata4=0; } else if (view == 0) { viewdata1 = 0; viewdata2 = 0; viewdata3 = &viewdata1; } drawgrid(screen, DNA, *grid, gridrows, gridcols, cellwidth, cellheight, xspace, yspace, screenwidth, screenheight, DNA_View_Cell_Size_Divisor, DNA_Length, view, viewdata1, viewdata2, viewdata3, viewdata4); t=0; tt++; if (tt == drawsbetweenscoreoutput) { printf("in world high score %i, highest was %i, lowest is %i, average %f ", highgen, highestgen, lowgen, avggen); if (view == 1) {printf ("(generation view)\n");} else if (view == 2) {printf ("(stunned view)\n");} else if (view == 3) {printf ("(breed mood view)\n");} else if (view == 4) {printf ("(DNA IP view)\n"); } else {printf("\n");} printf("%i gives %i pokes %i skips %i bites %i kills %i breeds %i splits\n", gives, pokes, skipsctr, bites, kills, breeds, splits); gives = 0; pokes = 0; skipsctr = 0; bites = 0; kills = 0; breeds = 0; splits = 0; tt = 0; } } autosavectr++; if (autosavectr == autosaveevery) { printf("Autosaving\n"); savecrit(highgen, DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.best.dna"); savecrit(avggen, DNA_Length, gridrows*gridcols, DNA, &generations, "ca-ga.average.dna"); autosavectr = 0; } cycles++; if (cycles == exitafter) { return; } } printf("Quiting SDL.\n"); /* Shutdown all subsystems */ SDL_Quit(); printf("Quiting....\n"); exit(0); }