Learning LabExplorable explanations
← All artifacts
Procedural Generation

Wave Function Collapse

Every cell starts as every possible tile at once, then collapses one at a time. Each choice ripples through its neighbors as a constraint wave until the whole map agrees, and a bad pick forces a backtrack.

wfcconstraint-propagationprocedural-generationentropy
LiveInteractive · drag, toggle, run it
Procedural generation / Constraint solving

Wave Function Collapse

Every cell starts as a blur of all five terrain tiles. The solver finds the most certain cell, collapses it to one tile, then propagates that choice outward so neighbours drop whatever no longer fits. Sea only touches sea or coast, mountains only touch land or mountains, and so the map stays coherent.

Collapsed
0
of 196 cells
Entropy left
784
surplus options
Contradictions
0
restarts on this seed

A solid cell is collapsed. A faded cell still holds several tiles, blended by colour, with a count of how many remain. The pulsing outline marks the cell just observed.

Force a cell

Pick a tile, then click any uncertain cell to pin it and watch the constraint wave ripple from your choice. The solver respects your pin and continues from there.

Observe then propagate · step 0 of 191

Every cell holds every tile

Before a single observation, each cell is in superposition: all five terrain tiles are still possible. Entropy is at its maximum. The algorithm now repeats two moves, observe then propagate, until the grid either fully agrees or hits a cell with no options left.

The adjacency rules

Each tile carries an edge type, and two tiles may sit side by side only when their edges are compatible. That single table is the entire grammar of the map. Minimum entropy first matters because collapsing the most constrained cell keeps later choices open: a cell with two options is far more likely to survive than one chosen at random. A contradiction means propagation cornered a cell into zero options, which is why the solver keeps a retry budget.

SeatouchesSea, Coast
CoasttouchesSea, Coast, Land, Forest
LandtouchesCoast, Land, Forest, Mountain
ForesttouchesCoast, Land, Forest, Mountain
MountaintouchesLand, Forest, Mountain

Five terrain tiles, edge-compatibility adjacency, seeded mulberry32 PRNG. Observe picks the minimum-entropy cell with seeded tie breaks; propagation runs a worklist until the grid is stable.