July 2015
Intermediate to advanced
286 pages
6h 31m
English
A maze made on a hex grid is, for some perverse reason, properly called a sigma maze. Fortunately, it works the same regardless of what you call it: just choose a maze algorithm and let it run its course. Let’s use the Recursive Backtracker algorithm to put our new to_png implementation through its paces. Put the following in a file named hex_maze.rb.
| hex_maze.rb | |
| | require 'recursive_backtracker' |
| | require 'hex_grid' |
| | |
| | grid = HexGrid.new(10, 10) |
| | RecursiveBacktracker.on(grid) |
| | |
| | grid.to_png.save('hex.png') |
Running it, you ought to get something like this figure. Very nice! It’s definitely working as we wanted. Experiment a bit with some other maze algorithms and see what you get, but be careful with Binary Tree ...
Read now
Unlock full access