Class: Knossos::Algorithm::Sidewinder
- Inherits:
-
Object
- Object
- Knossos::Algorithm::Sidewinder
- Defined in:
- lib/knossos/algorithm/sidewinder.rb
Instance Method Summary collapse
- #carve(grid:, seed: nil) ⇒ Object
-
#initialize ⇒ Sidewinder
constructor
A new instance of Sidewinder.
Constructor Details
#initialize ⇒ Sidewinder
Returns a new instance of Sidewinder.
4 5 6 |
# File 'lib/knossos/algorithm/sidewinder.rb', line 4 def initialize # nothing to do end |
Instance Method Details
#carve(grid:, seed: nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/knossos/algorithm/sidewinder.rb', line 8 def carve(grid:, seed: nil) srand(seed || Kernel.srand) grid.each_row do |row| run = [] row.each do |cell| run << cell if close_out_run?(grid, cell) member = run.sample north = grid.north(member) grid.build_passage(member, north) if north run.clear else east = grid.east(cell) grid.build_passage(cell, east) end end end grid end |