Maze Solving Algorithms: Wall Follower, Tremaux, BFS and A* Explained
Maze solving algorithms are step-by-step methods for getting from a maze's entrance to its goal. The best known are the wall follower (keep one hand on the wall), Trémaux's method (mark the passages you've walked), dead-end filling (block off every dead end until only the route is left), breadth-first search, or BFS (spread out in waves to find the shortest path), and A* (a smarter search that heads toward the goal first). Some need no memory at all, some are guaranteed to work, and some always find the shortest route. Which one is "best" depends on whether you're standing inside the maze or looking down at it on paper.
In this guide we'll run every one of those methods on the same small maze, drawn as a table, so you can see exactly how they behave and where they go wrong. No programming is needed. If you can follow a set of directions, you can follow these.
Two ways to look at a maze
Before we start, it helps to separate two situations, because they call for different methods.
- Inside the maze: you're a person in a hedge maze, or a robot mouse on a table. You can only see the walls right around you. You don't have a map, so you need a method that works one step at a time.
- Above the maze: you're holding a printed maze, or a computer has the whole layout in memory. You can see everything at once, so you can use methods that look at the whole maze.
Walter D. Pullen's long-running maze reference, Think Labyrinth: Maze Algorithms, makes the same split. Some methods, like the wall follower and Trémaux's algorithm, are meant for someone inside the maze. Others, like dead-end filling and shortest-path searches, need to see the whole thing.
A couple of quick definitions will help too:
- Junction: a spot where you have more than one new way to go.
- Dead end: a spot with only one way in and no way forward.
- Perfect maze: Pullen defines it as a maze with no loops and no unreachable areas. That means there's exactly one path between any two spots. Most printed puzzle mazes are perfect mazes.
- Loop: a route that lets you walk in a circle and come back to where you were. Mazes with loops are trickier for some methods.
Our sample maze
Here's the maze we'll use for every method. Each table cell is one square. A # is a wall, a dot is an open square, S is the start and G is the goal. Columns are lettered A to G and rows are numbered 1 to 7, so you can name any square like a spreadsheet cell. The start is A2, and the goal is G4.
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | # | # | # | # | # | # | # |
| 2 | S | . | . | # | . | . | # |
| 3 | # | # | . | # | . | # | # |
| 4 | # | . | . | . | . | . | G |
| 5 | # | . | # | # | # | . | # |
| 6 | # | . | . | . | # | . | # |
| 7 | # | # | # | # | # | # | # |
Take a moment to solve it by eye. You'll find that it has 19 open squares (counting S and G), three dead ends (D6, F2 and F6) and three junctions (C4, E4 and F4). It's a perfect maze, so there's only one true route:
A2, B2, C2, C3, C4, D4, E4, F4, G4. That's 8 moves.
Now let's see how each algorithm finds it.
The wall follower: keep one hand on the wall
The wall follower is the method most people already know. Put one hand on a wall and never take it off. Pullen's reference describes it simply: keep one hand on the wall and turn consistently at every junction.
Here's the right-hand version as a step list. At every square, try these in order:
- Turn right, if that way is open.
- Otherwise go straight, if that way is open.
- Otherwise turn left, if that way is open.
- Otherwise turn around and go back.
Right-hand trace on our maze
We start at A2 facing east, into the maze. Following the four rules gives this walk:
| Stretch | Squares visited | What happened |
|---|---|---|
| 1 | A2, B2, C2, C3, C4 | Corridor down to the first junction |
| 2 | B4, B5, B6, C6, D6 | The right hand pulls us into the lower-left branch, which ends at D6 |
| 3 | C6, B6, B5, B4, C4 | Turn around and walk back out |
| 4 | D4, E4, F4 | Along the main corridor; the right hand skips the upper branch at E4 |
| 5 | F5, F6, F5, F4 | A short detour into the dead end at F6 |
| 6 | G4 | Goal |
That's 22 moves to cover a route that's really only 8 long. The method found the goal, but it explored two dead ends along the way.
Left-hand trace on our maze
Now swap hands: try left first, then straight, then right, then back. Starting at A2 facing east, the walk goes A2, B2, C2, C3, C4, D4, E4, then up into E3, E2, F2 (a dead end), back to E2, E3, E4, then F4 and G4. That's 14 moves.
| Method | Moves on our maze | Dead ends explored |
|---|---|---|
| Shortest path (for comparison) | 8 | 0 |
| Left-hand wall follower | 14 | 1 (F2) |
| Right-hand wall follower | 22 | 2 (D6 and F6) |
So the choice of hand matters a lot, and there's no way to know in advance which one will be luckier. Both always reach the goal in a maze like this one, though.
When the wall follower fails
The wall follower is guaranteed to work only when every wall is connected to the outer wall. Pullen calls these "simply connected" mazes, and every perfect maze is one. Trouble starts when a maze has an "island," a chunk of wall that floats free, surrounded by passages on every side.
Picture a goal in the middle of a maze, sitting inside a ring-shaped corridor. If you start at the outer edge and follow the wall, your hand stays on the outer walls the whole time. You'll walk all the way around the maze and arrive back at the entrance, never touching the island that holds the goal. Pullen describes exactly this: if the goal sits in the center surrounded by a closed loop, you'll go around the center and come back to the start.
That's why many hedge mazes with a goal in the middle are built with loops. They're designed to defeat the hand-on-the-wall trick.
The Pledge algorithm: escaping from the middle
What if you're dropped somewhere inside a maze and want to get out? A plain wall follower can trap you circling an island forever. The Pledge algorithm, which Pullen credits to Jon Pledge, fixes that with a simple counter.
- Pick a direction, say north, and walk that way whenever you can.
- When a wall blocks you, start wall-following (say, with your right hand on the wall).
- Keep a running total of your turns while wall-following: add 1 for each right turn and subtract 1 for each left turn.
- Only leave the wall and head north again when you're facing north and the total is back to exactly zero.
The counter is the clever part. Just facing north isn't enough, because you might be facing north after spinning a full circle around an island. Requiring the total to return to zero means you've "unwound" every turn, so you leave the obstacle on the far side instead of looping around it.
Here's a tiny illustrative counter log for walking around a square block of wall:
| Event | Turn | Running total | Facing | Leave the wall? |
|---|---|---|---|---|
| Hit the wall heading north | Left, to put the wall on your right | -1 | West | No |
| Reach the block's corner | Right | 0 | North | Yes, total is zero and facing north |
Compare that with a spiral: if you'd made four right turns and ended up facing north with a total of +4, you'd keep following the wall instead of walking off into the same trap again.
There's a catch. Pledge's method is great for reaching the outside edge of a maze, but Pullen notes it can't reliably find a goal inside the maze. For that, you need something with memory.
Trémaux's algorithm: mark your path
Trémaux's algorithm is the oldest method in this guide, and it works in any maze, loops and islands included. It needs only a way to mark passages, such as chalk, coins or bread crumbs that the birds don't eat.
The method first appeared in print in the French mathematician Édouard Lucas's book Récréations mathématiques, published in Paris by Gauthier-Villars (the 1883 printing is on the Internet Archive). In his chapter on labyrinths, Lucas credits the solution to "Trémaux, ancien élève de l'École Polytechnique," meaning a former student of France's famous engineering school. Lucas presents it as a method that lets you explore every passage of a labyrinth by walking each one at most twice.
Here's the method in modern words, following Pullen's version:
- As you walk a passage, mark it. A passage can end up with zero, one or two marks.
- At a dead end, turn around.
- At a junction you've never visited, pick any unmarked passage.
- If you reach a junction you've already visited, by way of a fresh passage, treat it like a dead end and turn back.
- If you reach a junction while walking back along a passage marked once, take an unmarked passage if there is one. If not, take a passage marked once.
- Never enter a passage that already has two marks.
When you reach the goal, the passages marked exactly once form a path straight back to the start.
Trémaux trace on our maze
Suppose we make the "wrong" choice at every junction, just to see the method recover. Choices at a fresh junction are free, so this is one possible run.
| At | Situation | Choice | Result |
|---|---|---|---|
| C4 | New junction; unmarked ways: B4, D4 | B4 | Walk to the D6 dead end, turn back. The B4 branch now has two marks. |
| C4 | Back on a twice-marked branch; unmarked way left: D4 | D4 | Continue east |
| E4 | New junction; unmarked ways: E3, F4 | E3 | Walk to the F2 dead end, turn back. The E3 branch now has two marks. |
| E4 | Unmarked way left: F4 | F4 | Continue east |
| F4 | New junction; unmarked ways: F5, G4 | G4 | Goal |
Now look at the marks. Every passage on A2, B2, C2, C3, C4, D4, E4, F4, G4 has exactly one mark. Both side branches have two. Follow the single marks and you have the solution, even after two wrong turns.
Dead-end filling: solving from above
If you can see the whole maze, there's a lovely pencil-and-paper method. Pullen calls it the dead end filler. Instead of searching for the path, you erase everything that isn't the path.
- Find every dead end (not counting the start and goal).
- Shade in each dead end, then keep shading backward along the corridor until you reach a junction.
- Shading can turn a junction into a new dead end. If it does, keep going.
- When no dead ends are left, the unshaded squares are the solution.
On our maze:
| Dead end | Squares filled | Stopped at |
|---|---|---|
| D6 | D6, C6, B6, B5, B4 | C4 (still has two other ways out) |
| F2 | F2, E2, E3 | E4 |
| F6 | F6, F5 | F4 |
Ten squares get filled. The nine left over (19 minus 10) are exactly the solution path. This method is fast and needs no memory, but Pullen notes it does little in mazes with lots of loops and few dead ends, which he calls braid mazes. It's the method a lot of people use without realizing it when they solve printable mazes by "working backward" from the dead ends.
Breadth-first search: the shortest path, guaranteed
Now we move to the methods computers use. Breadth-first search, or BFS, explores a maze in waves. It checks every square 1 step from the start, then every square 2 steps away, then 3, and so on. Because it expands evenly in all directions, the first time it reaches the goal, it has found a shortest path. BFS is a standard topic in university algorithms courses, such as MIT's Introduction to Algorithms lecture on breadth-first search.
Here's the step list:
- Write the start square on a list (programmers call this list a queue) and label it 0.
- Take the first square off the list.
- For each open neighbor that has no label yet, label it with one more than the current square, note which square you came from, and add it to the end of the list.
- Repeat steps 2 and 3 until you label the goal.
- Follow the "came from" notes backward from the goal to the start. That's your path.
If you like code, the core idea fits in a few lines:
queue = [start]; distance[start] = 0
while the queue is not empty: take the first cell off the queue
for each open neighbor n of that cell with no distance yet: distance[n] = distance[cell] + 1; came_from[n] = cell; add n to the end of the queue
BFS wave by wave on our maze
| Distance from start | Squares reached |
|---|---|
| 0 | A2 |
| 1 | B2 |
| 2 | C2 |
| 3 | C3 |
| 4 | C4 |
| 5 | B4, D4 |
| 6 | B5, E4 |
| 7 | B6, E3, F4 |
| 8 | C6, E2, F5, G4 (goal) |
BFS reaches the goal at distance 8, which matches the true shortest path. Following the "came from" notes back from G4 gives F4, E4, D4, C4, C3, C2, B2, A2. By the time it found the goal, BFS had labeled 16 of the 19 open squares. It never needed D6, F2 or F6.
Two things make BFS special. It's guaranteed to find the goal if any path exists, and the path it finds is always as short as possible, even in mazes full of loops. The price is memory. It has to remember every square it has labeled, which is fine for a computer but hard to do in your head inside a hedge maze.
Dijkstra's algorithm: when some steps cost more
BFS assumes every step costs the same. But what if some squares are slow, like mud in a video game or stairs in a building? Dijkstra's algorithm, named after the Dutch computer scientist Edsger Dijkstra, handles that. Jamis Buck's book Mazes for Programmers uses it both to solve mazes and to analyze them.
The idea is the same as BFS, with one change: instead of always taking the oldest square off the list, you always take the square with the smallest total cost so far.
Here's a tiny illustrative example. Two routes lead from the start to the goal:
| Route | Steps | Cost of each step | Total cost |
|---|---|---|---|
| Short but muddy | 3 | 1, 5, 1 | 7 |
| Long but dry | 5 | 1, 1, 1, 1, 1 | 5 |
BFS would pick the 3-step route, because it counts steps. Dijkstra's algorithm picks the 5-step route, because its total cost is lower (5 versus 7). In a plain maze where every step costs 1, Dijkstra's algorithm and BFS give the same answer.
A*: searching with a sense of direction
BFS spreads out evenly, which wastes effort exploring away from the goal. A* (said "A star") fixes that by adding a guess about how far each square is from the goal. It was introduced in 1968 by Peter Hart, Nils Nilsson and Bertram Raphael in a paper titled "A Formal Basis for the Heuristic Determination of Minimum Cost Paths" in IEEE Transactions on Systems Science and Cybernetics.
A* gives each square a score:
- g is the number of steps from the start to this square (what BFS already counts).
- h is a guess of the steps left to the goal. On a grid, a common guess is the Manhattan distance: the number of columns apart plus the number of rows apart, as if there were no walls.
- f = g + h is the estimated length of the whole trip through this square.
A* always explores the square with the lowest f next. As long as the guess never overestimates the true distance, A* still finds a shortest path. That kind of guess is called an admissible heuristic, a term you'll find in MIT's course lecture on optimal search and A*. Manhattan distance is admissible in our maze, because walls can only make the real path longer, never shorter.
A* on our maze
The goal G4 is in column 7 (G) and row 4. So, for example, C4 is 4 columns and 0 rows away, giving h = 4.
| Order explored | Square | g (steps so far) | h (guess to goal) | f = g + h |
|---|---|---|---|---|
| 1 | A2 | 0 | 8 | 8 |
| 2 | B2 | 1 | 7 | 8 |
| 3 | C2 | 2 | 6 | 8 |
| 4 | C3 | 3 | 5 | 8 |
| 5 | C4 | 4 | 4 | 8 |
| 6 | D4 (B4 waits with f = 5 + 5 = 10) | 5 | 3 | 8 |
| 7 | E4 | 6 | 2 | 8 |
| 8 | F4 (E3 waits with f = 7 + 3 = 10) | 7 | 1 | 8 |
| 9 | G4, the goal (F5 waits with f = 8 + 2 = 10) | 8 | 0 | 8 |
A* explored just 9 squares, the solution path itself, while the side branches sat waiting with higher scores. BFS labeled 16. On a big maze, that difference can be enormous. It's the reason A* is so widely used for route-finding in games, maps and robots.
In fairness, our maze is kind to A*. The direct route mostly heads toward the goal. In a maze where the true path has to swing far away from the goal first, the guesses mislead A* for a while and it explores more. It still finds the shortest path, just with more work.
Comparing maze solving algorithms side by side
Here's how all the methods stack up, combining our traces with the properties listed in Pullen's reference:
| Method | Works from inside the maze? | Needs memory or marks? | Always finds the goal? | Always shortest? | Result on our maze |
|---|---|---|---|---|---|
| Wall follower | Yes | No | Only in simply connected mazes | No | 14 or 22 moves |
| Pledge | Yes | A turn counter | Reaches the outer edge; not inner goals | No | Not needed here (we already start at the edge) |
| Trémaux | Yes | Marks on passages | Yes | No (yes in a perfect maze, where there's only one path) | Found the path after 2 detours |
| Dead-end filling | No, needs the full map | No | Yes in perfect mazes | In a perfect maze there's only one path | 10 squares filled, path left |
| BFS | No, needs the full map | Yes | Yes | Yes | 16 squares labeled |
| Dijkstra | No, needs the full map | Yes | Yes | Yes, by total cost | Same as BFS (all steps cost 1) |
| A* | No, needs the full map | Yes | Yes | Yes, with an admissible guess | 9 squares explored |
What changes when a maze has loops
Our sample maze is a perfect maze, so every method that finishes finds the same path. Loops change that. Here's a second small maze where two routes lead to the goal. Again, # is a wall, S is the start (A2) and G is the goal (E4).
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | # | # | # | # | # |
| 2 | S | . | . | . | # |
| 3 | # | . | # | . | # |
| 4 | # | . | . | . | G |
| 5 | # | # | # | # | # |
The squares B2, C2, D2, D3, D4, C4, B4 and B3 form a ring around the wall at C3. From B2 you can go either way around the ring to reach D4 and then the goal. Both routes take the same number of moves: A2, B2, C2, D2, D3, D4, E4 is 6 moves, and so is A2, B2, B3, B4, C4, D4, E4.
Here's how the methods react:
- Wall follower: it still works, because the goal is on the outer edge and the start is too. The ring's inner wall (C3) is an island, but the outer walls lead to the goal.
- Trémaux: works. If you go around the ring and arrive back at a junction you've already visited, the rule tells you to treat it like a dead end and turn back, so you never loop forever.
- Dead-end filling: stalls. This maze has no dead ends at all, so there's nothing to fill. You're left with the whole ring and must choose a side yourself. That's what Pullen means when he says the method does little in braid mazes.
- BFS: works and finds a 6-move path. The two waves around the ring meet at D4, and whichever reaches it first gets recorded as the route.
- A*: works and finds a 6-move path, usually with less exploring, because the guess steers it toward E4.
Now imagine a bigger version where the goal sits in a pocket that can only be reached from the inner side of a ring, with the ring's center wall standing free of the outer wall. A wall follower starting at the outer edge would keep its hand on the outer walls, trace the outside of the maze and return to the start without ever touching the inner side of the ring. That's the island trap. Trémaux's method and BFS would still find the goal, because they don't depend on which wall you're touching.
Common mix-ups about maze solving
- "Any maze can be solved by keeping a hand on the wall." Only simply connected ones, where every wall links to the outside. A goal on an island defeats it.
- "BFS and depth-first search are the same." They aren't. Depth-first search follows one branch as far as it can before backing up, much like Trémaux's method. It finds a path but not necessarily the shortest one in a maze with loops. BFS spreads in waves and always finds a shortest path.
- "A* is always faster than BFS." Usually, but not always. With a misleading guess, or a path that has to wander far from the goal, A* can explore nearly as much as BFS.
- "Labyrinths need solving algorithms too." A classic single-path labyrinth has no choices at all, so there's nothing to solve. You just walk. Algorithms matter only when there are junctions.
Theseus: the first maze-solving machine
Maze solving became a computing problem surprisingly early. In 1950, Claude Shannon, the Bell Labs mathematician and engineer, built a mechanical mouse named Theseus. MIT Technology Review tells its story: the maze had 25 squares with metal walls that could be moved around, so the mouse had to learn each new layout.
The mouse itself was just a small wooden shape with a magnet and copper "whiskers." The real brain was a bank of telephone relay switches hidden under the maze floor, and an electromagnet on a motorized carriage pulled the mouse along. When a whisker touched a wall, a relay flipped to record it, and the mouse turned 90 degrees and tried again. Once it had found the goal, the relays held the solved route, and the mouse could run straight to the target. In a 1952 film shot at Bell Labs, it reached the goal, a brass piece of "cheese" that triggered a buzzer, in 18 seconds after its learning run.
The article notes that the original maze no longer works but is part of the MIT Museum's collection. Theseus explored by trial and error and then remembered, which is the same two-phase idea that modern robot mice still use.
Micromouse: maze solving as a sport
Shannon's idea lives on in Micromouse, a robotics competition where small autonomous robots race through a maze. The rules for the classic event from Japan's New Technology Foundation, which runs the All Japan Micromouse Contest, give a good picture:
- The maze is 16 x 16 squares, each 18 cm by 18 cm, with walls 5 cm high.
- The robot starts in a corner, and the goal is the four squares at the center.
- Each robot typically gets 10 minutes and up to 5 runs. Its official time is its fastest single run from start to goal.
- There are extra awards, including a Search Prize for the fewest steps to the goal on the first run.
That format rewards a two-part strategy. On the first runs, the robot explores and builds a map, working like someone inside the maze. Once it knows enough, it computes the shortest route, working like someone above the maze, and then races it. Notice the goal is in the center, which is exactly the setup that can defeat a simple wall follower. A robot that only followed walls could circle the outside forever.
Which maze solving algorithm should you use?
Here's a quick guide for real-life situations:
- Lost in a hedge or corn maze with an exit on the edge: use the wall follower. It's simple and you don't need to remember anything.
- Looking for a goal in the center of a hedge maze: use Trémaux's method. Leave small markers at junctions, such as a stone pointing back the way you came.
- Solving a printed maze with a pencil: try dead-end filling, especially on difficult mazes with long, twisty dead ends.
- Writing a program: use BFS for plain grids, Dijkstra's algorithm if steps have different costs and A* when you want speed on large maps.
For teachers, mazes are a great hands-on way to introduce algorithms. Our article on maze maker uses has classroom ideas, and mazes for kids are a gentle place to practice wall following before moving to bigger grids.
Try it yourself: race the algorithms
You can test everything in this guide with a pencil and a few printed mazes.
- Print three mazes of rising difficulty, such as an easy maze, a medium maze and one of our mazes for adults.
- Solve the first with the right-hand rule, tracing your finger along the wall and counting squares. Then try the left-hand rule and compare the counts.
- Solve the second by dead-end filling. Shade every dead end until the route appears. Time yourself.
- Solve the third with BFS by hand. Write 0 at the start, 1 in the squares next to it, 2 in the squares next to those, and so on. When you reach the goal, count back down to 0 to trace the shortest path.
- Compare. Which method felt fastest? Which made fewest mistakes? Most people find dead-end filling fastest on paper and BFS the most reliable.
Make mazes to test your algorithms
Maze solving algorithms range from the hand-on-the-wall trick anyone can use to A*, which powers route-finding in games and robots. The wall follower is simple but can be fooled by islands. Trémaux's 19th-century method always works if you can mark your path. Dead-end filling is a pencil solver's best friend. And BFS, Dijkstra and A* find the shortest route when you can see the whole map.
Want fresh mazes to practice on? Our free puzzle maker lets you pick a theme, choose a puzzle type such as a maze, and print it with an answer key, so you can check whether your algorithm found the right route.
Seven Maze Methods and Where Each Fits
This table sums up each method in plain words and says which situation suits it best.
| Method | The idea in plain words | Best fit |
|---|---|---|
| Wall follower | Keep one hand on the wall and turn consistently at every junction | Lost in a hedge or corn maze with an exit on the edge, since you don't need to remember anything |
| Pledge | Keep a running count of your turns and leave the wall only when facing your chosen direction with the total back at zero | Escaping to the outside edge, though it can't reliably find a goal inside the maze |
| Trémaux's method | Mark the passages you've walked | Looking for a goal in the center of a hedge maze, using small markers at junctions |
| Dead-end filling | Block off every dead end until only the route is left | Solving a printed maze with a pencil, especially one with long, twisty dead ends |
| Breadth-first search (BFS) | Spread out in waves to find the shortest path | Writing a program for a plain grid |
| Dijkstra's algorithm | Always take the square with the smallest total cost so far | Mazes where some steps cost more than others |
| A* | A smarter search that heads toward the goal first | Speed on large maps |
Frequently Asked Questions
Does the right-hand rule always solve a maze?
Only in some mazes. Keeping one hand on the wall always works when every wall connects to the outer wall, which is true of perfect mazes with no loops. It fails when the goal sits on an island, a section of wall surrounded by passages on all sides. Then your hand stays on the outer walls, and you circle back to the entrance without ever reaching the goal. Many hedge mazes with a goal in the center are built with loops for exactly this reason.
What is the fastest maze solving algorithm?
It depends on what you mean by fastest. If you want the shortest route and can see the whole maze, A* usually explores the fewest squares, because it uses a guess about the distance left to steer toward the goal. Breadth-first search also finds the shortest route but explores more evenly in every direction. On paper, many people find dead-end filling the quickest by hand. Inside a maze with no map, the wall follower is quickest to use because it needs no memory.
What is Trémaux's algorithm?
It's a method for solving any maze from the inside by marking the passages you walk. You never enter a passage marked twice, you turn back at dead ends and at old junctions reached by a new route, and you prefer unmarked passages at junctions. When you reach the goal, the passages marked once lead straight back to the start. It first appeared in print in Édouard Lucas's Récréations mathématiques in the 1880s, where Lucas credits a former student of the École Polytechnique named Trémaux.
What is the difference between BFS and A*?
Both find a shortest path, but they search differently. Breadth-first search spreads out in even waves, checking every square one step away, then two steps away, and so on, with no idea where the goal is. A* adds a guess of the remaining distance, often the Manhattan distance of columns plus rows apart, and always explores the most promising square next. As long as the guess never overestimates, A* still finds a shortest path while usually exploring far fewer squares than BFS.
How did Claude Shannon's maze mouse work?
Shannon's 1950 mouse, Theseus, ran on a 25-square maze with movable metal walls. The wooden mouse had copper whiskers, but its real brain was a bank of telephone relays under the maze floor, and an electromagnet on a motorized carriage pulled it around. When a whisker hit a wall, a relay recorded it, and the mouse turned and tried another way. Once it found the goal, the relays held the route, so the mouse could run straight to the target on later runs.
What is the Pledge algorithm used for?
The Pledge algorithm helps you escape a maze when you start somewhere in the middle. You pick a direction and walk it whenever you can. When blocked, you follow the wall while counting turns, adding one for each right turn and subtracting one for each left. You only leave the wall when you face your chosen direction and the count is back to zero. That stops you from circling an island forever. It reliably reaches the outer edge, but it can't reliably find a goal inside the maze.
How do Micromouse robots solve mazes?
Micromouse robots race through a 16 by 16 maze of 18 cm squares to reach the four squares in the center, starting from a corner. Under classic rules from Japan's New Technology Foundation, a robot usually gets 10 minutes and up to 5 runs, and its official time is its fastest single run. That encourages a two-phase plan: explore the maze and map the walls on early runs, then compute the shortest known route and race it on later runs.
What is dead-end filling in maze solving?
Dead-end filling is a way to solve a maze when you can see the whole thing, such as a printed puzzle. You find each dead end and shade it in, then keep shading back along the corridor until you hit a junction. Filling can turn a junction into a new dead end, so you keep going until none are left. What remains unshaded is the solution. It's fast and needs no memory, but it does little in mazes with many loops and few dead ends.
Sources
We checked every source below while writing this guide. Last reviewed October 30, 2026, by Joan Ramos.
- Think Labyrinth: Maze Algorithms (Walter D. Pullen) (Think Labyrinth (astrolog.org))
- Récréations mathématiques (Édouard Lucas, 1883 printing) (Gauthier-Villars, via Internet Archive)
- Mighty mouse (December 19, 2018) (MIT Technology Review)
- A Formal Basis for the Heuristic Determination of Minimum Cost Paths (Hart, Nilsson and Raphael, 1968) (IEEE Transactions on Systems Science and Cybernetics)
- Lecture 9: Breadth-First Search, Introduction to Algorithms 6.006 (MIT OpenCourseWare)
- Lecture 5: Search: Optimal, Branch and Bound, A*, 6.034 (MIT OpenCourseWare)
- Micromouse Classic Rules (New Technology Foundation (All Japan Micromouse Contest))
- Mazes for Programmers (Jamis Buck, 2015) (The Pragmatic Bookshelf)




