← All articles

17 November 2026

How a Maze-Solving Robot Finds Its Way Out

Illustration of a small robot in a maze, with distance numbers guiding it to the goal in the centre

Imagine a palm-sized robot placed at the entrance of a maze it has never seen. Nobody is steering it, there is no map to follow, and it cannot see the maze from above. Yet a few minutes later, it rolls into the goal square at the very centre — then turns around and races back along the shortest route, so fast your eyes can barely follow.

That is Micromouse, one of the oldest and most loved robotics competitions in the world: an autonomous robot solves a 16×16 grid maze, with the goal a 2×2 block right in the middle. And its lesson is a big one: the best robot is not the fastest robot, but the robot that remembers, plans, and fixes its plan when it discovers it was wrong.

The naive way: keep one hand on the wall

The first method almost everyone thinks of is wall following: keep one hand touching the wall on your right (or left) and walk forever. In a simple maze this can get you out — following one wall leads you along every passage connected to the outer wall.

But it fails badly in a Micromouse maze. The goal sits in the centre, cut off from the outer walls. A wall-following robot will circle around forever and never reach the goal square. That is the first lesson: a simple rule can be right in many cases and wrong in exactly the case that matters most. Engineers do not just need a method that is "usually right" — they need one that is "always right".

The patient way: walk to a dead end, then backtrack

The second method is depth-first search (DFS): walk straight until you hit a dead end, mark the path you took, walk back to the nearest junction, and try another direction. This is guaranteed to find the goal eventually, because it tries every passage in the end. But it is slow, and the first route it finds is rarely the shortest — the robot might wander through half the maze before stumbling onto the goal.

In a competition, time is the score. Reaching the goal is good, but taking a long winding route loses to another robot. So competing teams need an algorithm that finds a route and finds a short one — while it is still discovering the maze.

The champion's way: flood fill — imagine water spreading from the goal

The algorithm that wins most Micromouse competitions is called flood fill. Imagine pouring water into the goal square at the centre of the maze: the water spreads to the neighbouring squares, then spreads again, and every square gets a number — its distance to the goal. The goal square gets 0, its neighbours get 1, the next ones get 2, and so on until every square has a number.

The robot never has to remember a whole route. It just stands in a square, looks at its four neighbours, and steps into one whose number is exactly one lower. Follow the numbers downhill and you arrive at the goal. The "number map" itself is the plan — the robot stores distances, not a route.

The best part: the robot starts out knowing nothing about what the maze looks like. It assumes every wall it has not yet seen does not exist — a calculated optimism. That way it always has a plan to move forward instead of standing still exploring aimlessly. Whenever a sensor reveals a wall it thought was open, the robot records that wall on its map and recomputes all the numbers. The plan corrects itself, and the robot carries on from exactly where it stands. That is what makes flood fill special: it is designed for a map that is still changing, not a map that is already known.

Two runs: explore first, then race

A real competition robot runs the maze twice, with two different jobs:

And here is a detail that surprises most children: the shortest route is not always the fastest route. A longer route with few sharp turns can be quicker than a short route with 20 turns — at every turn the robot must slow down, rotate exactly 90 degrees, and speed up again. Champion teams count turning time in their planning, not just distance. That is engineering thinking: optimise the thing that is actually measured (time), not the thing that is easiest to measure (distance).

How does the robot know where it is?

The algorithm is only right when the robot knows exactly which square it is in. Miscount one square, or turn 88 degrees instead of 90 a few times, and the planner starts solving the maze for a robot that is somewhere else. The symptom is maddening: the algorithm is perfect, the wiring is fine, and the robot confidently drives straight into a wall.

So the hardest part of a maze-solving robot is not the algorithm — flood fill is only a few dozen lines of code. The hard part is driving straight and turning square: distance sensors (ultrasonic, or time-of-flight light sensors) to keep the right distance from the walls, a gyroscope to turn at exactly the right angle, and "re-squaring" its position whenever a front wall is available. That is also why teams always simulate the algorithm on a computer first, where position is exact by construction — prove the brain right, then teach the feet to walk right.

Try it with your child today

Start today, no kit needed

Your child can start exploring sensors, maps, and algorithms today on ManuStem — a browser-based robotics platform, no kit required, for ages 8+, with 28 lessons including 8 Component Lab lessons and 20 Competition Robot lessons, 4 of them free to try. The built-in AI co-pilot helps your child wire circuits, write code, and debug step by step, and the 3D robot preview shows their creation before it runs. Start at stem.manusignal.com — in Vietnamese or English, whichever your child prefers.

Read the Vietnamese version:

Robot vượt mê cung: robot tìm đường như thế nào