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 Binary Tree Algorithm

The Binary Tree algorithm is, quite possibly, the simplest algorithm around for generating a maze. As its name suggests, it merely requires you to choose between two possible options at each step. For each cell in the grid, you decide whether to carve a passage north or east. By the time you’ve done so for every cell, you have a maze!

This process of looking at cells is called visiting them. Visiting them in some order is walking the grid. Some walks might be random, choosing directions arbitrarily from step to step, like the ones we’ll see in Chapter 4, Avoiding Bias with Random Walks. Others are more predictable. For Binary Tree, it turns out that we can do it either way. The algorithm really doesn’t care what ...

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