Pathfinding Visualizer.

Watch search algorithms race across the grid, node by node.

Start Goal Wall Frontier (open set) Visited Shortest path
Algorithm
A*
Visited nodes
0
Path length
—
Frontier peak
0
Status
Ready

Drag on the grid to draw walls; drag again over a wall to erase. Drag the start or goal cell to move it. Heuristic only affects A* and Greedy.

How it works

每个算法都从起点向外扩散。BFS 用先进先出队列均匀展开,等权下保证最短;Dijkstra 按累计代价 g 排序的优先队列展开,对角线权重 √2;Greedy 只按到终点的启发式 h 排序,最快但不保证最优;A* 用 f = g + h 兼顾两者,可采纳启发式下既快又最优。 视觉上:浅到深的青色渐变表示访问先后,蓝色是当前 frontier(开放集),金色是回溯出的最短路径。

Why it matters

寻路是游戏 AI、地图导航、机器人运动规划与网络路由的基础。看清"访问节点数"如何随启发式与对角设置变化, 就能直观理解搜索的代价权衡:Dijkstra 探索面积大但稳妥,Greedy 探索面积小但可能绕远,A* 在两者间取得最佳平衡。 切换算法跑同一张地图,对比底部的访问数与路径长度,就是一堂活的算法效率课。

← Gallery