Introducing Our Basic Grid

The examples in this and later chapters will all build on one particular grid implementation, so we’ll spend a few pages on it here. This will be the tool we’ll use to build out our mazes, either by using this Grid class directly, or by subclassing it and adding more specific functionality. Seeing how it’s put together ought to make things clearer. We’ll start simple, and in the next few chapters we’ll add to it and extend it as needed.

What we want is to be able to instantiate the grid and operate on the cells that it contains. In pseudocode, something like this:

 
# instantiate a 10x10 grid
 
grid = Grid.new(10, 10)
 
 
# get the cell at row 1, column 2
 
cell = grid[1, 2]
 
 
# iterate over all the cells in the ...

Get Mazes for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.