1. The 2D Simple Tiled Model

Observe, collapse, propagate -- the canonical Wave Function Collapse loop, running on a 2D grid you can watch.

Interactive

Pipes, terrain, and circuits

Each cell in the grid begins in a superposition of every possible tile — just like a quantum particle that hasn't been observed. One step at a time, the algorithm narrows the possibilities until each cell resolves to a single tile.

The loop

  1. Observe

    Find the cell with the fewest remaining options — the lowest entropy. This is the most constrained cell, where a decision is least likely to cause problems.
  2. Collapse

    Pick one tile at random for that cell, weighted by tile frequency. The cell now has a single definite state.
  3. Propagate

    This collapse creates a ripple. Check every neighbor; remove any tile that is no longer compatible. If a neighbor's options shrink, check its neighbors too. This is constraint propagation — the same technique Sudoku solvers use.
  4. Repeat

    Until every cell has exactly one tile (success), or some cell has zero options (contradiction — restart).

Adjacency rules

Each tile has labeled edges. Two tiles can be neighbors only if their touching edges share the same label. The three tilesets here use different vocabularies:

  • Pipes — edges are either open or closed. Open meets open; closed meets closed.
  • Terrain — edges are materials like grass, water, sand. Matching materials connect.
  • Circuits — edges are trace or empty. Traces form continuous wires.

Entropy & the heatmap

Entropy measures uncertainty:

H = log(Sum w) - (Sum w * log w) / Sum w

Toggle Heatmap to visualise it. Blue cells are nearly decided; red cells have maximum uncertainty. Watch the wavefront of certainty spread outward from each collapse — constraints cascading through the grid.

The key insight

Nothing in this algorithm “plans” the output. There is no global layout, no aesthetic goal. Every rule is local — just “my right edge must match your left edge.” Yet the global structure that emerges — pipes forming closed networks, terrain having plausible coastlines, circuits routing coherent traces — is the algorithm's only emergent behaviour.