move in more helpers
This commit is contained in:
parent
b3410ab5d0
commit
9bd94fc8d2
@ -26,8 +26,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
* @see <a href="https://docs.google.com/document/d/1WVHHXKXFdCR1Oz__KtK8sFqyvSwJN_H4lftkHFgmzlc/edit"></a>
|
* @see <a href="https://docs.google.com/document/d/1WVHHXKXFdCR1Oz__KtK8sFqyvSwJN_H4lftkHFgmzlc/edit"></a>
|
||||||
*/
|
*/
|
||||||
protected static final double[] COEFFICIENTS = {1.5, 2, 2.5, 3, 4, 5, 10};
|
protected static final double[] COEFFICIENTS = {1.5, 2, 2.5, 3, 4, 5, 10};
|
||||||
|
/**
|
||||||
|
* If a path goes less than 5 blocks and doesn't make it to its goal, it's not worth considering.
|
||||||
|
*/
|
||||||
|
protected final static double MIN_DIST_PATH = 5;
|
||||||
|
|
||||||
public AbstractNodeCostSearch(BlockPos start, Goal goal) {
|
AbstractNodeCostSearch(BlockPos start, Goal goal) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
this.map = new HashMap<>();
|
this.map = new HashMap<>();
|
||||||
@ -44,22 +48,23 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
|
|
||||||
protected abstract IPath calculate();
|
protected abstract IPath calculate();
|
||||||
|
|
||||||
@Override
|
protected double distFromStart(PathNode n) {
|
||||||
public boolean isFinished() {
|
int xDiff = n.pos.getX() - start.getX();
|
||||||
return isFinished;
|
int yDiff = n.pos.getY() - start.getY();
|
||||||
|
int zDiff = n.pos.getZ() - start.getZ();
|
||||||
|
return Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected PathNode getNodeAtPosition(BlockPos pos) {
|
||||||
public Goal getGoal() {
|
PathNode alr = map.get(pos);
|
||||||
return goal;
|
if (alr == null) {
|
||||||
|
PathNode node = new PathNode(pos, goal);
|
||||||
|
map.put(pos, node);
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
return alr;
|
||||||
@Override
|
|
||||||
public BlockPos getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path bestPathSoFar() {
|
public Path bestPathSoFar() {
|
||||||
if (startNode == null || bestSoFar[0] == null) {
|
if (startNode == null || bestSoFar[0] == null) {
|
||||||
@ -72,4 +77,19 @@ public abstract class AbstractNodeCostSearch implements IPathFinder {
|
|||||||
public Path pathToMostRecentNodeConsidered() {
|
public Path pathToMostRecentNodeConsidered() {
|
||||||
return mostRecentConsidered == null ? null : new Path(startNode, mostRecentConsidered, goal);
|
return mostRecentConsidered == null ? null : new Path(startNode, mostRecentConsidered, goal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean isFinished() {
|
||||||
|
return isFinished;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Goal getGoal() {
|
||||||
|
return goal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final BlockPos getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user