Skip to content
Snippets Groups Projects
Commit 6195e5b3 authored by Jan Grewe's avatar Jan Grewe
Browse files

fix restart if alive cell count is flapping

parent 0908d26b
Branches
No related tags found
No related merge requests found
......@@ -9,10 +9,9 @@ int arrayCopy[SCREEN_HEIGHT][SCREEN_WIDTH];
bool runGame = true;
int currentTick = 0;
int cellsAliveBefore = 0;
int cellsAliveNow = 0;
int noEvolutionTicks = 0;
int currentTick;
int cellsAliveBefore;
int noEvolutionTicks;
void setupGameOfLife()
{
......@@ -40,8 +39,8 @@ void createRandomMatrix(int (&a)[SCREEN_HEIGHT][SCREEN_WIDTH])
void gameOfLife(int (&a)[SCREEN_HEIGHT][SCREEN_WIDTH])
{
currentTick++;
cellsAliveBefore = cellsAliveNow;
cellsAliveNow = 0;
int cellsAliveNow = 0;
for (int i = 0; i < SCREEN_HEIGHT; i++)
{
for (int j = 0; j < SCREEN_WIDTH; j++)
......@@ -83,6 +82,10 @@ void gameOfLife(int (&a)[SCREEN_HEIGHT][SCREEN_WIDTH])
}
}
if (currentTick % 2) {
cellsAliveBefore = cellsAliveNow;
}
if (cellsAliveNow == cellsAliveBefore)
{
noEvolutionTicks++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment