July 2015
Intermediate to advanced
286 pages
6h 31m
English
The algorithm really is as simple as described. First, we’ll “blank out” the grid by linking every cell to its neighbors (effectively removing all interior walls), and then recursively split the grid in half by adding walls back in.
Unlike the other algorithms we’ve implemented, we’re going to break this one into a few different methods to help with the recursion. It’ll all start with our typical on(grid) method, though. Put the following in recursive_division.rb.
| recursive_division.rb | |
| Line 1 | class RecursiveDivision |
| - | |
| - | def self.on(grid) |
| - | @grid = grid |
| 5 | |
| - | @grid.each_cell do |cell| |
| - | cell.neighbors.each { |n| cell.link(n, false) } |
| - | end |
| - | |
| 10 | divide(0, 0, @grid.rows, grid.columns) |
| - | end |