# World map, approach 3: wave function collapse Open `index.html?seed=7&style=tiles` (styles: parchment, painted, hex, iso, tiles). ## How it works 1. **Simple tiled model** (no overlapping model): 6 tiles (ocean, coast, plains, forest, hills, mountains) on a 60x40 grid, 4 cells per tile. Adjacency rules: ocean next to ocean or coast; coast next to ocean, coast, plains, forest; plains and forest next to coast, plains, forest, hills; hills next to plains, forest, hills, mountains; mountains next to hills and mountains. Tile weights 0.8 / 1.2 / 4 / 3 / 2.2 / 1.8. 2. The map border is pinned to ocean, and four tiles are pinned as stand-ins for **AI constraints**: two mountain tiles in the north, plains in the middle, forest in the south-west. 3. Lowest-entropy cell first, weighted random choice, arc-consistency propagation; restart on contradiction (with these permissive rules it almost never happens). 4. The tile grid becomes a heightfield (each tile a base height, bilinear between tile centres, a little noise) and a moisture field; biomes come straight from the tiles. 5. Then the **shared grid pipeline** of approach 1 does depression fill, rivers, lakes, places, roads and crossings. ## Good - Hard rules are guaranteed: mountains never touch the sea, ocean never touches plains. - Pinning tiles is the most direct way to honour "put X here" constraints, and the generator fills around them consistently. - Small and easy to understand; the tile set is a natural place for a DM to add rules ("swamp only next to forest or coast"). ## Bad (honest) - **Local consistency, no global structure.** WFC knows only neighbours, so the result is a patchwork: no continents, no long mountain chains, no watersheds. The pinned mountains do not grow into a range; they stay a blob. - Ocean and coast tiles appear inland, which the heightfield turns into many small lakes; rivers are short and many (100+ pieces). - The weights control the land share very sensitively (ocean weight 7 gives 1% land, 0.8 gives about 50%). - Without the shared heightfield pipeline there would be no rivers or roads at all; WFC itself contributes only the tile layout. ## What it costs to make real - Port to PHP is easy (about 100 lines), but the result is not worth it as a world generator. - Where it does fit: **small, rule-heavy maps** inside the tree (a dungeon level, a town district on a site_map, a tactical battle grid with walls and doors), where local rules matter and global geography does not. ## How it fits the locations tree Same JSON shape as approaches 1 and 2 (heightfield in `representation_data`, plus the raw tile grid under `representation_data.wfc`), children with `map_x/map_y`, `location_edges` with `travel_cost` in hours on foot. ## How the AI world-builder would use it The AI would pin tiles ("mountains here, a port there") and let WFC fill the rest. That works for placing things, but the AI cannot ask for "a river from the mountains to the sea" or "a continent", because WFC has no notion of either. For the world map, use approach 1 and keep WFC for tactical or site maps.