Implementing Better Weaving
Explore how to implement better weaving in maze generation by extending Kruskal's algorithm. Learn to add crossings thoughtfully, manage neighbor relationships, and customize the grid to produce well-structured weave mazes with controlled tunnel behavior.
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.
...