From 88b276f7c9931a672706d6d2678c1db28f81bb92 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 17 Aug 2018 19:19:25 -0700 Subject: [PATCH] minimum improvement repropagation --- src/main/java/baritone/bot/Settings.java | 39 ++++++++++++------- .../bot/behavior/impl/PathingBehavior.java | 2 +- .../bot/pathing/calc/AStarPathFinder.java | 11 +++++- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/main/java/baritone/bot/Settings.java b/src/main/java/baritone/bot/Settings.java index d228300b..4289fa4c 100644 --- a/src/main/java/baritone/bot/Settings.java +++ b/src/main/java/baritone/bot/Settings.java @@ -36,30 +36,41 @@ public class Settings { * because we want to generally conserve blocks which might be limited */ public Setting blockPlacementPenalty = new Setting<>(20D); - public Setting allowSprint = new Setting<>(true); - public Setting costHeuristic = new Setting(4D); - public Setting chuckCaching = new Setting<>(false); public Setting allowWaterBucketFall = new Setting<>(true); - public Setting planningTickLookAhead = new Setting<>(150); - public Setting chatDebug = new Setting<>(true); - public Setting chatControl = new Setting<>(true); // probably false in impact - public Setting renderPath = new Setting<>(true); - public Setting fadePath = new Setting<>(false); // give this a better name in the UI, like "better path fps" idk - public Setting pathTimeoutMS = new Setting<>(4000L); - public Setting slowPath = new Setting<>(false); - public Setting slowPathTimeDelayMS = new Setting<>(100L); - public Setting slowPathTimeoutMS = new Setting<>(40000L); + public Setting allowSprint = new Setting<>(true); public Setting> acceptableThrowawayItems = new Setting<>(Arrays.asList( Item.getItemFromBlock(Blocks.DIRT), Item.getItemFromBlock(Blocks.COBBLESTONE), Item.getItemFromBlock(Blocks.NETHERRACK) )); - public Setting renderGoal = new Setting<>(true); + + public Setting costHeuristic = new Setting(4D); + + // obscure internal A* settings that you probably don't want to change public Setting pathingMaxChunkBorderFetch = new Setting<>(50); - public Setting backtrackCostFavor = new Setting<>(true); + public Setting backtrackCostFavor = new Setting<>(true); // see issue #18 public Setting backtrackCostFavoringCoefficient = new Setting<>(0.9); // see issue #18 + public Setting minimumImprovementRepropagation = new Setting<>(true); + + public Setting pathTimeoutMS = new Setting<>(4000L); + + public Setting slowPath = new Setting<>(false); + public Setting slowPathTimeDelayMS = new Setting<>(100L); + public Setting slowPathTimeoutMS = new Setting<>(40000L); + + public Setting chuckCaching = new Setting<>(false); + + public Setting planningTickLookAhead = new Setting<>(150); + + public Setting chatDebug = new Setting<>(true); + public Setting chatControl = new Setting<>(true); // probably false in impact + + public Setting renderPath = new Setting<>(true); + public Setting renderGoal = new Setting<>(true); public Setting pathRenderLineWidth = new Setting<>(5F); public Setting goalRenderLineWidth = new Setting<>(3F); + public Setting fadePath = new Setting<>(false); // give this a better name in the UI, like "better path fps" idk + public final Map> byName; public final List> allSettings; diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index 4598677a..4bf49d97 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -265,7 +265,7 @@ public class PathingBehavior extends Behavior { PathRenderer.drawPath(current.getPath(), renderBegin, player(), partialTicks, Color.RED, Baritone.settings().fadePath.get(), 10, 20); } if (next != null && next.getPath() != null) { - PathRenderer.drawPath(next.getPath(), 0, player(), partialTicks, Color.GREEN, Baritone.settings().fadePath.get(), 10, 20); + PathRenderer.drawPath(next.getPath(), 0, player(), partialTicks, Color.MAGENTA, Baritone.settings().fadePath.get(), 10, 20); } long split = System.nanoTime(); diff --git a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java index 186bd940..1d0e66d0 100644 --- a/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/bot/pathing/calc/AStarPathFinder.java @@ -97,6 +97,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { boolean cache = Baritone.settings().chuckCaching.get(); int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); + boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime) { if (slowPath) { try { @@ -160,6 +161,14 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { if (tentativeCost < 0) { throw new IllegalStateException(movementToGetToNeighbor.getClass() + " " + movementToGetToNeighbor + " overflowed into negative " + actionCost + " " + neighbor.cost + " " + tentativeCost); } + double improvementBy = neighbor.cost - tentativeCost; + // there are floating point errors caused by random combinations of traverse and diagonal over a flat area + // that means that sometimes there's a cost improvement of like 10 ^ -16 + // it's not worth the time to update the costs, decrease-key the heap, potentially repropagate, etc + if (improvementBy < 0.01 && minimumImprovementRepropagation) { + // who cares about a hundredth of a tick? that's half a millisecond for crying out loud! + continue; + } neighbor.previous = currentNode; neighbor.previousMovement = movementToGetToNeighbor; neighbor.cost = tentativeCost; @@ -190,7 +199,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared - displayChatMessageRaw("A* cost coefficient " + COEFFICIENTS[i]); + displayChatMessageRaw("Took " + (System.currentTimeMillis() - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i]); if (COEFFICIENTS[i] >= 3) { System.out.println("Warning: cost coefficient is greater than three! Probably means that"); System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)");