wfc.cs is an implementation of the WaveFunctionCollapse algorithm (OverlappingModel) for tile maps, based on the post by Grid Bugs.
Note that it’s not set up for others: not well refactored, the input file being hard coded, and even uncommon format in use!
-
The OverlappingModel can be used to fill a segment, like done in Caves of Qud
-
The OverlappingModel is really slow, so I also implemented adjacency-based constraints, which doesn’t care about local similarity.
-
It doesn’t reduce the order of the algorithm, but makes the input smaller.
-
By default, an example of the OverlappingModel with input Example/Res/rooms.txt
is hard coded.
If you’re using VSCode, there’s .vscode/tasks.json
, so type Cmd+Shift+B or Ctrl+Shift+B to run the Example project. Or, run it with dotnet
:
$ dotnet run --project Example/Example.csproj
~~ omitted ~~
=== Source map===
###.########.###
###.#####......#
#.....###......#
#.....###......#
#...............
......###......#
#.....###......#
##.######......#
##.########.####
##.########.####
##......##....##
........##......
##............##
##......##....##
##......####.###
###.########.###
FAIL
SUCCESS
=== Output: ===
#######.#####.###.###......##...###.
....###.#####.###.###.###..##...###.
....###.###.......###.###.......###.
....###.###............##..##...##..
....##...##.......##...##..##...##..
....##...##.......##.####..#########
....#######.......##.####..#########
#.#########.......##.##########...##
#.##########.###.###.##########.....
.....#######.###.###.....##..##...##
.....##...##.##..........##.......##
#######...##.##...##.........##...##
#######...##.##########.####.#######
#######...##.##########.####.#######
#....#######.###...####.........####
#....#######.###................####
.....###...........####.........####
#....###......##...####.........####
###.####......##...####.........####
###.####......#########.........####
##....##......################.###..
##....##......##....##########.###..
########............####..####.###..
########......##....####..####.###..
########......##....#########...####
#.....##............#########...####
#.............##....#########...##..
#.....###.###.###########..##...##..
......###.###.###########.......##..
#.....###.##...####..####..##.......
#.....##..##...####........##...##..
#.....##.............####..##...##.#
#.........###.######.####.########.#
......##..###.######.####.########.#
##.#####.....................##.....
##.#####..##.................##.....
.###.###.##
#.......###.###..
##............##..#
..##.......##...##..##.
...##.......##.####..####
######.......##.####..#####
#######.......##.##########..
########.###.###.##########..
..#######.###.###.....##..##...
...##...##.##..........##.......#
#####...##.##...##.........##...#
#####...##.##########.####.######
######...##.##########.####.#######
....#######.###...####.........####
....#######.###................####
....###...........####.........####
....###......##...####.........####
##.####......##...####.........####
##.####......#########.........####
#....##......################.###..
#....##......##....##########.###..
#######............####..####.###..
#######......##....####..####.###..
######......##....#########...###
....##............#########...###
............##....#########...##.
...###.###.###########..##...##
..###.###.###########.......#
..###.##...####..####..##....
.##..##...####........##...
##.............####..##..
...###.######.####.####
.###.######.####.##
.................
...........
Good. But you’ll find it’s slow!