Log In  


I'd like to share the results of my exploration of the Wave Function Collapse algorithm and its implementation in Pico-8. I hope you'll find it useful.

It took me quite some time to wrap my head around this concept. Of all the resources I came across, the one that helped me the most was an article by Robert Heaton:

https://robertheaton.com/2018/12/17/wavefunction-collapse-algorithm/

If you're new to this, I'd really recommend reading this article first — it explains what the Wave Function Collapse algorithm actually is. In it, the author explains the algorithm using a Simple Tile Model WFC, but he also introduces an Even Simpler Tiled Model (ESTM). That model became the starting point for my own journey toward implementing Wave Function Collapse in Pico-8.

Over time, this initial implementation evolved into three different versions of the algorithm:

  • Even Simpler Tile Model (ESTM)
  • Simple Tile Model
  • Overlap Model

The following sections provide a brief overview of each implementation, along with a link to more detailed walkthrough for ESTM.

Even Simpler Tile Model

The Even Simpler Tile Model (ESTM) is the most basic implementation in this series. Unlike more advanced versions, it uses direction-independent adjacency rules, making it much easier to understand and implement. In other words, if two tiles are compatible, they can be placed next to each other regardless of direction.

Cart #estm_wfc-0 | 2026-09-29 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

Here is the link to a more detailed explanation of what is going on in the cart.

https://www.lexaloffle.com/bbs/?tid=157332&tkey=nZGKw5UHBqQN630xlnf5

Simple Tile Model

The Simple Tile Model extends the ideas of ESTM by using direction-dependent adjacency rules. Instead of simply defining which tiles can be placed next to each other, it specifies which tiles are allowed above, below, to the left, and to the right of each tile. This additional information allows the generation of more structured and coherent patterns.

Cart #simple_tile_model_wfc-0 | 2026-09-29 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

Overlap Model

And finally, the Overlap Model builds on the previous approaches, but instead of defining rules based on separate tiles, it generates them from a single input image.

This is the most involved of the three models, since it needs an extra preprocessing step before generation can even begin.

For this version, I needed to create a separate cart that exports a text file of the propagation rules and the tiles themselves. Here's the link to it:

https://www.lexaloffle.com/bbs/?tid=159424&tkey=n1YCYzmroPNWSQGDlQBR

This cart takes a texture from the Pico-8 spritesheet and cuts it into many 3x3 tiles. It then gets rid of all the duplicate tiles and creates the rules based on the unique tiles that are left, by overlapping their edges.

It then exports the rules and the unique tiles via Pico-8's printh to text files. Later, these are pasted into the algorithm's cart, so that when we run it, it doesn't have to do all the work of creating rules and extracting tiles from the texture — making it more optimized.

Cart #overlap_model_wfc-0 | 2026-09-29 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
5

If you have any questions or ideas about any of the three models, or any part of the code, as well as ideas on how you could use it in your own projects, feel free to reach out — I'll be happy to help or hear your ideas.

Here are some additional links that i found useful during my research:

Maxim Gumin's GitHub WFC repository
https://github.com/mxgmn/WaveFunctionCollapse

The Coding Train — Overlapping Model WFC
https://www.youtube.com/watch?v=5iSAvzU2WYY

Brian Bucklew - Dungeon Generation via Wave Function Collapse
https://www.youtube.com/watch?v=fnFj3dOKcIQ

5


ayy, this is cool!
i've been tihnking of making a wave function collapse algorithm (or similar) for cave generation in my game.


1

Thank you, @Astralsparv
This algorithm is great for generating various kinds of maps. Also if you are interested in cave generation I’d recommend you investigate Cellular Automaton generators. It might be the best and cheapest way to make cave maps.


Maybe..
My plan is basically to create a bunch of "walkers" and have them move in random directions, will just go for a lifespan and when they die they spawn new ones in different directions with a shorter lifespan than what the parent started with.
It'd then just fill in the tiles around it to create a dungeony/cave sorta thing - I used it a while back in Pico-8 and it was good, never released it anywhere though.

Would've then went over that and on the floor tiles generated new stuff where it could have rules to add stuff like barrels, chests and ponds, in a way that would ensure it wouldn't block off 99% of the map and ensure the cave is still playable (since some stuff like water you would need upgrades to traverse, and would then be used as a way to incentivise you to upgrade to be able to go through water, and then getting more rewards).



[Please log in to post a comment]