Skip to content

Tiled Wave Function Collapse model implemented in Ruby and rendered using Gosu

License

Notifications You must be signed in to change notification settings

pusewicz/wave-function-collapse-ruby

Repository files navigation

Wave Function Collapse in Ruby

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.

Wave Function Collapse in Ruby

Objective

Build the Wave Function Collapse algorithm in Ruby that's fast enough to iterate in a game on each frame.

Development

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.

Benchmark

Run bin/benchmark to see how fast the algorithm is.

f8157d0: Apple M3 Max 64GB (2023): 1.09s

    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

Contributing

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.

Contributors

pusewicz
Piotr Usewicz
cyberarm
Cyberarm

Others

License

The gem is available as open source under the terms of the MIT License.

Credits

Tileset: https://opengameart.org/content/consolidated-hard-vacuum-terrain-tilesets

About

Tiled Wave Function Collapse model implemented in Ruby and rendered using Gosu

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •