openset refactor
This commit is contained in:
		
							
								
								
									
										4
									
								
								src/main/java/baritone/bot/behavior/PathingBehavior.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/main/java/baritone/bot/behavior/PathingBehavior.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
package baritone.bot.behavior;
 | 
			
		||||
 | 
			
		||||
public class PathingBehavior {
 | 
			
		||||
}
 | 
			
		||||
@@ -6,8 +6,8 @@ package baritone.bot.pathing.calc;
 | 
			
		||||
import baritone.bot.pathing.goals.Goal;
 | 
			
		||||
import baritone.bot.pathing.movement.ActionCosts;
 | 
			
		||||
import baritone.bot.pathing.movement.Movement;
 | 
			
		||||
import baritone.bot.pathing.openset.BinaryHeapOpenSet;
 | 
			
		||||
import baritone.bot.pathing.openset.IOpenSet;
 | 
			
		||||
import baritone.bot.pathing.calc.openset.BinaryHeapOpenSet;
 | 
			
		||||
import baritone.bot.pathing.calc.openset.IOpenSet;
 | 
			
		||||
import baritone.bot.utils.ToolSet;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.util.math.BlockPos;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package baritone.bot.pathing.openset;
 | 
			
		||||
package baritone.bot.pathing.calc.openset;
 | 
			
		||||
 | 
			
		||||
import baritone.bot.pathing.calc.PathNode;
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package baritone.bot.pathing.openset;
 | 
			
		||||
package baritone.bot.pathing.calc.openset;
 | 
			
		||||
 | 
			
		||||
import baritone.bot.pathing.util.FibonacciHeap;
 | 
			
		||||
import baritone.bot.pathing.calc.PathNode;
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package baritone.bot.pathing.openset;
 | 
			
		||||
package baritone.bot.pathing.calc.openset;
 | 
			
		||||
 | 
			
		||||
import baritone.bot.pathing.calc.PathNode;
 | 
			
		||||
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package baritone.bot.pathing.openset;
 | 
			
		||||
package baritone.bot.pathing.calc.openset;
 | 
			
		||||
 | 
			
		||||
import baritone.bot.pathing.calc.PathNode;
 | 
			
		||||
 | 
			
		||||
@@ -1,272 +1,38 @@
 | 
			
		||||
package baritone.bot.pathing.movement;
 | 
			
		||||
 | 
			
		||||
public interface ActionCostsButOnlyTheOnesThatMakeMickeyDieInside {
 | 
			
		||||
    /**
 | 
			
		||||
     * Doesn't include walking forwards, just the falling
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Based on a sketchy formula from minecraftwiki
 | 
			
		||||
     * <p>
 | 
			
		||||
     * d(t) = 3.92 × (99 - 49.50×(0.98^t+1) - t)
 | 
			
		||||
     * <p>
 | 
			
		||||
     * Solved in mathematica
 | 
			
		||||
     */
 | 
			
