-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAStar.js
More file actions
55 lines (40 loc) · 973 Bytes
/
AStar.js
File metadata and controls
55 lines (40 loc) · 973 Bytes
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
51
52
53
54
55
class AStar {
constructor(grid, start, end) {
this.grid = grid;
this.start = start;
this.end = end;
this.currentNode = start;
this.openSet = [start];
this.closedSet = [];
}
getNeighbors() {
let c = this.currentNode.c;
let r = this.currentNode.r;
let neighbors = [];
if (this.grid[r - 1]) {
neighbors.push()
}
if (this.grid[r][c - 1]) {
}
if (this.grid[r + 1]) {
}
if (this.grid[r][c + 1]) {
}
}
heuristic(a) {
return max(
abs(a.i - this.goal.i),
abs(a.j - this.goal.j)
);
}
removeFromArray(arr, elt) {
// Could use indexOf here instead to be more efficient
for (var i = arr.length - 1; i >= 0; i--) {
if (arr[i] == elt) {
arr.splice(i, 1);
}
}
}
step() {
}
}