🗺️ Wave Function Collapse

Procedural level generation · Constraint propagation · Entropy-guided collapse

Controls

Speed

Tile Set

Stats

Collapsed cells0
Remaining
Contradictions0
StatusReady

🧩 Wave Function Collapse — Procedural Generation

Watch the Wave Function Collapse (WFC) algorithm generate coherent tile maps in real time. Tiles propagate adjacency constraints across the grid, with entropy guiding the collapse order.

🔬 What It Demonstrates

WFC maintains a superposition of possible tiles at each cell. The cell with lowest Shannon entropy collapses first (is assigned a definite tile). Constraint propagation then eliminates incompatible neighbours, reducing entropy across the grid until all cells are resolved.

🎮 How to Use

Select a tile set and grid size. Click Start to watch entropy-guided collapse. Cells collapse one at a time, with constraint propagation rippling outward. The colour indicates remaining entropy.

💡 Did You Know?

WFC was created by Maxim Gumin in 2016, inspired by quantum mechanics notation. It's now used in commercial games (Townscaper, Bad North) and architectural design for procedural environment generation.

About this simulation

This demo runs the Wave Function Collapse algorithm, a constraint-satisfaction method for procedural map generation. Every grid cell begins in a superposition of all permitted tiles. On each step the simulation collapses the cell with the lowest entropy — here measured simply as the number of remaining candidate tiles — then propagates that choice outward, pruning neighbours whose edge sockets no longer match. The borrowed quantum vocabulary is metaphorical, but the resulting maps are coherent and surprisingly organic.

🔬 What it shows

A tile-based WFC solver on a square grid. Each tile carries four edge sockets (north, east, south, west); two tiles may sit side by side only when their facing sockets share an id. Collapse picks the lowest-candidate cell at random among ties, fixes one tile, and a stack-based propagation step filters every affected neighbour. Unsatisfiable cells are tallied as contradictions.

🎮 How to use

Press New Map to reset, Step to collapse one cell, or Auto to run continuously. The Slow/Med/Fast tabs set the per-step delay (200, 30 or 0 ms). The Grid size slider spans 10 to 50 cells per side, and you can switch between the Land and Dungeon tile sets. The Stats panel tracks collapsed cells, those remaining and any contradictions.

💡 Did you know?

Wave Function Collapse was published by Maxim Gumin in 2016 and named after the quantum-mechanics idea of a measured state settling into one outcome. The technique now appears in commercial titles such as Townscaper and Bad North, as well as in architectural and texture-synthesis tools.

Frequently asked questions

What is the Wave Function Collapse algorithm?

It is a procedural-generation technique that fills a grid with tiles so that every neighbouring pair obeys a set of adjacency rules. Each cell starts holding all possible tiles, and the algorithm repeatedly fixes one cell and propagates the consequences until the whole grid is consistent. The name is an analogy to quantum measurement, not actual physics.

How does the collapse step work here?

The solver scans for the uncollapsed cell with the fewest remaining candidate tiles, breaking ties at random. It assigns that cell one random tile from its candidates, then runs a propagation pass: each neighbour keeps only the tiles whose facing edge socket matches, and any change ripples further outward via a stack.

What do the controls and tile sets do?

New Map clears and restarts, Step advances a single collapse, and Auto loops at the selected speed (200, 30 or 0 ms per step). The grid slider sets the side length from 10 to 50 cells. Land builds water, beach, grass, forest and mountain terrain; Dungeon builds voids, walls, corridors, rooms, torches and lava, each with its own socket compatibility.

What is entropy in this context?

Entropy is a measure of how undecided a cell still is. In this simulation it is approximated by the count of tiles a cell could still become; the classic algorithm uses Shannon entropy weighted by tile frequencies. Collapsing low-entropy cells first keeps the most constrained regions consistent and reduces the chance of dead ends.

Why do contradictions sometimes appear?

A contradiction occurs when propagation leaves a cell with zero valid tiles, meaning no tile can satisfy all of its neighbours. Because this demo uses simple ordered backtracking-free collapse, it resolves such cells by forcing a fallback tile and counting the event rather than restarting. Richer implementations backtrack or restart to guarantee a fully valid map.