Class: Knossos::Algorithm::BinaryTree
- Inherits:
-
Object
- Object
- Knossos::Algorithm::BinaryTree
- Defined in:
- lib/knossos/algorithm/binary_tree.rb
Instance Attribute Summary collapse
-
#bias ⇒ Object
readonly
Returns the value of attribute bias.
Instance Method Summary collapse
- #carve(grid:, seed: nil) ⇒ Object
-
#initialize(**options) ⇒ BinaryTree
constructor
A new instance of BinaryTree.
Constructor Details
#initialize(**options) ⇒ BinaryTree
Returns a new instance of BinaryTree.
6 7 8 9 10 |
# File 'lib/knossos/algorithm/binary_tree.rb', line 6 def initialize(**) = defaults.merge() @bias = [:bias] end |
Instance Attribute Details
#bias ⇒ Object (readonly)
Returns the value of attribute bias.
4 5 6 |
# File 'lib/knossos/algorithm/binary_tree.rb', line 4 def bias @bias end |
Instance Method Details
#carve(grid:, seed: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/knossos/algorithm/binary_tree.rb', line 12 def carve(grid:, seed: nil) srand(seed || Kernel.srand) grid.each_cell do |cell| neighbors = bias.map { |direction| grid.send(direction, cell) }.compact neighbor = neighbors.sample grid.build_passage(cell, neighbor) if neighbor end grid end |