新增breadthfirst与dijkstra寻路算法
This commit is contained in:
@@ -4,6 +4,34 @@ class MainScene extends Scene {
|
||||
|
||||
this.addEntityProcessor(new SpawnerSystem(new Matcher()));
|
||||
this.astarTest();
|
||||
this.dijkstraTest();
|
||||
this.breadthfirstTest();
|
||||
}
|
||||
|
||||
public breadthfirstTest(){
|
||||
let graph = new UnweightedGraph<string>();
|
||||
|
||||
graph.addEdgesForNode("a", ["b"]); // a->b
|
||||
graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
|
||||
graph.addEdgesForNode("c", ["a"]); // c->a
|
||||
graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
|
||||
graph.addEdgesForNode("e", ["b"]); // e->b
|
||||
|
||||
// 计算从c到e的路径
|
||||
let path = BreadthFirstPathfinder.search(graph, "c", "e");
|
||||
console.log(path);
|
||||
}
|
||||
|
||||
public dijkstraTest(){
|
||||
let graph = new WeightedGridGraph(20, 20);
|
||||
|
||||
graph.weightedNodes.push(new Point(3, 3));
|
||||
graph.weightedNodes.push(new Point(3, 4));
|
||||
graph.weightedNodes.push(new Point(4, 3));
|
||||
graph.weightedNodes.push(new Point(4, 4));
|
||||
|
||||
let path = graph.search(new Point(3, 4), new Point(15, 17));
|
||||
console.log(path);
|
||||
}
|
||||
|
||||
public astarTest(){
|
||||
|
||||
Reference in New Issue
Block a user