Implementing Eller’s Algorithm
Eller’s algorithm works strictly one row at a time, so our implementation will take advantage of that by leaning on a row-centric state object. Once we have that state object, the rest of the algorithm comes together quickly.
We’ll start with the RowState class, which we’ll place under the namespace of the Ellers class. It will all go in ellers.rb.
ellers.rb | |
| class Ellers |
| |
| class RowState |
| def initialize(starting_set=0) |
| @cells_in_set = {} |
| @set_for_cell = [] |
| @next_set = starting_set |
| end |
| end |
| |
| end |
It’s certainly not much yet, but it does get us started. The initialize method has a starting_set parameter (defaulting to 0), which will be used to determine what value is used for new sets. It ...
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.