Counting Neighbors on a Grid
Each cell's next state depends on whether it is alive or dead in the current time step.
Why Neighbors Decide a Cell's Fate
Conway's Game of Life is a grid of cells, where each cell is either alive or dead. The game does not involve a player making moves. Instead, every cell follows a fixed set of rules that decides whether it will be alive or dead in the next time step. Each new generation is built entirely from those rules applied to the current one.
The central idea of this article is that a cell's next state depends on whether it is alive or dead right now, together with how many living neighbors it has. Once you can count those neighbors correctly for a cell, the rules tell you what happens to that cell next. Before reading the rules, try the question below.
What do you think happens?
A living cell has exactly 1 living neighbor in the current time step. Does it stay alive in the next time step?
Reveal answer
No, it dies.
A living cell survives only with 2 or 3 living neighbors. A count of 1 falls in the loneliness condition, which covers 0 or 1 living neighbor, so the cell dies.
Following One Cell Through a Time Step
To decide the fate of a cell, you look at the cell itself and the eight cells surrounding it. Those eight are the cells directly above, below, left, right, and diagonal to it. The cell being examined is not counted as its own neighbor. Only the surrounding cells that are alive contribute to the count.
Read the diagram as a 3 by 3 block centered on the cell. Each neighbor is found by adding a row offset and a column offset to the cell's own position. The center square is the cell you are examining, so it is excluded from the count. Your whole job in counting is to check these eight positions, one at a time, and tally the ones that are alive.
The Survival and Reproduction Rules
The rules form one decision that begins with the cell's current state. If the cell is alive, one rule applies. If the cell is dead, a different rule applies. In both cases the next state is decided by the count of living neighbors. The diagram below shows how the branches connect, so you can follow any cell from its current state to its next state.
Follow any branch from left to right to check a cell. The left side of the diagram sorts cells by whether they are alive now. The right side gives the outcome for the next time step, which depends only on the count of living neighbors.
Working Through a Full Generation
The clearest way to internalize the rules is to apply them to a specific cell. The example below is an original illustration built for this article. It uses two cells, one alive and one dead, and asks only what each one does in the next time step.
One living cell and one dead cell
Cell A is alive in the current time step and has 2 living neighbors. Cell B is dead in the current time step and has 3 living neighbors. What is each cell's state in the next time step?
- 1Identify the current state of Cell A
Cell A is alive, so the survival rule applies to it.
- 2Count the living neighbors of Cell A
Cell A has 2 living neighbors. A count of 2 is one of the two surviving counts.
- 3Decide the next state of Cell A
Because a living cell with 2 or 3 living neighbors survives, Cell A stays alive in the next time step.
- 4Identify the current state of Cell B
Cell B is dead, so the reproduction rule applies to it.
- 5Count the living neighbors of Cell B
Cell B has 3 living neighbors. This is exactly the count that triggers reproduction.
- 6Decide the next state of Cell B
A dead cell with exactly 3 living neighbors becomes alive, so Cell B is alive in the next time step.
Cell A stays alive and Cell B becomes alive in the next time step.
A grid-wide step must be computed from the current grid. Every cell's next state is decided by looking at the current generation, not at cells that have already been updated during the same step. If you changed one cell and then used its new value when counting for a neighbor, you would be mixing two generations and the result would be wrong.
Mistakes Beginners Make When Counting
Common mistake Counting the cell itself as one of its own neighbors
What it looks likeA living cell with 2 living surrounding cells is counted as having 3, so it survives when it should not.
Why it failsThe neighbor count uses the eight surrounding cells only. The examined cell sits at the center of the 3 by 3 block and is not part of its own neighborhood.
Do this insteadCheck only the eight surrounding positions and leave out the center square.
Common mistake Using the survival rule for a dead cell
What it looks likeA dead cell with 2 living neighbors is treated as alive because 2 is a surviving count.
Why it failsThe survival rule applies only to living cells. A dead cell follows the reproduction rule, which needs exactly 3 living neighbors.
Do this insteadFirst read the current state, then choose the rule that matches it.
Common mistake Treating a count of 4 or more as survival
What it looks likeA living cell with 4 living neighbors is kept alive.
Why it failsOnly 2 and 3 are surviving counts. Any count above 3 is overcrowding, which causes death.
Do this insteadCompare the count against the surviving pair 2 and 3, and treat everything else as death.
Common mistake Updating cells one at a time while counting
What it looks likeA cell becomes alive early in the step, and a later neighbor counts it as alive.
Why it failsEach next state must come from the current grid. Mixing updated and not-yet-updated cells produces a grid that matches no real generation.
Do this insteadRead every cell from the current grid first, then write all the next states.
Practice Deciding Next States
A living cell has 3 living neighbors. A dead cell has 4 living neighbors. A second dead cell has exactly 3 living neighbors. For each of the three cells, state whether it is alive or dead in the next time step and name the rule or condition that decides it.
Hints
- Start with each cell's current state to choose between the survival rule and the reproduction rule.
- For the living cell, check whether 3 is one of the two surviving counts.
- For the dead cells, only an exact count of 3 leads to becoming alive.
Summary of the Two Rules
- 1A cell's next state depends on whether it is alive or dead now and on how many of its eight surrounding cells are alive.
- 2A living cell survives with 2 or 3 living neighbors. Fewer than 2 is loneliness, and more than 3 is overcrowding, and both lead to death.
- 3A dead cell becomes alive only with exactly 3 living neighbors. Any other count leaves it dead.
- 4Every next state must be computed from the current grid so that one generation is built entirely from the previous one.
At a glance
- A cell's next state depends on whether it is alive or dead in the current time step and on its count of living neighbors.
- A living cell survives with 2 or 3 living neighbors; 0 or 1 is loneliness and more than 3 is overcrowding, and both cause death.
- A dead cell becomes alive only with exactly 3 living neighbors and otherwise remains dead.
- Every grid-wide step is computed from the current generation, not from cells already updated in that same step.