Review: ‘Mazes for Programmers’

Books Geek Culture

I picked up Mazes for Programmers when it first came out because I like puzzles and I’m a programmer. If I’m not the target audience, who is? I don’t have a need for maze-generating algorithms in my day job, but I like learning new corners of the programming world.

I’ve stopped and started it over the years, always heavily intrigued by it but then pulled away by this or that other project. I recently sat down with it again, determined to make good progress. I’m glad I did. While I haven’t finished the book yet, I’ve had a lot of fun learning about the guts of maze generation.

Author Jamis Buck starts you off simple. A couple of paper-and-pencil algorithms that will generate passable mazes. These two algorithms set the tone for the rest of the book. Buck gives clear explanations of how this or that algorithm works before diving into the source code that will let you do it on your own computer.

Cover of _Mazes for Programmers_

The book does have “for programmers” in the title, and it means it. You should be comfortable writing and editing code; outside of the maze algorithms, Buck assumes you’re already familiar with lists, maps, inheritance, and other workhorses of the programmer’s life. But you don’t have to be a superstar programmer. Even if you’ve written reasonably complicated scripts, that should be enough to get you to understand the book. And while Buck notes that the algorithms can be implemented in any language — for this go-around I decided to write my maze generation in go — you’ll be best served on your first pass if you know a little Ruby. That way, it’s easy to debug — at a minimum, you can always compare your code to his — and you won’t be scratching your head about some of the idiomatic Ruby in the book. If you don’t know Ruby, Python would probably map pretty easily. But even if you don’t know either of those languages, Buck explains the source code carefully enough that you’ll be able to figure out the gist of what’s going on.

Mazes For Programmers will certainly give you a good introduction to a dozen maze algorithms, but it goes a lot farther than that. At one point, Buck shows you how to paint the mazes so you can get a sense of their texture and the long paths going through them (using Dijkstra’s algorithm, a handy tool for your programming utility belt). Woven into the text are thoughts about the philosophy of what makes good mazes. He covers masking as a way to make mazes with bits chipped away. One section pulls in the mathematics of circles for drawing circular mazes and expands the code to make hexagonal mazes and more. And in the end, he covers mazes on 3D surfaces. By the end, you’ll have learned a lot about mazes and a little bit about a bunch of other concepts.

Liked it? Take a second to support GeekDad and GeekMom on Patreon!