All projects

Project — 05

Fastest route

A Python pathfinding playground: paint forests, water, fire and walls onto a grid, press Start, and watch Dijkstra's algorithm work out the cheapest way from A to B — terrain by terrain, cost by cost.

Python / Dijkstra's algorithm

View code

01 — The map

Paint the terrain

The app opens with an empty grid — A pinned in one corner, B in the other. Every cell starts free, and each terrain you can paint carries a price for stepping on it. Left click lays down the selected terrain, right click clears a cell back to open ground. Like the Angular project, the interface speaks Slovak.

0

Volne

Open

5

Les

Forest

10

Voda

Water

20

Ohen

Fire

Stena

Wall

Cost per cell — walls are effectively impassable

Empty map editor — a blank grid with start point A in the top-left corner, end point B in the bottom-right, and terrain options in the toolbar
The editor on launch: an empty grid with start A and goal B pinned to opposite corners, and the terrain palette down the side.

02 — The route

The cheapest way out

Hit Start and Dijkstra's algorithm explores outward from A, always expanding the cheapest reachable cell first, until it arrives at B. The winning route is then drawn back across the map with the running cost written into every cell. On this map it weaves around water, fire and walls, pays for a single stretch of forest, and reaches the goal at a total cost of 5 — announced at the top as “Hotovo. Najrychlejsia trasa ma cenu 5.”

Start A → Goal BPath cost 5
The frontier spreads from A in order of cost, cheapest cell first, until B is reached. Walls are impassable, so the only price paid is one forest crossing.
Solved map — the grid filled with forest, water, fire and wall cells, with the cheapest route from A to B highlighted in yellow and the running cost shown in each cell
The same solve, captured in the actual app: terrain painted in, the cheapest route picked out, and every cell on the path carrying its running cost.