July 2015
Intermediate to advanced
286 pages
6h 31m
English
Let’s create a Mask class that will encapsulate the on-off state of each cell in our grid. That is to say, for each cell in the grid, our mask should be able to tell us whether or not it should be included in the maze. The following implementation does this by keeping a separate two-dimensional array of Boolean values, where false means the corresponding cell is “off the grid.”
Create a new file named mask.rb, and start it off with the following properties and constructor.
| mask.rb | |
| | class Mask |
| | attr_reader :rows, :columns |
| | |
| | def initialize(rows, columns) |
| | @rows, @columns = rows, columns |
| | @bits = Array.new(@rows) { Array.new(@columns, true) } |
| | end |
The initialize constructor is pretty straightforward, just recording ...