From 9bd94fc8d2202d49bb085fba0eca77816fa6b001 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 3 Aug 2018 01:06:49 -0400 Subject: [PATCH] move in more helpers --- .../pathing/calc/AbstractNodeCostSearch.java | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java index 0d95f20e5..f356fafce 100644 --- a/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/bot/pathing/calc/AbstractNodeCostSearch.java @@ -26,8 +26,12 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { * @see */ 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.goal = goal; this.map = new HashMap<>(); @@ -44,22 +48,23 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { protected abstract IPath calculate(); - @Override - public boolean isFinished() { - return isFinished; + protected double distFromStart(PathNode n) { + int xDiff = n.pos.getX() - start.getX(); + int yDiff = n.pos.getY() - start.getY(); + int zDiff = n.pos.getZ() - start.getZ(); + return Math.sqrt(xDiff * xDiff + yDiff * yDiff + zDiff * zDiff); } - @Override - public Goal getGoal() { - return goal; + protected PathNode getNodeAtPosition(BlockPos pos) { + PathNode alr = map.get(pos); + if (alr == null) { + PathNode node = new PathNode(pos, goal); + map.put(pos, node); + return node; + } + return alr; } - @Override - public BlockPos getStart() { - return start; - } - - @Override public Path bestPathSoFar() { if (startNode == null || bestSoFar[0] == null) { @@ -72,4 +77,19 @@ public abstract class AbstractNodeCostSearch implements IPathFinder { public Path pathToMostRecentNodeConsidered() { 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; + } }