自动寻路算法。
原理和实现
Dijkstra's algorithm
推荐一个寻路算法的项目
各种寻路算法
可视化
A Star | A 星寻路算法
Introduction to A*
http://www.redblobgames.com/pathfinding/tower-defense/
系統地介紹了各種 尋路算法,還有可交互逐步動畫。
- One source, one destination:
Greedy Best First Search
A* - commonly used in games - One source, all destinations, or all sources, one destination:
Breadth First Search - unweighted edges
Dijkstra’s Algorithm - adds weights to edges
Bellman-Ford - supports negative weights - All sources, all destinations:
Floyd-Warshall
Johnson’s Algorithm
深度优先也可以的
http://jsfiddle.net/LXVMj/
以前搞出来的东西...
楼上给的amitp的文章非常不错,他还有一篇 Pathfinding for tower defence 介绍了不同情况下适用的寻路算法(如单起点/单终点,单起点/多终点,多起点/多终点)。