		||||
    double[] FALL_N_BLOCKS_COST = {
 | 
			
		||||
            0,
 | 
			
		||||
            5.113536276700843,
 | 
			
		||||
            7.2828323066872045,
 | 
			
		||||
            8.968618232732705,
 | 
			
		||||
            10.404365959100446,
 | 
			
		||||
            11.680480623396742,
 | 
			
		||||
            12.843313631721617,
 | 
			
		||||
            13.920391760441351,
 | 
			
		||||
            14.929645007107348,
 | 
			
		||||
            15.883523984254479,
 | 
			
		||||
            16.79109129057836,
 | 
			
		||||
            17.65918648560504,
 | 
			
		||||
            18.49312169856919,
 | 
			
		||||
            19.297120173295674,
 | 
			
		||||
            20.07460511655106,
 | 
			
		||||
            20.8283969319279,
 | 
			
		||||
            21.560852030800998,
 | 
			
		||||
            22.273963072907762,
 | 
			
		||||
            22.969432977622052,
 | 
			
		||||
            23.648730635504094,
 | 
			
		||||
            24.313133563454144,
 | 
			
		||||
            24.96376105880576,
 | 
			
		||||
            25.601600317276624,
 | 
			
		||||
            26.22752725784882,
 | 
			
		||||
            26.84232330924579,
 | 
			
		||||
            27.446689075671973,
 | 
			
		||||
            28.04125556279362,
 | 
			
		||||
            28.62659347601145,
 | 
			
		||||
            29.203220980727895,
 | 
			
		||||
            29.771610224502076,
 | 
			
		||||
            30.332192854241576,
 | 
			
		||||
            30.885364711409714,
 | 
			
		||||
            31.431489850114986,
 | 
			
		||||
            31.970903993712962,
 | 
			
		||||
            32.50391752291778,
 | 
			
		||||
            33.03081807074975,
 | 
			
		||||
            33.551872785739214,
 | 
			
		||||
            34.067330313780815,
 | 
			
		||||
            34.57742254022905,
 | 
			
		||||
            35.082366126750486,
 | 
			
		||||
            35.58236387172606,
 | 
			
		||||
            36.077605918342215,
 | 
			
		||||
            36.56827083070201,
 | 
			
		||||
            37.05452655515648,
 | 
			
		||||
            37.536531281468676,
 | 
			
		||||
            38.01443421627468,
 | 
			
		||||
            38.488376279513304,
 | 
			
		||||
            38.95849073299524,
 | 
			
		||||
            39.424903749019556,
 | 
			
		||||
            39.88773492587905,
 | 
			
		||||
            40.347097756192305,
 | 
			
		||||
            40.80310005323151,
 | 
			
		||||
            41.25584433975873,
 | 
			
		||||
            41.70542820332173,
 | 
			
		||||
            42.15194462147737,
 | 
			
		||||
            42.59548225999495,
 | 
			
		||||
            43.03612574673234,
 | 
			
		||||
            43.473955923566265,
 | 
			
		||||
            43.90905007848757,
 | 
			
		||||
            44.34148215973641,
 | 
			
		||||
            44.771322973646555,
 | 
			
		||||
            45.19864036768775,
 | 
			
		||||
            45.6234994000367,
 | 
			
		||||
            46.045962496868576,
 | 
			
		||||
            46.46608959843794,
 | 
			
		||||
            46.88393829491001,
 | 
			
		||||
            47.299563952807276,
 | 
			
		||||
            47.71301983285154,
 | 
			
		||||
            48.12435719990593,
 | 
			
		||||
            48.53362542565443,
 | 
			
		||||
            48.94087208459637,
 | 
			
		||||
            49.34614304388003,
 | 
			
		||||
            49.74948254745144,
 | 
			
		||||
            50.15093329495179,
 | 
			
		||||
            50.55053651575828,
 | 
			
		||||
            50.94833203852857,
 | 
			
		||||
            51.344358356577956,
 | 
			
		||||
            51.7386526893903,
 | 
			
		||||
            52.131251040538295,
 | 
			
		||||
            52.5221882522659,
 | 
			
		||||
            52.911498056964746,
 | 
			
		||||
            53.29921312575791,
 | 
			
		||||
            53.68536511438698,
 | 
			
		||||
            54.06998470658305,
 | 
			
		||||
            54.45310165508815,
 | 
			
		||||
            54.83474482048066,
 | 
			
		||||
            55.214942207946656,
 | 
			
		||||
            55.59372100212837,
 | 
			
		||||
            55.97110760017104,
 | 
			
		||||
            56.34712764308082,
 | 
			
		||||
            56.7218060454978,
 | 
			
		||||
            57.09516702398098,
 | 
			
		||||
            57.467234123894954,
 | 
			
		||||
            57.83803024498192,
 | 
			
		||||
            58.20757766569654,
 | 
			
		||||
            58.57589806637605,
 | 
			
		||||
            58.943012551313004,
 | 
			
		||||
            59.30894166979339,
 | 
			
		||||
            59.67370543615876,
 | 
			
		||||
            60.03732334894715,
 | 
			
		||||
            60.39981440916383,
 | 
			
		||||
            60.76119713772981,
 | 
			
		||||
            61.12148959215276,
 | 
			
		||||
            61.480709382462294,
 | 
			
		||||
            61.83887368644886,
 | 
			
		||||
            62.19599926424302,
 | 
			
		||||
            62.5521024722697,
 | 
			
		||||
            62.90719927660977,
 | 
			
		||||
            63.26130526579944,
 | 
			
		||||
            63.61443566309607,
 | 
			
		||||
            63.96660533823729,
 | 
			
		||||
            64.31782881871884,
 | 
			
		||||
            64.6681203006148,
 | 
			
		||||
            65.01749365896293,
 | 
			
		||||
            65.36596245773595,
 | 
			
		||||
            65.71353995941902,
 | 
			
		||||
            66.0602391342122,
 | 
			
		||||
            66.40607266887541,
 | 
			
		||||
            66.75105297523314,
 | 
			
		||||
            67.09519219835428,
 | 
			
		||||
            67.43850222442256,
 | 
			
		||||
            67.78099468831131,
 | 
			
		||||
            68.1226809808764,
 | 
			
		||||
            68.46357225597976,
 | 
			
		||||
            68.80367943725574,
 | 
			
		||||
            69.14301322463155,
 | 
			
		||||
            69.4815841006127,
 | 
			
		||||
            69.81940233634366,
 | 
			
		||||
            70.15647799745355,
 | 
			
		||||
            70.49282094969598,
 | 
			
		||||
            70.82844086439191,
 | 
			
		||||
            71.16334722368377,
 | 
			
		||||
            71.49754932560899,
 | 
			
		||||
            71.83105628900007,
 | 
			
		||||
            72.16387705821887,
 | 
			
		||||
            72.49602040773145,
 | 
			
		||||
            72.82749494653027,
 | 
			
		||||
            73.15830912240982,
 | 
			
		||||
            73.48847122610157,
 | 
			
		||||
            73.81798939527378,
 | 
			
		||||
            74.14687161840179,
 | 
			
		||||
            74.47512573851341,
 | 
			
		||||
            74.80275945681478,
 | 
			
		||||
            75.12978033620105,
 | 
			
		||||
            75.45619580465629,
 | 
			
		||||
            75.78201315854709,
 | 
			
		||||
            76.10723956581364,
 | 
			
		||||
            76.43188206906233,
 | 
			
		||||
            76.75594758856334,
 | 
			
		||||
            77.07944292515718,
 | 
			
		||||
            77.40237476307294,
 | 
			
		||||
            77.72474967266207,
 | 
			
		||||
            78.04657411305035,
 | 
			
		||||
            78.36785443471128,
 | 
			
		||||
            78.68859688196352,
 | 
			
		||||
            79.00880759539531,
 | 
			
		||||
            79.3284926142182,
 | 
			
		||||
            79.64765787855289,
 | 
			
		||||
            79.9663092316492,
 | 
			
		||||
            80.28445242204289,
 | 
			
		||||
            80.60209310565104,
 | 
			
		||||
            80.91923684780862,
 | 
			
		||||
            81.23588912524778,
 | 
			
		||||
            81.55205532802215,
 | 
			
		||||
            81.86774076137777,
 | 
			
		||||
            82.18295064757277,
 | 
			
		||||
            82.49769012764693,
 | 
			
		||||
            82.81196426314357,
 | 
			
		||||
            83.12577803778456,
 | 
			
		||||
            83.43913635910059,
 | 
			
		||||
            83.75204406001774,
 | 
			
		||||
            84.0645059004021,
 | 
			
		||||
            84.37652656856343,
 | 
			
		||||
            84.68811068271964,
 | 
			
		||||
            84.99926279242277,
 | 
			
		||||
            85.30998737994823,
 | 
			
		||||
            85.62028886164805,
 | 
			
		||||
            85.93017158926958,
 | 
			
		||||
            86.23963985124041,
 | 
			
		||||
            86.54869787392082,
 | 
			
		||||
            86.85734982282462,
 | 
			
		||||
            87.16559980380936,
 | 
			
		||||
            87.47345186423686,
 | 
			
		||||
            87.78090999410504,
 | 
			
		||||
            88.08797812715169,
 | 
			
		||||
            88.39466014193125,
 | 
			
		||||
            88.70095986286539,
 | 
			
		||||
            89.00688106126789,
 | 
			
		||||
            89.31242745634496,
 | 
			
		||||
            89.61760271617149,
 | 
			
		||||
            89.92241045864394,
 | 
			
		||||
            90.22685425241062,
 | 
			
		||||
            90.53093761778003,
 | 
			
		||||
            90.83466402760772,
 | 
			
		||||
            91.1380369081625,
 | 
			
		||||
            91.44105963997252,
 | 
			
		||||
            91.74373555865165,
 | 
			
		||||
            92.04606795570685,
 | 
			
		||||
            92.34806007932717,
 | 
			
		||||
            92.64971513515455,
 | 
			
		||||
            92.95103628703731,
 | 
			
		||||
            93.2520266577665,
 | 
			
		||||
            93.55268932979581,
 | 
			
		||||
            93.85302734594525,
 | 
			
		||||
            94.15304371008936,
 | 
			
		||||
            94.45274138783006,
 | 
			
		||||
            94.75212330715466,
 | 
			
		||||
            95.05119235907955,
 | 
			
		||||
            95.34995139827977,
 | 
			
		||||
            95.6484032437049,
 | 
			
		||||
            95.94655067918174,
 | 
			
		||||
            96.24439645400388,
 | 
			
		||||
            96.54194328350879,
 | 
			
		||||
            96.83919384964254,
 | 
			
		||||
            97.13615080151253,
 | 
			
		||||
            97.43281675592864,
 | 
			
		||||
            97.7291942979329,
 | 
			
		||||
            98.02528598131825,
 | 
			
		||||
            98.32109432913622,
 | 
			
		||||
            98.6166218341944,
 | 
			
		||||
            98.9118709595435,
 | 
			
		||||
            99.20684413895441,
 | 
			
		||||
            99.50154377738548,
 | 
			
		||||
            99.79597225144039,
 | 
			
		||||
            100.09013190981668,
 | 
			
		||||
            100.38402507374525,
 | 
			
		||||
            100.67765403742101,
 | 
			
		||||
            100.97102106842496,
 | 
			
		||||
            101.26412840813789,
 | 
			
		||||
            101.55697827214576,
 | 
			
		||||
            101.84957285063727,
 | 
			
		||||
            102.14191430879345,
 | 
			
		||||
            102.43400478716974,
 | 
			
		||||
            102.72584640207059,
 | 
			
		||||
            103.01744124591679,
 | 
			
		||||
            103.30879138760572,
 | 
			
		||||
            103.59989887286467,
 | 
			
		||||
            103.89076572459741,
 | 
			
		||||
            104.18139394322415,
 | 
			
		||||
            104.471785507015,
 | 
			
		||||
            104.7619423724172,
 | 
			
		||||
            105.05186647437611,
 | 
			
		||||
            105.34155972665033,
 | 
			
		||||
            105.6310240221207,
 | 
			
		||||
            105.92026123309378,
 | 
			
		||||
            106.2092732115996,
 | 
			
		||||
            106.49806178968389,
 | 
			
		||||
            106.78662877969508,
 | 
			
		||||
            107.07497597456587,
 | 
			
		||||
            107.36310514808983,
 | 
			
		||||
            107.65101805519288,
 | 
			
		||||
            107.93871643219987,
 | 
			
		||||
            108.22620199709642,
 | 
			
		||||
            108.51347644978608,
 | 
			
		||||
            108.80054147234273,
 | 
			
		||||
            109.08739872925868,
 | 
			
		||||
            109.37404986768833
 | 
			
		||||
    };
 | 
			
