O'Reilly logo

Mazes for Programmers by Jamis Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required