Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 14th, 2018 97 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. gameOfLife nextStep(gameOfLife world)
  2. {
  3.     int** nextWorld = cloneWorld(world);
  4.     for (int maty = 0; maty < world.leny; maty++){
  5.         for (int matx = 0; matx < world.lenx; matx++)
  6.         {
  7.             int counter = 0;
  8.             for (int checkx = -1; checkx <= 1; ++checkx)
  9.             {
  10.                 for (int checky = -1; checky <= 1; ++checky)
  11.                 {
  12.                     if (checkx == 0 && checky == 0)
  13.                         continue;
  14.                     int x = matx + checkx;
  15.                     int y = maty + checky;
  16.  
  17.                     if (x == -1)
  18.                         x = world.lenx - 1;
  19.                     if (y == -1)
  20.                         y = world.leny - 1;
  21.                     if (x == world.lenx)
  22.                         x = 0;
  23.                     if (y == world.leny)
  24.                         y = 0;
  25.                     counter += world.field[y][x];
  26.                 }
  27.             }
  28.             nextWorld[maty][matx] = conway(counter, world.field[maty][matx]);
  29.         }
  30.     }
  31.  
  32.     world.field[0][0] = 1;  //this is the check line
  33.     world.field = nextWorld;
  34.  
  35.     return world;
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top