O'Reilly logo

Mazes for Programmers by Jamis Buck

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required