Click & Whirr needs a wider screen
Open it on a laptop or desktop (1280px or wider recommended). The Learn · Code · Watch workspace needs the room to breathe.
Lesson 07
Plan the route
Checkpoints · 0 of 2 (waiting for Run)
- Find the goal (any heuristic gets there) (waiting for Run)
- Find it efficiently: explore under 110 cells (waiting for Run)
A map, a start, a goal
Point your robot at a goal behind walls. There is no line to ride and no rays to read this time, just a map, a start, and a goal with walls in between. Before it moves a single wheel, the robot has to plan the whole route.
The map on the right is a grid of cells. A* plans by exploring it one cell at a time, always expanding the most promising cell so far: the one with the smallest cost to reach it plus estimated cost still to go. That estimate is a heuristic, a hunch you write in code. A good hunch keeps the search pointed at the goal; a bad one, or none at all, sends it wandering.
The starter ships with no hunch. Read the skeleton in the editor: a plan_path that hands the engine your heuristic h(a, b), and an h that returns 0 for every cell. Press Run and watch what a search with no sense of direction does.
Run as-is: the search floods
Add the heuristic: beeline the goal
▸API reference
- plan_path()
- Runs ONCE when you press Run. Define your heuristic inside it and hand it to world.search.
- h(a, b)
- Your estimate of the cost from cell a to the goal cell b (each has .col and .row). If it throws or returns a non-number, that cell counts as 0: the search never crashes, it just floods.
- world.search(h)
- The engine's A* over this lesson's grid. Returns a summary: try print(plan_path().nodes_explored).
space pause · r reset · ctrl/cmd+enter run
Simulator
press Run to search