reformat code
This commit is contained in:
@@ -3,7 +3,7 @@ module es {
|
||||
* 计算路径给定的IUnweightedGraph和开始/目标位置
|
||||
*/
|
||||
export class BreadthFirstPathfinder {
|
||||
public static search<T>(graph: IUnweightedGraph<T>, start: T, goal: T): T[]{
|
||||
public static search<T>(graph: IUnweightedGraph<T>, start: T, goal: T): T[] {
|
||||
let foundPath = false;
|
||||
let frontier = [];
|
||||
frontier.unshift(start);
|
||||
@@ -11,15 +11,15 @@ module es {
|
||||
let cameFrom = new Map<T, T>();
|
||||
cameFrom.set(start, start);
|
||||
|
||||
while (frontier.length > 0){
|
||||
while (frontier.length > 0) {
|
||||
let current = frontier.shift();
|
||||
if (JSON.stringify(current) == JSON.stringify(goal)){
|
||||
if (JSON.stringify(current) == JSON.stringify(goal)) {
|
||||
foundPath = true;
|
||||
break;
|
||||
}
|
||||
|
||||
graph.getNeighbors(current).forEach(next => {
|
||||
if (!this.hasKey(cameFrom, next)){
|
||||
if (!this.hasKey(cameFrom, next)) {
|
||||
frontier.unshift(next);
|
||||
cameFrom.set(next, current);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ module es {
|
||||
return foundPath ? AStarPathfinder.recontructPath(cameFrom, start, goal) : null;
|
||||
}
|
||||
|
||||
private static hasKey<T>(map: Map<T, T>, compareKey: T){
|
||||
private static hasKey<T>(map: Map<T, T>, compareKey: T) {
|
||||
let iterator = map.keys();
|
||||
let r: IteratorResult<T>;
|
||||
while (r = iterator.next() , !r.done) {
|
||||
|
||||
Reference in New Issue
Block a user