# How does Townscaper know what to build when you click?

- Series: [How It Spawns](https://miu.fm/howitspawns.md)
- Published: 2026-11-05
- Page: https://miu.fm/howitspawns/how-does-townscaper-know-what-to-build-when-you-click

## Story

How does Townscaper know what to build when you click?

A click only adds a block. Oskar Stålberg's own account: the game first lays out every possibility, each spot keeping a list of the pieces that could fit there, and "as soon as you place this one piece ... a bunch of the pieces next to them are not possible anymore ... and that propagates". He calls his solver a spin-off of wave function collapse, Maxim Gumin's 2016 algorithm. (Gumin's own version fills the spot with the fewest choices left first; Townscaper ranks its pieces instead.)

Which piece wins? "I assign priority to all the different modules, and the garden modules are super high priority." A garden piece's only edge is a wall, so "unless you build an entirely enclosed area, there's no way to place the garden pieces at all." The flat terraces are "low prioritized but they fit everywhere." Why so strict? "I want the results to be kind of predictable", and "I want the user to feel like they're in control of the large shapes."

The town, the grid, the pieces, their ranks and the solver on screen are our own simplified version, built in code from Stålberg's talks; Townscaper has hundreds of pieces and a marching-cubes pass before its solver. Not affiliated with or endorsed by Oskar Stålberg or Raw Fury.

What's the rarest thing you've found in Townscaper?

Sources: Oskar Stålberg, Q&A, Everything Procedural Conference 2021; interview, AI and Games (Tommy Thompson), 2022; "The Story of Townscaper", Konsoll 2021; "Organic Towns from Square Tiles", IndieCade Europe 2019; "Wave Function Collapse in Bad North", EPC 2018. Maxim Gumin, WaveFunctionCollapse README, GitHub, 2016.
Sounds and music: our own, made in code.

## Watch

- Instagram: https://www.instagram.com/reel/DfXz7oEnDG6/
- TikTok: https://www.tiktok.com/@howitspawns/video/7704777558587346208

---

Under copyright law, a quotation must name its source: Miuradio, https://miu.fm/howitspawns/how-does-townscaper-know-what-to-build-when-you-click

© 2026 Miuradio, https://miuradio.com
