← All animations

🧭 A* Pathfinding

When a game character walks around a wall to reach you, something has to find that route. A* (pronounced "A-star") is the classic answer: it spreads outward from the start like a flood, but a heuristic — a cheap guess of how far the goal still is — pulls the search toward the target so it explores far fewer squares than a blind flood would. Draw some walls, drag the endpoints, and watch it think.

1. Watch A* search — draw walls, drag the endpoints, find the path

Click & drag on empty cells to paint walls (drag over a wall to erase). Drag the green start or gold goal to move them. Then press Find path and watch the frontier (cells queued to explore) and visited cells fill in, before the shortest route lights up. Use Step to advance one expansion at a time.

start goal wall frontier (open) visited (closed) path
Ready · 0 nodes expanded

2. Why the heuristic matters — A* vs Dijkstra vs Greedy

The same maze, three search strategies. Dijkstra ignores the goal and expands in every direction equally — guaranteed shortest, but it explores a huge blob. Greedy best-first charges straight at the goal using only the heuristic — fast, but it can be fooled into a longer route. A* combines both (f = g + h): it heads toward the goal and stays optimal. Watch how many cells each one touches.

A* · 0 expanded · path 0

3. The idea in one equation: f = g + h

A* keeps a priority queue of cells to explore and always expands the one with the smallest f-score. That score has two parts:

f(n) = g(n) + h(n)

Scene 2 is exactly this: the only thing that changes between the three runs is how f is computed from g and h.