From 86025a8836d541eba09986e14f9ed50362a89097 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Wed, 4 Sep 2024 22:24:05 +0200 Subject: [PATCH] Comments --- src/life.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/life.cpp b/src/life.cpp index e2c6c25..db57eec 100755 --- a/src/life.cpp +++ b/src/life.cpp @@ -129,6 +129,7 @@ int gridAliveNeighbors(Grid &grid, int row, int col) { return alive; } + /** * Run one Game of Life tick. * Cells (X) live and die by the following rules: @@ -144,12 +145,16 @@ void gridTick(Grid &grid) { for (int col = 0; col < grid.numCols(); col++) { int alive = gridAliveNeighbors(grid, row, col); + // A cell with 1 or fewer neighbours dies. if (alive == 1) nextGrid.set(row, col, Cell::DEAD); + // Locations with 2 neighbours remain stable. else if (alive == 2) nextGrid.set(row, col, grid.get(row, col)); + // Locations with 3 neighbours will create life. else if (alive == 3) nextGrid.set(row, col, Cell::ALIVE); + // A cell with 4 or more neighbours dies. else if (alive == 4) nextGrid.set(row, col, Cell::DEAD); }