diff --git a/src/gameoflife.cpp b/src/gameoflife.cpp index a5da2560fd35c648a7b178275e09e71664d84328..67c70ab1028d55ed906d06157974691bff8b8c32 100644 --- a/src/gameoflife.cpp +++ b/src/gameoflife.cpp @@ -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++) @@ -82,7 +81,11 @@ void gameOfLife(int (&a)[SCREEN_HEIGHT][SCREEN_WIDTH]) a[i][j] = arrayCopy[i][j]; } } - + + if (currentTick % 2) { + cellsAliveBefore = cellsAliveNow; + } + if (cellsAliveNow == cellsAliveBefore) { noEvolutionTicks++;