Find a shortest route through free cells
The planner searches free cells for a route with the fewest moves. Blocking a doorway changes which routes exist and how far the robot must travel.
Try the room planner
Choose a goal in the room, then run the robot.
Robot navigation room
The 3D workspace loads when it comes into view.
6 moves remaining
More controls
Robot (2, 4), goal (8, 4). 6 moves remaining. Click a cell to set the goal. The green square is the modeled robot footprint.
2D reference and fallback
Inspect route and obstacle coordinates
Route in travel order: (2, 4) → (3, 4) → (4, 4) → (5, 4) → (6, 4) → (7, 4) → (8, 4)
Occupied cells: (5,3), (5,5), (5,6), (5,7).
Excluded robot-center cells: (5,3), (5,5), (5,6), (5,7).
Planner assumptions
Every cardinal move costs one. Breadth-first search finds a shortest route on this fixed grid. The robot is a square aligned with the grid. For footprint width 2r + 1 cells, centers within r cells horizontally and vertically of an occupied cell are excluded. Centers whose footprint crosses a room edge are also excluded. Routes move only the center. There is no turning radius, acceleration, uncertain localization, or moving obstacle prediction. The movement button advances a discrete simulation state, not a physical robot.
Optional reasoning check
Opening the Python editor…
Requirements and learning goals
Before you start
- The robot-footprint lesson
- A browser with JavaScript enabled
You will be able to
- Count route length as moves between cell centers
- Explain why breadth-first search gives a shortest route for equal-cost moves
- Identify assumptions that make a grid route incomplete for hardware
After accounting for the robot's body, we need to connect its starting cell to a goal through legal center positions. Our planner can move up, down, left, or right. Each move costs one. It cannot move diagonally, jump over a wall, or rotate a non-square body.
The algorithm is breadth-first search, often shortened to BFS. It first considers positions one move from the start, then two moves away, then three. When it reaches the goal, it has found a route with the fewest moves under these rules. If several routes are equally short, the neighbor exploration order decides which one is displayed.
This is a real search over the current grid, not a prerecorded route. Changing the , goal, or obstacle cells changes the graph the algorithm searches. Allow about 10 minutes.
Try it
Click a clear cell in the room to choose a goal, or use the Goal selector. Run robot executes the route. Open More controls for robot size and obstacle switches.
- Reset the map. With a one-cell footprint, predict the number of moves from (2,4) to (8,4).
- Inspect the white route and the text list of route coordinates. Count transitions between adjacent cells rather than counting the start as a move.
- Change the goal to (8,2). Predict the shortest possible distance if obstacles allow it, then compare the planner's result.
- Restore goal (8,4). Select Block doorway. Follow the route around the upper end of the wall.
- Select Close all crossings. Explain why there is no route regardless of how long the search runs.
Work through the lower bound
Without obstacles, the shortest cardinal route needs the horizontal difference plus the vertical difference. From (2,4) to (8,4), that is |8 − 2| + |4 − 4| = 6 moves. The open doorway allows the planner to achieve this bound.
For goal (8,2), the bound is 6 + 2 = 8 moves. A valid 8-move route exists in the reset room. Blocking the doorway to goal (8,4) forces the route to leave row 4 and return. The nearest open crossing is row 2, adding two upward and two downward moves. The shortest route therefore needs 10 moves.
BFS can guarantee the fewest moves here because all legal moves have equal cost. If you assign different costs to terrain, turning, or proximity to obstacles, you need a planner that accounts for those costs rather than treating every move as identical.
Check the expected results
With the one-cell footprint and open doorway, expect 6 moves to (8,4) and 8 moves to (8,2). With the doorway blocked and goal restored to (8,4), expect 10 moves. Closing every cell in column 5 produces no route because it separates the start from the goal.
The route may run next to an obstacle. Fewest grid moves does not mean best clearance, smoothest steering, or shortest travel time. The previous lesson's footprint rule prevents overlap under the square model, but adds no extra uncertainty margin.
Check a route yourself
Open the route coordinates. For every consecutive pair, exactly one coordinate should change by one. No route cell should be occupied or excluded. The first cell should equal the current robot position and the last should equal the goal. These checks help distinguish a valid route from a line that only looks plausible.
You are done when you can justify the 6-, 8-, and 10-move results and explain why a fully sealed dividing wall cannot be solved by a different search order.
Troubleshooting
Check footprint and goal before comparing counts. A larger footprint changes the free-center map, so it is a different planning problem. The route count excludes the starting cell. A no-route result is meaningful; changing colors or waiting longer will not connect two disconnected regions.
The localization lesson asks how a robot knows which starting cell is actually its own.
Before you move on
Can you do each of these?
- Count route length as moves between cell centers
- Explain why breadth-first search gives a shortest route for equal-cost moves
- Identify assumptions that make a grid route incomplete for hardware
0 of 2 checkpoints solved. Try checkpoint 1