From 40bea503c3f13029f11ce30af87d4a4b7b53a07f Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 24 Sep 2018 20:40:04 -0500 Subject: [PATCH] Merge ActionCosts with ActionCostsButOnlyTheOnesThatMakeMickeyDieInside --- .../api/pathing/goals/GoalYLevel.java | 8 +-- .../api/pathing/movement/ActionCosts.java | 55 +++++++++++++- ...ButOnlyTheOnesThatMakeMickeyDieInside.java | 71 ------------------- 3 files changed, 56 insertions(+), 78 deletions(-) delete mode 100644 src/api/java/baritone/api/pathing/movement/ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.java diff --git a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java index d9ae45974..ce54eebb7 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java +++ b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java @@ -17,14 +17,14 @@ package baritone.api.pathing.goals; -import baritone.api.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside; +import baritone.api.pathing.movement.ActionCosts; /** * Useful for mining (getting to diamond / iron level) * * @author leijurv */ -public class GoalYLevel implements Goal, ActionCostsButOnlyTheOnesThatMakeMickeyDieInside { +public class GoalYLevel implements Goal, ActionCosts { /** * The target Y level @@ -48,11 +48,11 @@ public class GoalYLevel implements Goal, ActionCostsButOnlyTheOnesThatMakeMickey public static double calculate(int goalY, int currentY) { if (currentY > goalY) { // need to descend - return ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.FALL_N_BLOCKS_COST[2] / 2 * (currentY - goalY); + return FALL_N_BLOCKS_COST[2] / 2 * (currentY - goalY); } if (currentY < goalY) { // need to ascend - return (goalY - currentY) * ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.JUMP_ONE_BLOCK_COST; + return (goalY - currentY) * JUMP_ONE_BLOCK_COST; } return 0; } diff --git a/src/api/java/baritone/api/pathing/movement/ActionCosts.java b/src/api/java/baritone/api/pathing/movement/ActionCosts.java index e31682aa5..e1f72dfab 100644 --- a/src/api/java/baritone/api/pathing/movement/ActionCosts.java +++ b/src/api/java/baritone/api/pathing/movement/ActionCosts.java @@ -17,9 +17,7 @@ package baritone.api.pathing.movement; -import baritone.api.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside; - -public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieInside { +public interface ActionCosts { /** * These costs are measured roughly in ticks btw @@ -46,4 +44,55 @@ public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieI * and that would make it overflow to negative */ double COST_INF = 1000000; + + double[] FALL_N_BLOCKS_COST = generateFallNBlocksCost(); + + double FALL_1_25_BLOCKS_COST = distanceToTicks(1.25); + double FALL_0_25_BLOCKS_COST = distanceToTicks(0.25); + /** + * When you hit space, you get enough upward velocity to go 1.25 blocks + * Then, you fall the remaining 0.25 to get on the surface, on block higher. + * Since parabolas are symmetric, the amount of time it takes to ascend up from 1 to 1.25 + * will be the same amount of time that it takes to fall back down from 1.25 to 1. + * And the same applies to the overall shape, if it takes X ticks to fall back down 1.25 blocks, + * it will take X ticks to reach the peak of your 1.25 block leap. + * Therefore, the part of your jump from y=0 to y=1.25 takes distanceToTicks(1.25) ticks, + * and the sub-part from y=1 to y=1.25 takes distanceToTicks(0.25) ticks. + * Therefore, the other sub-part, from y=0 to y-1, takes distanceToTicks(1.25)-distanceToTicks(0.25) ticks. + * That's why JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST + */ + double JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST; + + + static double[] generateFallNBlocksCost() { + double[] costs = new double[257]; + for (int i = 0; i < 257; i++) { + costs[i] = distanceToTicks(i); + } + return costs; + } + + static double velocity(int ticks) { + return (Math.pow(0.98, ticks) - 1) * -3.92; + } + + static double oldFormula(double ticks) { + return -3.92 * (99 - 49.5 * (Math.pow(0.98, ticks) + 1) - ticks); + } + + static double distanceToTicks(double distance) { + if (distance == 0) { + return 0; // Avoid 0/0 NaN + } + double tmpDistance = distance; + int tickCount = 0; + while (true) { + double fallDistance = velocity(tickCount); + if (tmpDistance <= fallDistance) { + return tickCount + tmpDistance / fallDistance; + } + tmpDistance -= fallDistance; + tickCount++; + } + } } diff --git a/src/api/java/baritone/api/pathing/movement/ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.java b/src/api/java/baritone/api/pathing/movement/ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.java deleted file mode 100644 index e492b21ca..000000000 --- a/src/api/java/baritone/api/pathing/movement/ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.api.pathing.movement; - -public interface ActionCostsButOnlyTheOnesThatMakeMickeyDieInside { - double[] FALL_N_BLOCKS_COST = generateFallNBlocksCost(); - - double FALL_1_25_BLOCKS_COST = distanceToTicks(1.25); - double FALL_0_25_BLOCKS_COST = distanceToTicks(0.25); - /** - * When you hit space, you get enough upward velocity to go 1.25 blocks - * Then, you fall the remaining 0.25 to get on the surface, on block higher. - * Since parabolas are symmetric, the amount of time it takes to ascend up from 1 to 1.25 - * will be the same amount of time that it takes to fall back down from 1.25 to 1. - * And the same applies to the overall shape, if it takes X ticks to fall back down 1.25 blocks, - * it will take X ticks to reach the peak of your 1.25 block leap. - * Therefore, the part of your jump from y=0 to y=1.25 takes distanceToTicks(1.25) ticks, - * and the sub-part from y=1 to y=1.25 takes distanceToTicks(0.25) ticks. - * Therefore, the other sub-part, from y=0 to y-1, takes distanceToTicks(1.25)-distanceToTicks(0.25) ticks. - * That's why JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST - */ - double JUMP_ONE_BLOCK_COST = FALL_1_25_BLOCKS_COST - FALL_0_25_BLOCKS_COST; - - - static double[] generateFallNBlocksCost() { - double[] costs = new double[257]; - for (int i = 0; i < 257; i++) { - costs[i] = distanceToTicks(i); - } - return costs; - } - - static double velocity(int ticks) { - return (Math.pow(0.98, ticks) - 1) * -3.92; - } - - static double oldFormula(double ticks) { - return -3.92 * (99 - 49.5 * (Math.pow(0.98, ticks) + 1) - ticks); - } - - static double distanceToTicks(double distance) { - if (distance == 0) { - return 0; // Avoid 0/0 NaN - } - double tmpDistance = distance; - int tickCount = 0; - while (true) { - double fallDistance = velocity(tickCount); - if (tmpDistance <= fallDistance) { - return tickCount + tmpDistance / fallDistance; - } - tmpDistance -= fallDistance; - tickCount++; - } - } -}