-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|695|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Blogs Home -> Blogs


 
Pakz
Created : 25 September 2020
Edited : 26 September 2020
Language : raylib c

Wave Function Collapse Algorithm



I think it was last year that I learned about the Wave Function Collapse algorithm. It is rather new. Only a few years ago it was created.
There are no easy to understand tutorials on how to learn it.

What it does is create levels from pieces of levels. Puzzling from one piece into to a whole level. Online there are a whole bunch of examples and a lot better than what I created. My version kind of creates some kind of dungeons.

Here is where I finally learned how to create some working code :

www.boristhebrave.com/2020/04/13/wave-function-collapse-explained/

edit:



Here one of the outputs:


Here a video showing my code and the output levels.


View on YouTube

My code was made in Raylib using the c language. (github user : pakz001)

 

Comments


Saturday, 26 September 2020, 01:42
Pakz
Bump!

I commented the code and put that version here on the site into a code box. Maybe someone wil find it useful.
Saturday, 26 September 2020, 05:54
Jayenkai
That looks handy for making some nice level layout and such.
Still waiting for that epic game that makes use of all these generators, and your awesome sprites. Come on, Pakz!!
Saturday, 26 September 2020, 07:16
Pakz
I had almost started with porting my 'dude space mining' game from monkey2 to raylib and expand on that. But I want to spend a lot more time learning how to do reasonable pixelart.

Knowing me this is going to take me 'a while'

These were done recently for rpg inventories : still a newb though !


Saturday, 26 September 2020, 07:23
Jayenkai
"newb" my arse! Those would definitely work in a game.
Thursday, 01 October 2020, 09:16
Pakz
A little bit more about the wave function collapse. I have had more time to think about it.

It is a sort of auto tiling algorithm. When in sim city you placed a road into a straight direction and then went into another direction the game would auto change the corner road to be a corner tile. Also it would handle all directions a road would go by placing the rights tiles there. No need to select each tile from the menu.

This wfc algorithm is somewhat similar. It places a random tile and based on that tile it would select tiles besides it that connect with that one. Say you have a flower and you start at the bottom. Its base can only go up so that tile would be selected or the flower part. At random it could be a large or small flower.

There are a bunch of tricks and mods that can be done to get different behaviour and output but auto tiling seems to be what it is in its most primitive form.
Thursday, 01 October 2020, 10:42
cyangames
After giving it a readup it sure seems interesting, I wander if it could be used to create something larger than expected on a lil 32kb NES cart then.... Hmmmmm