astar 注释

This commit is contained in:
yhh
2020-07-09 16:36:42 +08:00
parent a80bb4b6f3
commit 877fc4c9bf
10 changed files with 153 additions and 3 deletions

View File

@@ -3,6 +3,12 @@
* 计算路径给定的IAstarGraph和开始/目标位置
*/
class AStarPathfinder {
/**
* 尽可能从开始到目标找到一条路径。如果没有找到路径则返回null。
* @param graph
* @param start
* @param goal
*/
public static search<T>(graph: IAstarGraph<T>, start: T, goal: T){
let foundPath = false;
let cameFrom = new Map<T, T>();
@@ -60,6 +66,12 @@ class AStarPathfinder {
return null;
}
/**
* 从cameFrom字典重新构造路径
* @param cameFrom
* @param start
* @param goal
*/
public static recontructPath<T>(cameFrom: Map<T, T>, start: T, goal: T): T[]{
let path = [];
let current = goal;