Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gameOfLife nextStep(gameOfLife world)
- {
- int** nextWorld = cloneWorld(world);
- for (int maty = 0; maty < world.leny; maty++){
- for (int matx = 0; matx < world.lenx; matx++)
- {
- int counter = 0;
- for (int checkx = -1; checkx <= 1; ++checkx)
- {
- for (int checky = -1; checky <= 1; ++checky)
- {
- if (checkx == 0 && checky == 0)
- continue;
- int x = matx + checkx;
- int y = maty + checky;
- if (x == -1)
- x = world.lenx - 1;
- if (y == -1)
- y = world.leny - 1;
- if (x == world.lenx)
- x = 0;
- if (y == world.leny)
- y = 0;
- counter += world.field[y][x];
- }
- }
- nextWorld[maty][matx] = conway(counter, world.field[maty][matx]);
- }
- }
- world.field[0][0] = 1; //this is the check line
- world.field = nextWorld;
- return world;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement