Click or drag to toggle cells
How It Works
Conway's Game of Life is a cellular automaton โ a grid of cells that evolve according to simple rules. Each cell is alive or dead; each generation, all cells update simultaneously based on their 8 neighbors.
The Four Rules
- A live cell with fewer than 2 live neighbors dies (underpopulation)
- A live cell with 2 or 3 live neighbors survives
- A live cell with more than 3 live neighbors dies (overpopulation)
- A dead cell with exactly 3 live neighbors becomes alive (reproduction)
Key Implementation
function step(grid, rows, cols) {
const next = Array.from({length: rows}, () => new Uint8Array(cols));
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
let n = 0;
for (let dr = -1; dr <= 1; dr++)
for (let dc = -1; dc <= 1; dc++) {
if (dr === 0 && dc === 0) continue;
const nr = (r + dr + rows) % rows; // wrap-around
const nc = (c + dc + cols) % cols;
n += grid[nr][nc];
}
// apply rules
next[r][c] = (grid[r][c] && (n === 2 || n === 3)) || (!grid[r][c] && n === 3) ? 1 : 0;
}
}
return next;
}
Toroidal topology: The grid wraps around โ left edge connects to right, top connects to bottom. This avoids edge-case handling and creates an "infinite" universe feel.
Famous Patterns
- Glider โ a 5-cell pattern that moves diagonally across the grid
- Pulsar โ a period-3 oscillator, one of the most common
- R-pentomino โ 5 cells that take 1103 generations to stabilize, producing gliders
- Gosper Glider Gun โ the first pattern found that grows without bound