The course
Graphs and pathfinding is an advanced Coding course in seven lessons. Every lesson runs on the same circuit: a Raspberry Pi 4 with a traffic light module (red on GPIO17, amber on GPIO27, green on GPIO22), which is the rover's status lamp. Maps and routes print to the Serial Monitor, and each step is checked against what the Pi prints or which lamp it lights.
- Graphs as data: Base Jezero's stations and roads as a dict of lists, degrees and the busiest hub, a checker that finds a one-way road, the handshake lemma, and a terrain map turned into a graph of cells.
- BFS: a queue that explores in rings, distance in hops, parents that
rebuild the route, one
routefunction for stations and for the grid, the path drawn on the map, and a red lamp when a rockfall walls the goal in. - DFS: recursion and an explicit stack, the stations a dust storm cuts off, a first path that is 32 steps where BFS found 24, and the recursion limit a 30 by 30 field runs into.
- Dijkstra: drive times as edge weights,
heapqas a priority queue, the 30 minute route that takes one road more than the 40 minute one, and soft sand on the terrain map. - A: the f = g + h priority, Manhattan distance and admissible heuristics, the same route from 25 squares instead of 42, a 600 square plain where A expands 54 squares to Dijkstra's 570, and the worse route an overconfident guess picks.
- Mazes: a randomized DFS carves a perfect maze (39 passages for 40 cells), BFS solves it, the solution is drawn, dead ends are counted, and a new seed makes a new maze.
- Boss: a robot that solves a maze: the finale.
The catalog lists an ESP32-C3 and a two-wheel chassis too. This course is built on the Pi alone, with the rover's motion as printed drive commands, so every step can be checked in the browser.
The finale
Rover 7's console reads commands typed in the Serial Monitor. Its canyon is
the maze from lesson 6 with six extra walls knocked out, because a real
canyon has loops. solve plans with A*, amber lamp on while it searches,
then green, and prints the route as drive commands: R F L F F F F R F L F R F L F F R F for the 11 cell route, worked out from the change in compass
heading at each cell. rock 4 9 drops a boulder on the route and the next
solve finds a 13 cell way around. rock 8 15 blocks the goal's only
way in, and the red lamp says so. drive plans and plays the commands
out, one move at a time, until "arrived at the goal. Science time."
What the Pi's engine does differently
The Pi runs MicroPython 1.29, not CPython. For this course that shows in a few places:
heapqhasheappush,heappopandheapify, which is all Dijkstra and A* need;collections.dequeis there for BFS.- A dict does not keep the order keys went in, so tables loop over
sorted(...). Lists keep their order, so neighbor lists are safe. - Recursion stops near 800 frames with
RuntimeError: pystack exhausted. CPython's limit is 1,000 and its error isRecursionError. The DFS lesson hits the wall on purpose and then fixes it with a stack. random.seed(2026)gives the same maze every run on this engine. CPython draws its random numbers from a different generator, so the same seed there may carve a different, equally perfect maze.input()reads a line typed in the Serial Monitor.