The Sidewinder Algorithm
Here’s an algorithm called the Sidewinder, which, though closely related to the Binary Tree, still manages to dial back the biases a notch. Recall that Binary Tree chooses between north and east at every cell; Sidewinder, on the other hand, tries to group adjacent cells together before carving a passage north from one of them. Go ahead and grab another piece of paper, sketch another grid on it, and we’ll jump right in.
Now, unlike Binary Tree, the Sidewinder won’t easily let us start carving anywhere we like. It has a strong preference for beginning in the western column, so that’s where we’ll start. In fact, we might as well start where we did before, in the southwest corner. I’ll just flip a coin for both of us, as ...
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.