mazes_2018/binary_tree.rb
2018-04-10 22:31:01 -04:00

16 lines
275 B
Ruby

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