A* Pathfinding

Click: place walls | Shift+click: set start | Ctrl+click: set end
Start End Wall Open Closed Path

About this simulation

A* (pronounced "A-star") is a graph search algorithm that finds the shortest path between two points while exploring far fewer nodes than a naive breadth-first search. It works by scoring every candidate cell with f = g + h: g is the actual cost from the start, and h is a heuristic estimate of the remaining distance to the goal. By always expanding the cell with the lowest combined score, the search stays biased toward the goal instead of fanning out in every direction.

It's the algorithm behind most real-time pathfinding — game NPCs navigating a level, robotics motion planning, and routing engines all lean on the same idea. The trade-off is the heuristic: a good one (like the Chebyshev distance used here, since diagonal movement is allowed) keeps the search fast and still guarantees the shortest path; a bad one can make it slower than brute force or wrong altogether.

This implementation visualizes the search live: cells in the open set (still being considered) and the closed set (already evaluated) are colored separately, so you can watch the frontier expand toward the goal step by step, or run it to completion and see the final path highlighted.

← Back to Simulations