I'm not sure how to think about this algorithm. Is it just applied statistics?
I'm not sure how to think about this algorithm. Is it just applied statistics?
For a 2D map the loose layout of the algorithm is this: construct a 2D array of blank tiles. Choose a tile at random from the set of most-constrained tiles (this is currently all of them as they are all equally unconstrained) and give it a value according to some distribution. Constrain its neighbors' potential values and update whatever system you use to track most-constrained-tiles for selection, then repeat until no unset tiles remain.
Depending on the complexity of the distribution (# of tile types and absoluteness of neighbor relations), you may end up with a contradiction where an unset tile has no possibilities. At this point you could progressively backtrack, throw the whole set away, or fudge something, depending on what matters to you in life.
You can end up with some very cool things!
The problem has some neat aspects to consider in how to represent tiles, how to track constraints, how to efficiently update your selector, how to design your distributions, etc! There are a ton of avenues to explore.
I make no claims on the goodness of this example or its implementation, but I wrote a small game to use/test my wfc code here: https://wcarss.ca/jabiru/ -- the maps generated are entirely outputs of the algorithm.