Wave function collapse - Simple tiled model

This is my take on the wave function collapse algorithm in one of its simple variants : the simple tiled model.
Given a set of tiles and some adjancency rules, the algorithm tries to produce an image. It can be used for levels generation, pattern-like backgrounds and can also be used for non-visual data.
How does it work ?
This cart contains a few demo tilesets and rulesets that you can navigate between with the left and right arrows.
Sometimes the algorithm gets stuck (shown with red tiles). This happens when there is a contradiction : the rules won't allow any tile to be placed on a position. Press X or O to restart.
Yeah but, really, how does it work ?
I suggest you look at the links provided below for more information about the algorithm.
For this specific implementation, I used bitfields to encode adjacency rules : each tile has a list of 4 integers (for the four directions : up, right, down, left). Valid neighbors are determined by comparing (with a binary AND) the opposite bitfields of each tiles : 1 can connect with 1, 3 can connect with 2 and with 1,...
Links

Original implementation by Maxim Gumin (@ExUtumno) : https:github.commxgmnWaveFunctionCollapse
The coding train's implementation which this cart is based on : https:youtu.berI_y2GAlQFM
A nice explanatory video by Martin Donald : https:youtu.be2SuvO4Gi7uY
GDC Talk about wave function collapse in 'Caves of Qud' : https:youtu.beAdCgi9E90jw



Close
Connection Error!

Please check your connection and try again.