		||||
    double[] FALL_N_BLOCKS_COST = generateFallNBlocksCost();
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
        }
 | 
			
		||||
        int tickCount = 0;
 | 
			
		||||
        while (true) {
 | 
			
		||||
            double fallDistance = velocity(tickCount);
 | 
			
		||||
            if (distance <= fallDistance) {
 | 
			
		||||
                return tickCount + distance / fallDistance;
 | 
			
		||||
            }
 | 
			
		||||
            distance -= fallDistance;
 | 
			
		||||
            tickCount++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
package baritone.bot.pathing.openset;
 | 
			
		||||
package baritone.bot.pathing.calc.openset;
 | 
			
		||||
 | 
			
		||||
import baritone.bot.pathing.calc.PathNode;
 | 
			
		||||
import baritone.bot.pathing.goals.GoalBlock;
 | 
			
		||||
@@ -3,17 +3,30 @@ package baritone.bot.pathing.movement;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
import static baritone.bot.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.FALL_N_BLOCKS_COST;
 | 
			
		||||
import static baritone.bot.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.velocity;
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
 | 
			
		||||
public class ActionCostsButOnlyTheOnesThatMakeMickeyDieInsideTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testFallNBlocksCost() {
 | 
			
		||||
        assertEquals(FALL_N_BLOCKS_COST.length, 257); // Fall 0 blocks through fall 256 blocks
 | 
			
		||||
        for (int i = 0; i < 256; i++) {
 | 
			
		||||
            double t = FALL_N_BLOCKS_COST[i];
 | 
			
		||||
            double fallDistance = 3.92 * (99 - 49.50 * (Math.pow(0.98, t) + 1) - t);
 | 
			
		||||
            assertEquals(fallDistance, -i, 0.000000000001); // If you add another 0 the test fails at i=43 LOL
 | 
			
		||||
        for (int i = 0; i < 257; i++) {
 | 
			
		||||
            double blocks = ticksToBlocks(FALL_N_BLOCKS_COST[i]);
 | 
			
		||||
            assertEquals(blocks, i, 0.01);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double ticksToBlocks(double ticks) {
 | 
			
		||||
        double fallDistance = 0;
 | 
			
		||||
        int integralComponent = (int) Math.floor(ticks);
 | 
			
		||||
        for (int tick = 0; tick < integralComponent; tick++) {
 | 
			
		||||
            fallDistance += velocity(tick);
 | 
			
		||||
        }
 | 
			
		||||
        double partialTickComponent = ticks - Math.floor(ticks);
 | 
			
		||||
        double finalPartialTickVelocity = velocity(integralComponent);
 | 
			
		||||
        double finalPartialTickDistance = finalPartialTickVelocity * partialTickComponent;
 | 
			
		||||
        fallDistance += finalPartialTickDistance;
 | 
			
		||||
        return fallDistance;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user