Maze Solver Robot Simulator for Flood-Fill Planning
Run a maze solver robot simulator in your browser. Watch the robot sense walls, update its map, and choose each flood-fill move step by step.
- Category
- ESP32
- Time
- 2–4 hours
- Platform
- Browser · ESP32
01 / Start here
Introduction
Maze-solving robots combine local sensors with an internal map. This interactive lab makes that loop visible: the robot senses left, front, and right walls, records reciprocal edge knowledge, recomputes an optimistic flood-fill field, and advances one cell toward the center. Step through each decision before adapting the same architecture to an ESP32 robot.
Live lab / Local mapping and flood fill
Maze solver simulator
Watch a robot sense walls, update its map, and choose each flood-fill move from only the edges it has observed.
Solid neutral lines are the physical maze. Thicker solid lines are mapped walls, dashed edge marks are unknown, short ticks are known open, and the triangle shows the robot heading.
- Physical wall
- Mapped wall
- Robot trail
- Goal
- Cell
- Row 8, column 1
- Heading
- North
- Moves
- 0
- Explored
- 1 / 64
- Mapped walls
- 0
- Replans
- 0
- Optimal
- —
- Efficiency
- —
Keyboard: focus the maze, then use Space to run/pause, N to step, R to reset, and F for full screen.
Controls
Choose Open course, Switchbacks, or Dead ends, then run the robot at three speeds or advance exactly one cell with Step. Start, Pause, Reset, keyboard shortcuts, and Full screen keep the experiment controllable. The map distinguishes physical walls, mapped walls, unknown edges, known-open edges, visited cells, flood distances, the robot trail, and its current heading.
Theory
A grid maze can be represented as cells connected by passable edges. The robot does not begin with the full graph; it discovers left, front, and right walls from its current heading and records each observation on both sides of the shared edge. Boundary walls are known from the fixed maze dimensions.
Flood fill assigns the center goals a value of zero and propagates increasing values through every edge not known to be blocked. Unknown edges remain optimistically open. When sensing reveals a new wall, the simulator recomputes the field and chooses a safe neighbor one level closer to the goal, preferring unvisited cells and deterministic turns on ties.
Algorithm
- Align the robot with a cell and classify its left, front, and right edges.
- Store each blocked or open observation reciprocally for the current cell and its neighbor.
- Recalculate flood-fill distances when a newly discovered wall changes the known map.
- Choose a safe neighbor one distance level lower, preferring an unvisited cell, then the smaller turn.
- Move exactly one cell, record the trail and heading, and repeat until a center goal is reached.
- Compare the completed move count with the truth-map optimum to measure exploration efficiency.
Source code
Keep the planning core independent of motor and sensor drivers:
void planOneCell(Maze& map, Robot& robot) {
map.observe(robot.cell(), robot.senseLeftFrontRight());
map.floodFill(centerGoals);
Cell next = map.bestDescendingNeighbor(robot.cell());
robot.turnAndMoveTo(next);
}
Keep sensing, mapping, planning, and motion as separate functions. That boundary makes the same planner testable in this browser lab, on a desktop, and on the final controller.
Circuit diagram
Use an external regulator sized for the motor stall current. The ESP32 and sensors need a stable logic rail even when motors reverse.
Hardware checklist
Components
- ESP32 development board
- Three time-of-flight or infrared distance sensors
- Two encoder-equipped geared motors
- Dual motor driver and regulated battery supply
- Compact differential-drive chassis
Continue building
Download resources
Use these on-page references while working through the project. Downloadable project bundles will be added only after their source and version are published.
Common questions
Frequently asked questions
Which maze algorithm is best for a first robot?
Flood fill is a strong teaching choice for a grid maze because every reachable cell receives a distance value and each movement decision can be inspected. This simulator uses one deterministic flood-fill planner so sensing, mapping, and replanning stay clear.
Why doesn't flood fill find the shortest path on the first run?
On the first run the robot has not seen the whole maze, so it treats unknown walls as open and follows the current best guess toward the goal. Real Micromouse robots use two phases: an exploration run that discovers enough of the maze, then a fast run along the shortest path that the completed map reveals. Exploration efficiency, not first-run optimality, is the goal early on.
How is flood fill different from BFS or A*?
BFS and A* plan over a graph you already know. Flood fill is designed for a maze you are still discovering: it assigns the goal distance zero and floods increasing values outward through every edge not known to be blocked, then recomputes whenever a newly sensed wall changes the map. The distance field itself encodes the route, so the robot just steps to any neighbor one value lower.
Why does the robot treat unknown walls as open?
Optimism keeps the robot moving toward the goal instead of exploring pointlessly. Assuming unknown edges are passable produces the shortest possible estimate; when a sensor later reveals a wall, the flood-fill field is recomputed and the plan corrects. This is far more efficient than assuming the worst everywhere.
What sensors does a Micromouse or maze robot need?
At minimum, distance sensors looking left, front, and right to classify the walls of the current cell, plus wheel encoders to move an accurate number of cells and square up turns. Time-of-flight or infrared distance sensors are common; encoders matter because wall sensing alone cannot tell you how far you have travelled.
Why use flood fill instead of wall following?
Wall following (always keep one hand on a wall) is simple but cannot reach a goal that is not attached to the outer wall, such as the centre of a Micromouse maze, and it rarely finds a short route. Flood fill builds a distance map of the whole known maze, so it can reach an interior goal and improve toward the shortest path as it explores.
Further reading
References
Authoritative sources for going deeper than this simulator's bounded educational model.