mazes_2018/binary_tree.rb

16 lines
275 B
Ruby
Raw Normal View History

2018-04-11 02:31:01 +00:00
class BinaryTree
def self.on(grid)
grid.each_cell do |cell|
neighbors = []
neighbors << cell.north if cell.north
neighbors << cell.east if cell.east
neighbor = neighbors.sample
cell.link(neighbor) if neighbor
end
grid
end
end