Implementing Better Weaving
Learn how to include the crossings to implement better waving.
Reconditioning the Kruskals class
To implement better weaving, 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 class. With those changes in hand, generating the actual maze will be really straightforward.
So, first, we'll add the add_crossing method just after the merge method in the Kruskals::State class, which is highlighted below.
The updated Kruskals class
Code explanation
Line 42: This method will attempt to add a new crossing centered on the given cell, but it won’t do so blindly.
Line 43: Here, we make sure that the crossing is not centered on a cell that’s already been linked.
...