Wave Function Collapse

Programming Something That Already Exists Without Knowing it Exists
read in ~1 minute | Apr 28th 2022

Hello! I’ve been bingeing more YouTube content recently and I discovered that there was something called Wave Function Collapse. Basically, given a grid, and some tiles with special rules, write an algorithm that places those tiles in the grid following those rules. Basically Sudoku but more generalized.

This immediately reminded me of a script I wrote in Godot for infinite 3d world generation. I wanted to have specific rooms or hallways placed in a usable way. I also used “weights” on each tile to make some tiles appear much more frequently.

I created a bunch of “tiles” and added rules saying where other tiles can connect, and generate x number of blocks away from the player, much like Minecraft.

Apparently, what I created is an imperfect version of Wave Function Collapse.

Here’s my understanding of what Wave Function Collapse should do.

  1. Find the space with the least valid possible tiles
  2. Place one of the possible tiles
  3. Repeat until no more tiles can be filled.

Obviously, with some back-tracking for when no tiles can be placed, but the board is still not full.

It’s so cool to find out that something you worked on in the past are problems that have been perfectly solved by others, and that you can learn from the differences in methods of solution.

Usages of the Wave Function Collapse seem to be for procedural generation or for puzzle solving.

Here’s the links to the videos that reminded me of it:

Youtube Video #1 Youtube Video #2


🪧 Enjoy Reading This?

Here are some more you might like to read next:

My Development Experience With Godot 3 in VR

My Recent Development Shenanigans Aug 16th 2022


The Point Of Formatters

May 1st 2024


Developing a PC + VR game with Godot

A long Journey Jun 1st 2023



💬 Looking for comments?

I don't have comments on this site as they can be time consuming to manage. I'd rather concentrate on programming cool and new things.

Since you can't leave a comment, feel free to ✉️ contact me instead.