-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
AStarNode.java
49 lines (38 loc) · 1.13 KB
/
AStarNode.java
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
package net.citizensnpcs.api.astar;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.Lists;
public abstract class AStarNode implements Comparable<AStarNode> {
float f, g, h;
AStarNode parent;
List<AStarNode> parents;
public abstract Plan buildPlan();
@Override
public int compareTo(AStarNode other) {
return Float.compare(f, other.f);
}
@Override
public abstract boolean equals(Object other);
public abstract Iterable<AStarNode> getNeighbours();
protected AStarNode getParent() {
return parent;
}
@SuppressWarnings("unchecked")
protected <T extends AStarNode> Iterable<T> getParents() {
if (parents != null)
return (Iterable<T>) parents;
parents = Lists.newArrayList();
AStarNode start = this;
while (start != null) {
parents.add(start);
start = start.parent;
}
Collections.reverse(parents);
return (Iterable<T>) parents;
}
protected float getPathCost() {
return f;
}
@Override
public abstract int hashCode();
}