Generating Weave Mazes

It turns out that generating weave mazes isn’t all that different from generating normal mazes. The trick is figuring out how to represent those passages that tunnel underneath the others. Once we’ve got those ironed out, we’ll work on a new Grid subclass with some more to_png tweaks, so we can draw these new tunneling passages.

To get an idea of how these new passages work, let’s take a minute and glance back at Figure 5, A Weave Maze. Pay attention to how and when the passages weave over and under each other. It’s not entirely arbitrary—there are four important rules that make this work unambiguously.

A passage cannot dead-end over or under another passage.
This prevents confusion that could happen when a passage seems ...

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.