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

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'

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