July 2015
Intermediate to advanced
286 pages
6h 31m
English
To make this work, we’re going to add a method to our Kruskals::State class so we can install those crossings in it. That method will be supported by a simple subclass of our WeaveGrid from the previous chapter. With those changes in hand, generating the actual maze will be really straightforward.
So, first things first, open up kruskals.rb and add the following method just after the merge method in Kruskals::State.
| Line 1 | def add_crossing(cell) |
| - | return false if cell.links.any? || |
| - | !can_merge?(cell.east, cell.west) || |
| - | !can_merge?(cell.north, cell.south) |
| 5 | |
| - | @neighbors.delete_if { |left,right| left == cell || right == cell } |
| - | |
| - | if rand(2) == 0 |
| - | merge(cell.west, cell) |
| 10 | merge(cell, cell.east) ... |