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'

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.