← Back to Hub

Wave Function Collapse (WFC)

The Concept

WFC is a constraint-based algorithm. Imagine every cell starts in a "superposition" of all possible tiles. We observe (collapse) one cell, then propagate constraints to its neighbors, eliminating impossible options.

Rules: Like Sudoku, but with adjacency rules (e.g., "Water" can touch "Sand" but not "Grass").

Status: Ready

Core Logic


function propagate(cell) {
    stack.push(cell);
    while(stack.length > 0) {
        let current = stack.pop();
        current.neighbors.forEach(neighbor => {
            // Remove options incompatible with current's possible options
            if(constrain(neighbor, current)) {
                stack.push(neighbor);
            }
        });
    }
}