Algorithms

Conway’s Game of Life: movement from simple rules

Three cells change direction. A small pattern travels diagonally. No cell knows about the whole shape: it only counts its neighbours. Draw your own board and inspect each decision step by step.

1× = 4 generations/s. Editing starts a new history from the current field; Restart repeats its beginning.

Living: 3 · Born: 0 · Died: 0

Draw with a mouse or finger. Arrow keys select a cell; Space applies the tool. Blue outline: selection. Dot: birth next step. Cross: death next step. Counters describe the last completed update.

B3/S23 · 32 × 24 board · Cells outside the board are dead; edges do not wrap.

Video walkthrough

One update for the whole board

Each cell is either alive or dead. Its next state depends on its current state and the eight surrounding positions. Every cell changes at once. This is a mathematical cellular automaton; the name does not imply a biological simulation. The B3/S23 rule means birth with three neighbours and survival with two or three.

Three cases

Dead + exactly 3 neighbours → birth. Alive + 2 or 3 neighbours → survival. Every other combination gives a dead cell in the next generation.

A dead cell with two neighbours stays dead. Counting neighbours is not enough: the current state matters too. A cell never counts itself.

Inspect the blinker

The starting pattern has live cells at (13, 10), (14, 10) and (15, 10), using zero-based coordinates. The middle cell has two live neighbours and survives. Each end has one and dies. The dead cells at (14, 9) and (14, 11) have three neighbours and are born. The horizontal line becomes a vertical line; one more generation restores the original pattern.

Press Next and use Inspect cell to compare a prediction with the result. Outlines show the neighbourhood in the current generation. Green dots and crosses predict the next update. The counters below the board describe the transition that has already happened. Births and deaths are zero at generation 0.

Why use a second array?

Writing directly into the current board makes later cells read a mixture of old and new states. If the first end of the blinker dies early, later neighbour counts change before the generation is complete. The result then depends on traversal order. Instead, read only the old board and write all results into a new one. Replace the current board after the whole pass finishes.

Three kinds of behaviour

The 2 × 2 block stays unchanged: each live cell has three neighbours, and no outside position qualifies for birth. The blinker repeats after two generations. After four updates the glider has the same shape one cell to the right and one cell down. No movement instruction exists: some cells die while others are born. We recognise the translated shape. Step through these patterns slowly and check each prediction.

The edge of this board

Our example uses a finite 32 × 24 board. Positions outside it are always dead, and opposite edges do not connect. This is an explicit choice for the teaching example. A glider reaching the edge can change or disappear; it will not reappear on the other side. This board is not an infinite plane.

Cost of a generation

For width W and height H, visit every cell and inspect at most eight neighbours: O(W·H) time per generation. The new board takes O(W·H) extra memory. Seeking is a separate player feature: storing G+1 snapshots costs O(G·W·H). With W=32, H=24 and G≤240, this example stores at most 185,088 board elements, plus arrays and bookkeeping. This is an element count, not a claim about JavaScript byte usage.

Try it

Add one cell to the blinker and predict the next generation. Build a stationary block. Step through four glider generations and compare the shape. Draw near an edge and explain the result using the dead exterior. Editing begins a new history. A reproducible link preserves that history’s starting board, current generation and speed, and opens paused.

Edit, share and record

Draw and erase with a mouse or finger. Arrow keys on the board select a cell; Space applies the tool. You can also enter its X and Y coordinates. Editing pauses playback and creates generation 0. Restart repeats the beginning of the current session; Clear creates an empty board.

Choose 1–240 generations and press Apply to rebuild history from its initial board. Invalid input preserves the active run. At 1× the player shows four generations per second; speed does not change the model. Playback stops at the end, while inspection still predicts the next update beyond the recording.

Share creates a clean-player link containing the exact initial board, generation limit, selected cell, position and speed. It opens paused. Save video records the entire current history from the beginning without sound, using a separate canvas. Full screen preserves the session.

Code for one generation

The code below is the executable model core with the same dimensions and dead exterior. It takes a binary array of 768 elements. The wrapper validates size and values, stores immutable snapshots and counts births and deaths separately.

Show the executable model
"use strict";
const LIFE_WIDTH = 32, LIFE_HEIGHT = 24;
function countLifeNeighbours(cells, x, y) {
    let count = 0;
    for (let dy = -1; dy <= 1; dy++)
        for (let dx = -1; dx <= 1; dx++) {
            const nx = x + dx, ny = y + dy;
            if ((dx || dy) && nx >= 0 && nx < LIFE_WIDTH && ny >= 0 && ny < LIFE_HEIGHT)
                count += cells[ny * LIFE_WIDTH + nx];
        }
    return count;
}
function nextLifeCells(cells) {
    return cells.map((alive, i) => {
        const n = countLifeNeighbours(cells, i % LIFE_WIDTH, Math.floor(i / LIFE_WIDTH));
        return Number(n === 3 || (alive === 1 && n === 2));
    });
}