How to escape a maze – according to maths

I’m sure there’s an equation for this… Shutterstock

Mazes are in vogue at the moment, from NBO’s Westworld, to the return of the British cult TV series, The Crystal Maze. But mazes have been around for millennia and one of the most famous mazes, the Labyrinth home of the Minotaur, plays a starring role in Greek mythology.

Which begs the question: what is the difference between a maze and a labyrinth? Although considered synonymous by some, it is generally accepted that a labyrinth contains only one path, often spiralling around and folding back on itself, in ever-decreasing loops, whereas a maze contains branching paths, presenting the explorer with choices and the potential for getting very, very lost.

While designing a maze can be a rewarding human task, computer scientists and mathematicians have a love of maze-generating algorithms. The algorithms tend to fall into two principal types: ones which start with a single, bounded space and then sub-divide it with walls (and doors) to produce ever smaller sub-spaces; and others which start with with a world full of disconnected rooms and then demolish walls to create paths/routes between them.

The great escape

There are techniques for escaping from mazes, but first you need to be sure what kind of maze it is. Most methods work for “simple” mazes, that is, ones with no sneaky short-cuts via bridges or “passage loops” – circular paths that lead back to where they started.

So, assuming it is a simple maze, the method that many people know is “wall-following”. Essentially, you place one hand on a wall of the maze (it doesn’t matter which hand as long as you are consistent) and then keep walking, maintaining contact between your hand and the wall. Eventually, you will get out. This is because if you imagine picking up the wall of a maze and stretching its perimeter to remove any corners, you will eventually form something circle-like, part of which must form part of the maze’s outer boundary. This method of escape may not work, however, if the start or finish locations are in the maze’s centre.

But some mazes are deliberately designed to frustrate, such as the Escot Gardens’ beech hedge maze in Devon, which contains no fewer than five bridges, and so far from “simple”.

Another method of maze escape, known as Trémaux’s algorithm, works in all cases.

Imagine that, like Hansel and Gretel in the fairy story, you are able to leave a trail of “breadcrumbs” behind you as you navigate your way through the maze and then remember these rules: if you arrive at a junction you have not previously encountered (there will be no crumbs already on the trail ahead), then randomly select a way to go. If that leads you to a junction where one path is new to you but the other is not, then select the unexplored path. And if choosing between a once or twice-used path, choose the path used once, then leave a new, second trail behind you. The cardinal rule is never, ever select a path already containing two trails. This method is guaranteed, eventually, to get you out of any maze.

Everyday mazes

So how is any of this maze stuff useful? Well, from the perspective of architecture and urban design, we want to avoid accidentally creating mazes. Mazes are fun, but are not necessarily something we want in our everyday lives – or in our way when we just want to get to work.

In the 1980s, the architectural theorist, Bill Hillier, observed that many of the most socially problematic housing estates were those that appeared to be somewhat “maze-like” in their layout. This begged the theoretical question: how do we actually measure the “maze-iness” of a place?

Barnsbury, in London: extremely unmaze-like. Shutterstock

To answer this, Hillier developed the measure of “intelligibility”, which is the relationship between what is immediately visible from a single location in a maze/housing estate/neighbourhood and how accessible that same place is from other locations in the area. The measure ranges from 0 to 1: environments that score highly (greater than 0.5) tend to be quite intelligible, easy to understand and navigate, and frequently desirable – for example Barnsbury, in London.

Conversely, places with a low intelligibility score tend to be confusing, hard to navigate and, ultimately, maze-like – London’s Barbican Estate, although architecturally lauded, is so confusing that visitors need to follow the yellow lines in order to find their way around.

It was this measure of intelligibility that we used to design the game levels in the recent SeaHeroQuest game, a game designed to measure people’s navigational skills in order to further dementia research.

We “reverse-engineered” intelligibility in order to produce game levels that were more, or less, maze-like, to ensure a range of challenges for the players. Therefore, the mathematics of maze design is just as applicable in modern, dementia-battling apps as it was in distant Greek mythology.