What you're seeing
A grid of cells, each one initially undecided — holding every possible tile at once, a superposition. One at a time, the algorithm finds the cell with the fewest remaining options (the most constrained, lowest-entropy cell), and forces it to pick a single tile. That choice immediately ripples outward: any neighbor tile that can no longer fit beside the new one is forbidden, which constrains its neighbors, and so on. Cell by cell the undecided dots resolve into pipe segments, and when the dust settles a single globally coherent pattern has crystallized — connected pipes that always meet pipe-to-pipe, never a dead end against a wall. Nothing drew the network; it fell out of repeatedly enforcing one local rule.
The rule
Each tile carries a socket on each of its four edges: a pipe (1) or a blank (0). The only knowledge in the whole system is a single adjacency rule: two tiles may be neighbors iff their touching edges match — a piped edge must meet a piped edge, a blank must meet a blank. From a handful of base tiles (empty, straight, elbow, tee, cross) and their rotations, that rule alone is enough. The algorithm then loops three steps until every cell is decided:
- Superposition — every cell starts holding all tiles as live possibilities.
- Observe — find the un-collapsed cell with the lowest entropy (fewest options left), breaking ties at random.
- Collapse — pick one tile for that cell (here, weighted so empty tiles are commoner and the network stays legible), discarding its other options.
- Propagate — for each neighbor, delete every tile no longer compatible with any surviving option of the changed cell; if a neighbor's option set shrank, propagate from it too — a cascade that runs until nothing more can be eliminated.
Coherence is never imposed globally. There is no objective function, no search over whole layouts, no "make the pipes connect" instruction. The rule is purely local — which tiles may sit beside which — and propagated. If the constraints ever back a cell into a corner with zero legal tiles, that's a contradiction: this entry handles it the simplest way, by discarding the grid and restarting with a fresh seed (the readout counts how often that happens).
Why it matters
Wave Function Collapse is a vivid demonstration of global order from purely local constraints. With no objective function and no search, constraint propagation alone reliably produces structures that look designed. That is not a coincidence: Karth and Smith showed that WFC is constraint solving — specifically the arc-consistency idea at the heart of constraint-satisfaction solvers, the same machinery that powers a Sudoku solver. The algorithm was popularized by Maxim Gumin in 2016, and it descends directly from Paul Merrell's earlier model synthesis.
It is worth being honest about what kind of emergence this is. Most of the Atlas — boids, the Ising model, reaction–diffusion — is dynamical and interaction-based: many agents push on each other over time and order settles out of the feedback. WFC, like the Atlas's L-systems, is instead generative and algorithmic: there is no equilibrium being sought and no time-stepped physics — a constraint solver simply resolves a consistent assignment. Both are emergence in the sense that the whole is far richer than any rule, but the mechanism here is constraint propagation, not interaction, and it is fair to say so. One more honesty note: the quantum-sounding name is a loose metaphor. "Observing the lowest-entropy cell" and "collapse" borrow physics vocabulary, but nothing here is actual quantum mechanics.
In the wild
WFC and its descendants are a workhorse of procedural content generation in games — used to lay out levels, worlds, and textures in titles such as Bad North, Townscaper, and Caves of Qud, among many others. The same edge-matching idea drives tiling and texture synthesis. And because the core is ordinary constraint solving, its mechanism is shared by Sudoku-style constraint puzzles and the arc-consistency routines studied in computer science: propagate the consequences of each forced choice, and either a consistent solution falls out or a contradiction tells you to back up.
Try this
- Press randomize repeatedly: every run is a completely different network, yet every run is fully coherent — same rules, new pattern.
- Shrink the grid and lower the speed to watch a single collapse-and-propagate step at a time: one cell decides, and a wave of forbidden options sweeps out from it.
- Watch the restarts counter. Bigger or denser grids occasionally paint the constraints into a corner; the grid throws itself away and starts over until a consistent layout survives.
References
- Gumin, M. (2016). "Wave Function Collapse" algorithm (reference implementation and tilesets). github.com/mxgmn/WaveFunctionCollapse.
- Karth, I. & Smith, A. M. (2017). "WaveFunctionCollapse is Constraint Solving in the Wild." Proceedings of the 12th International Conference on the Foundations of Digital Games (FDG '17).
- Merrell, P. (2007). "Example-Based Model Synthesis." Proceedings of the 2007 Symposium on Interactive 3D Graphics and Games (I3D '07), 105–112.