-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpathfinder.js
50 lines (40 loc) · 1.29 KB
/
pathfinder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Dijkstra's Algorithm
function getNodeWithLeastTraversalCost(arrayOfNodes){
// return node with least traversalCost
};
function findShortestPath(currentNode, goalNode){ // where nodes between start and end have tentative costs.
// return shortest path array based on graph of nodes with traversalCosts assigned
};
function dijkstra(startNode, endNode){
// return shortest path array of nodes
};
// Nodes for Graphs/Maps
function Node(name, cost){
this.name = name;
this.cost = cost;
this.traversalCost = Infinity;
this.neighbors = [];
};
Node.prototype.setTraversalCost = function(value) {
this.traversalCost = value;
};
Node.prototype.connectTo = function(node){
if(this.neighbors.indexOf(node) === -1){
this.neighbors.push(node);
node.connectTo(this);
}
};
// A*
function astar(startNode, endNode){
// return shortest path array of nodes
};
function createDistanceHeuristic(goalCoords){
return function distanceHeuristic(currentCoords){ // closure/function generator is useful to avoid repeating goalCoords
var deltaX = currentCoords.x - goalCoords.x;
var deltaY = currentCoords.y - goalCoords.y;
return Math.sqrt(deltaX*deltaX + deltaY*deltaY);
};
};
Node.prototype.setCoords = function(x, y){ // don't worry about coords till A*
this.coords = {x: x, y: y};
};