Game of Life
The grid is a set of cells that are either alive or dead. Every generation, each cell looks at its eight neighbors and decides its next state from one small rule table. Each cell sees only its neighbors, and the patterns emerge from that.
One generation
flowchart TD
A["Start a new empty grid for the next generation"] --> B["Pick a cell in the current grid"]
B --> C["Count live cells among its 8 neighbors, wrapping at the edges"]
C --> D{"Is the cell alive?"}
D -- yes --> E{"2 or 3 live neighbors?"}
E -- yes --> F["Stays alive"]
E -- no --> G["Dies"]
D -- no --> H{"Exactly 3 live neighbors?"}
H -- yes --> I["Becomes alive"]
H -- no --> J["Stays dead"]
F --> K["Write the result into the new grid"]
G --> K
I --> K
J --> K
K --> L{"More cells?"}
L -- yes --> B
L -- no --> M["Replace the old grid with the new one and redraw"]
Two details that matter
- Results go into a second grid. If cells were updated in place, a cell changed early in the pass would feed wrong counts to its neighbors later in the same pass. Every cell in a generation has to see the same previous generation.
- The edges wrap. A cell on the right edge counts the left edge as its neighbor, so the board behaves like the surface of a donut. A glider that leaves one side comes back through the other.
The four rules
| Cell is | Live neighbors | Next generation |
|---|---|---|
| Alive | 0 or 1 | Dies (isolation) |
| Alive | 2 or 3 | Survives |
| Alive | 4 or more | Dies (crowding) |
| Dead | Exactly 3 | Becomes alive |