Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

toyboot4e/wfc.cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wfc

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!

Notes

  • 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.

Running an example

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!

TODO

Features

  • more generic domain (it only takes Floor and Wall, currently)

  • CLI for examples

Improvements

  • remove entropy and just use totalWeight / maxTotalWeight

  • backjumping for constant performance

  • seed-based output

About

Experimental implementation of wave function collapse algorithm in C# for 2D tile maps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages