Skip to Main Content
Mazes for Programmers
book

Mazes for Programmers

by Jamis Buck
July 2015
Intermediate to advanced content levelIntermediate to advanced
286 pages
6h 31m
English
Pragmatic Bookshelf
Content preview from Mazes for Programmers

Implementing a Polar Grid

To implement this improved polar grid, we’re going to introduce a new Cell subclass, and then walk through how these new cells will be laid out and subdivided. We’ll finish it all off with one last mostly cosmetic tweak to make our final maze as tidy as possible.

The PolarCell Class

First, the new Cell subclass. We’ve made do so far with using the existing Cell class, but it’s getting a bit unwieldy to keep referring to compass directions when they don’t map very intuitively to a polar grid. Also, with adaptive subdivision, some cells may now have two neighbors in the outward direction, and our existing Cell class has no support for that.

So, put the following in polar_cell.rb.

polar_cell.rb
Line 1 
require ​'cell'
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exercises for Programmers

Exercises for Programmers

Brian P. Hogan

Publisher Resources

ISBN: 9781680501315Errata Page