This repository is an example implementation of the Wave Function Collapse algorithm using Ruby and Gosu.
The algorithm is used to generate the entire map using tiles based on the rules. Rules are defined using the Tiled program and read by the Ruby program from the TSJ file.
Build the Wave Function Collapse algorithm in Ruby that's fast enough to iterate in a game on each frame.
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Run bin/run
to run the example.
Run bin/benchmark
to see how fast the algorithm is.
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Run #1: Benchmark for Model(grid=20x20 entropy=188)… Finished in 1.17s
Run #2: Benchmark for Model(grid=20x20 entropy=188)… Finished in 1.02s
Run #3: Benchmark for Model(grid=20x20 entropy=188)… Finished in 1.07s
Average time: 1.0883400000069134
Slowest time: 1.1748530000040773
Fastest time: 1.020996000006562
Result: 1.09s
Bug reports and pull requests are welcome on GitHub at https://github.com/pusewicz/wave-function-collapse-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Piotr Usewicz |
Cyberarm |
The gem is available as open source under the terms of the MIT License.
Tileset: https://opengameart.org/content/consolidated-hard-vacuum-terrain-tilesets