Wave Function Collapse Algorithm

I have made a WFC Algorithm not too dissimilar from this one https://www.youtube.com/watch?v=vjR5eCqT5yM. It takes in a set of tiles, weights for those tiles, and world conditions to generate a random rectangular world.


Using said set of tiles and weights, this was made.

There are edge cases where no tile can fit into a space, this is a fault of the tiles, none can fit in there. This is not a problem with the algorithm.

I invite Anyone to play around with it.
Wave Function Collapse.rbxl (61.2 KB)

If anyone has any insight on how to make the world less random, or stringy (I don’t like the grass randomly cutting through everything) Please share them with me.

General how it works
After making a world it choses a random part. Said part gets chosen from the list of possible parts weighted so some parts have a better than even chance to get chosen. After choosing, it checks to see if a part can fit next to it, if it cant, it is removed (this is how the edge cases happen). Then it choses a random part with the lowest amount of possible parts.

In Depth
Each side of a part has a name, checking which part fits looks at weather the bordering sides share a name, if they don’t, then they cant fit next to one another. Deserts cant be next to mountains, but deserts can be next to a desert mountain transition tile.

How the script decides when to remove a tile is strange. It would be nice to have a mountain next to a desert, reducing the amount of transition tiles needed. It needs to be worked on. Insights appreciated.

The itemlookup and weights module scripts contain dictionaries that are based upon the names of the tiles. and the itemlookup’s arrays are in order east,north,west,south. (it contains the side names)

4 Likes

What are you talking about, this isn’t quantum physics or has anything to do with it. I can’t tell if your joking or not.

Asking for feedback. The code should work as intended, though you are welcome to look at it by downloading the rblx file. I was just wondering If a specific set of tiles, rules, and weights make the world more natural looking.

I believe there is a different WFC related to quantum physics.

Algorithms look very cool, I don’t know why, but they really just do.

its just a really cool algorithm inspired by quantum mechanics

I knew what wave function collapse was beforehand and that it involved terrain generation, didn’t know it was rooted in quantum mechanics

Please don’t bash the post because you think wave function collapse is complicated.
When you solve a sudoku puzzle, you are using wave function collapse to solve it.

The premise of WFC is that you have a set of tiles, a set of rules and a set of states each tile can be in.

In Sudoku, you have an 9x9 set of tiles.
Each tile can be in 1 of 9 states (1 to 9, obviously).
The rules of Sudoku mean that whilst most tiles will have multiple possible states (hence quantum mechanics), at least 1 tile will have only 1 possible state, allowing you to fill that tile in. This process repeats until the board is completed.

I recommend you watch this video to understand it! https://youtu.be/2SuvO4Gi7uY?si=GJLVixw_mSkcwclk