Mazes for Programmers
eBook - ePub

Mazes for Programmers

Code Your Own Twisty Little Passages

  1. 286 pages
  2. English
  3. ePUB (mobile friendly)
  4. Only available on web
eBook - ePub

Mazes for Programmers

Code Your Own Twisty Little Passages

Book details
Table of contents
Citations

About This Book

From video games to movies, mazes are ubiquitous. Explore a dozen algorithms for generating these puzzles randomly, from Binary Tree to Eller's, each copiously illustrated and accompanied by working implementations in Ruby. You'll learn their pros and cons, and how to choose the right one for the job.

You'll start by learning six maze algorithms and transition from making mazes on paper to writing programs that generate and draw them. You'll be introduced to Dijkstra's algorithm and see how it can help solve, analyze, and visualize mazes. Part 2 shows you how to constrain your mazes to different shapes and outlines, such as text, circles, hex and triangle grids, and more. You'll learn techniques for culling dead-ends, and for making your passages weave over and under each other. Part 3 looks at six more algorithms, taking it all to the next level. You'll learn how to build your mazes in multiple dimensions, and even on curved surfaces.

Through it all, you'll discover yourself brimming with ideas, the best medicine for programmer's block, burn-out, and the grayest of days. By the time you're done, you'll be energized and full of maze-related possibilities!

Q&A with Jamis Buck, author of Mazes for Programmers

It has to be asked: Why mazes?

You know, I came to programming because it fascinated me. There was something magical and wonderful about itā€”this idea that I could write a few commands in some cryptic syntax and make something happen. It was powerful! I don't think I'm unique that way. I think a lot of us come to programming like that.

But somewhere along the line we generally lose that sense of the magical. Maybe it gets drowned in the mundane tasks we typically use these amazing tools for, I don't know. But when the magic goes away, so does the wonder. So does the fun.

For me, mazes take me back to those days when programming was fun, when I'd sit down and start coding simply to see what might happen! Every random maze is unique, and the algorithms lend themselves well to variation and experimentation. It becomes this iterative game of "what if, " for me. What if I make this condition more or less likely? What if I disallow this set of cells in the grid? What if I use color to visualize this or that aspect of the maze?

So, why mazes? Because they bring the wonder and the fun back into programming.

How did you come to write this book?

Would you believe there aren't any other books solely about maze algorithms? I couldn't. There are lots of great resources online about them, but if you want to learn how to generate a maze in more than just one or two ways, you wind up having to do a fair bit of research. You glean a bit of information here, a bit more there, you tinker and experiment until you get something working, and then you do it all over again for the next algorithm.

Some years ago I wrote a series of blog articles summarizing my own explorations in just this vein, and they were pretty well-received. Some readers suggested I write a bookā€¦and I'm embarrassed to admit that it took me a few years to take them seriously. But I did, and here I am!

Why are there so many algorithms for generating mazes?

You can't write software for very long before realizing that there are lots of different ways to solve problems in code. There are at least a dozen different ways to sort information, for instance, and each one has different strengths and weaknesses. Just so with maze algorithms, too. Depending on your need for memory efficiency, speed, and esthetics, the variety of maze algorithms let you choose one that will best fit your needs.

Besides, life would be a bit less wonderful if there were only one way to generate mazes. I like to celebrate the fact that there are that many more things to explore!

What's your favorite maze algorithm?

I don't know that I could pick just oneā€¦ I love the novelty of the Recursive Division algorithm, and how it works so well to add "rooms" to the mazes. One of my favorite projects recently was implementing a variation on Recursive Division that split each space into "blobs, " instead of rectangular spaces, and that gave some really nice results.

I've always loved the Recursive Backtracker algorithm, though. The esthetics of the long, winding passages that it produces really appeals to me, and the algorithm itself can be used to solve as well as create mazes!

What do you hope readers take away from the book?

More than anything, I want them to come away with a new sense of wonder for computer programming. I hope they find themselves remembering their own first steps into the world of software development, and rediscovering that joy of learning and exploring.

My favorite thing about writing this book has been the times that readers have contacted me to show me something wonderful that they've created as a result of what they've learned. One man used the masking chapter to write a program that generated mazes in the shape of his child's name, which apparently earned him "dad-of-the-year" in their house! I love that stuff so much.

What's your favorite part of the book?

Since I suppose you won't be happy if I simply answer "all of it, " I'll say that I really enjoyed writing the last chapter, the one about mazes on non-planar surfaces. I got very side-tracked on that one and as part of my "research" wrote an OpenGL program that built a maze on a sphere, and then allowed the player to navigate through it!

That kind of thing happened throughout the process of writing the book, though. Every algorithm suggested curious little projects to me, and I had to stop for a bit and explore sometimes. I hope the readers find themselves similarly distracted!

Frequently asked questions

Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes, you can access Mazes for Programmers by Jamis Buck in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Algorithms. We have over one million books available in our catalogue for you to explore.

Information

Table of contents

  1. Mazes for Programmers