Think Differently

I have heard many answers like this from people who I ask why they don’t want to study at university. Many individuals question the significance of studying at university and believe that they don’t…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Chapter 1 Your First Random Mazes

Mazes for Programmers — by Jamis Buck (7 / 121)

👈 Part 1 The Basics | TOC | Preparing the Grid 👉

Maze-making seems magical when you’re outside looking in, but don’t be fooled. There is no magic. Starting on this very page, we’ll begin demystifying the processes that drive maze generation. We’ll see the scaffolding that lies just beneath their surface. We’ll get specific, talking about what exactly mazes are, and then we’ll get the ball rolling with two simple ways to create mazes, walking through them together with paper and pencil.

Eventually, this will take us to some exciting places, but like most beginnings, ours is quite humble. Here, it all starts with algorithms.

We’re going to focus on those algorithms that produce mazes randomly. Passage length, the number of dead ends, crossroad frequency, and how often passages branch will all be determined by randomly choosing from a prescribed list of possibilities.

There is no universally ideal algorithm for generating mazes, so over the course of this book we’ll explore twelve different ones. You’ll learn how to choose between them depending on your project’s needs, such as speed, memory efficiency, or simplicity (or even your own personal sense of aesthetics!). On top of that, most of the algorithms have little idiosyncrasies that cause the mazes they generate to share some feature, like short, stubby passages, or maybe the passages all skew a certain direction. We’ll explore those, too.

But we’ll get to that. By the end of this book you’ll be an expert, able to nimbly switch between these different algorithms to choose just the right one for the job. You’ll be pounding these out in code before you know it.

First, though, let’s do it on paper.

Joe asks:

Joe asks:

What’s an Algorithm?

An algorithm is just a description of a process. Like a recipe in a cookbook, it tells you what steps to take in order to accomplish some task. Any task. Algorithms exist for everything. If lasagna is your goal, then the steps you take to make lasagna are your algorithm. Want to make your bed, or drive to work? Both can be described as a series of steps. More algorithms! Algorithms launch rockets, land airplanes, drive cars, sort information, and search the Web. Algorithms solve mazes. And if you’re out to make a maze, like we are, your algorithm consists of the steps you take to make that maze.

👈 Part 1 The Basics | TOC | Preparing the Grid 👉

Add a comment

Related posts:

Death and Dying

I spend a fair amount of time considering death and dying and what it all means in the grand spectrum of this omnipotent universe I wonder if there is death or if our game just ends and we get…

Listing Immediate Subdirectories Using flatMap

Lambda expressions are lightweight, highly concise anonymous methods backed by functional interfaces in Java 8. You can use them to leap forward into a whole new world of programming in Java. With functional programming capabilities, which have been around for decades in other languages, you can now write elegant, concise, less

How Losing My Hair Taught Me to Listen

My hair has always shed. I cannot remember a time when I was not shedding. I have always had thick, long blonde hair. Family and loved ones are forever picking pieces of my hair off their clothes and…