Andreu Playà
EN
← All projects Archive

Wave Function Collapse

A map generator that is handed a few tiles and the rules for which may touch which, and resolves a layout that never breaks them.

StatusArchived
Built2022
StackUnity3D · C#

What it is

Overview

The algorithm starts with every cell holding every possibility at once, picks the cell with the least freedom left, collapses it to one tile, and propagates what that forces on its neighbours. Repeat until nothing is undecided — or until it contradicts itself and has to back out.

I wrote it in Unity3D because I wanted to see it resolve. Watching the grid settle is the whole appeal: it is not random placement, it is a constraint system finding the only answers that fit.

What it left behind

Afterwards

This is the same shape of problem as sequencing a machine. A station cannot move here because that axis is there, this gripper cannot close until the other one has cleared — you are propagating constraints until only legal states remain. I did not build it to learn that; I noticed it afterwards.

It stayed a test application. It generates maps, it proves the algorithm, and it never grew a purpose beyond that.