Class: Amaze::Algorithm::AldousBorder
- Inherits:
-
Amaze::Algorithm
- Object
- Amaze::Algorithm
- Amaze::Algorithm::AldousBorder
- Defined in:
- lib/amaze/algorithm/aldous_border.rb
Instance Attribute Summary
Attributes inherited from Amaze::Algorithm
Instance Method Summary collapse
Methods inherited from Amaze::Algorithm
Instance Method Details
#status ⇒ Object
33 34 35 |
# File 'lib/amaze/algorithm/aldous_border.rb', line 33 def status "Aldous-Border algorithm: #{@iterations} iterations in #{duration}s" end |
#work(grid) ⇒ Object
4 5 6 7 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/amaze/algorithm/aldous_border.rb', line 4 def work grid cell = grid.random_cell unvisited = grid.size - 1 @iterations = 0 # visualize pause = true # while unvisited > 0 yield Stat.new( # visualize current: [cell], # pause: pause, # info: "Iteration: #{@iterations += 1}") if block_given? # pause = false # neighbor = cell.neighbors.sample if neighbor.links.empty? pause = true # visualize cell.link neighbor unvisited -= 1 end cell = neighbor end grid end |