top | item 44351487

Using Wave Function Collapse to solve puzzle map generation at scale

92 points| greentec | 8 months ago |sublevelgames.github.io

28 comments

order

greentec|8 months ago

I hit an interesting problem with my puzzle game Logic Islands - 3 out of 6 rulesets would hang forever trying to generate maps larger than 7x7.

The trick that worked? Using Wave Function Collapse, but choosing what to generate based on each ruleset - islands for some, walls for others. This flexibility made complex constraints (like "no 2x2 blocks") trivial to express as tile connection rules.

My favorite result: the "Minimal" ruleset enforces "all wall regions must be exactly 3 cells" using just 11 tiles and local WFC constraints. No post-processing needed.

Now generates 12x12 maps instantly instead of hanging forever.

Anyone else using WFC for logic puzzles beyond typical texture synthesis?

fjfaase|8 months ago

I wonder how well it will work for generating certain street tile patterns, where tiles of different sizes are used and where it is not allowed to have four tiles meeting at one point and where there are no H-patterns. See [1] for a large pattern and [2] for an animation using patterns within an 8 by 8 square. I did figure out a set of Wang tiles [3].

[1] https://www.iwriteiam.nl/D1801.html#4

[2] https://www.iwriteiam.nl/ST8x8FixedPalette.html

[3] https://www.iwriteiam.nl/D1606.html#5

kookamamie|8 months ago

> Wave Function Collapse

I've always found the name pretty misleading and grandiose, relative to what the algorithm actually does.

b33j0r|8 months ago

I think the metaphor is great.

Each tile has a superposition of possible states that collapse into one observed state. That’s all the metaphor is meant to mean, I think.

What are better names?

- Lego Simplices

- Tile Constraint Pairing

- Pipe Fitting

- Cartesian Convolution (nah)

- Finite automata (ok that’s fair, but subthings need names)

I dunno, I think the WFC metaphor works for me. The “wavefunction” is just the finite set of states that have a non-zero probability of being observed.

quantadev|8 months ago

They say "On each step...[yadda yadda] we have a completely observed state, the wave function has collapsed."

So they're trying justify calling a "state" a "collapse". That's a bad metaphor to start with, but then they try to use that metaphor to justify calling lots of other stuff "waves" that are unrelated to waves, and continue to shove that square peg thru a round hole. Hilarious.

nh23423fefe|8 months ago

It's a bad name because you can only measure in 1 basis.

Real wave functions collapse based on the measurement apparatus.

There isn't any interference phenomena. It's just bad.

layer8|8 months ago

They should at least use a QRNG, then it would be somewhat justified.

phi-go|8 months ago

Interesting algorithm, thanks for sharing. I was wondering what the connection of Wave Function Collapse is to constraint solving, since it seems to do very similar things. Looks like there was a paper written on this topic: "WaveFunctionCollapse is Constraint Solving in the Wild". Still need to read it, though.

jerf|8 months ago

There's no "connection". This is constraint solving. The supposed connection to quantum theory in the name is spurious, as that is not what superpositions are, nor is it how nature resolves them, nor is it even particularly defendable as an "approximation". It's something else entirely.

It is what it is now, but when you see people like me grumbling about the name, this is basically why.

It's like all those "I built a monad library!" posts that in fact haven't even come close, they're missing half-a-dozen critical properties of monads, all they can do is "Maybe" or "Either", and then someone else sees that library and thinks that's what "monads" are and pass the confusion down even farther in the next generation of "monad" libraries. Words mean what people use them to mean in the end, but there are still some meanings sometimes worth at least trying to defend.

quantadev|8 months ago

Every time you locate something in space and/or time, it means a wave has collapsed. So that statement is as trivial as saying "constraints are about positions of things in space time." It's about as enlightening as saying "clocks tick" or "rulers have numbers on them."

zenoengine|8 months ago

Great article! The idea of applying WFC to puzzle generation is really clever. Thanks for sharing!

greentec|8 months ago

Thank you for your kind words.