Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement