better falling costs

This commit is contained in:
Leijurv 2018-08-04 18:28:36 -04:00
parent 84d9a9bf35
commit d3a2238493
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
5 changed files with 309 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package baritone.bot.behavior;
import baritone.bot.pathing.calc.IPath; import baritone.bot.pathing.calc.IPath;
import baritone.bot.pathing.movement.ActionCosts; import baritone.bot.pathing.movement.ActionCosts;
import baritone.bot.pathing.movement.Movement; import baritone.bot.pathing.movement.Movement;
import baritone.bot.pathing.movement.MovementState;
import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.BlockStateInterface;
import baritone.bot.utils.ToolSet; import baritone.bot.utils.ToolSet;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
@ -10,6 +11,8 @@ import net.minecraft.init.Blocks;
import net.minecraft.util.Tuple; import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import static baritone.bot.pathing.movement.MovementState.MovementStatus.*;
/** /**
* Behavior to execute a precomputed path. Does not (yet) deal with path segmentation or stitching * Behavior to execute a precomputed path. Does not (yet) deal with path segmentation or stitching
* or cutting (jumping onto the next path if it starts with a backtrack of this path's ending) * or cutting (jumping onto the next path if it starts with a backtrack of this path's ending)
@ -116,8 +119,14 @@ public class PathExecution extends Behavior {
failed = true; failed = true;
return; return;
} }
movement.onTick(); MovementState.MovementStatus movementStatus = movement.update();
if (movement.isFinished()) { if (movementStatus == UNREACHABLE || movementStatus == FAILED) {
System.out.println("Movement returns status " + movementStatus);
pathPosition = path.length() + 3;
failed = true;
return;
}
if (movementStatus == SUCCESS) {
System.out.println("Movement done, next path"); System.out.println("Movement done, next path");
pathPosition++; pathPosition++;
ticksOnCurrent = 0; ticksOnCurrent = 0;

View File

@ -4,6 +4,7 @@ import net.minecraft.util.math.BlockPos;
/** /**
* A specific BlockPos goal * A specific BlockPos goal
*
* @author leijurv * @author leijurv
*/ */
public class GoalBlock implements Goal { public class GoalBlock implements Goal {
@ -47,14 +48,14 @@ public class GoalBlock implements Goal {
public static double calculate(double xDiff, double yDiff, double zDiff) { public static double calculate(double xDiff, double yDiff, double zDiff) {
double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double heuristic = 0; double heuristic = 0;
double baseline = (PLACE_ONE_BLOCK_COST + FALL_ONE_BLOCK_COST) * 32; double baseline = (PLACE_ONE_BLOCK_COST + FALL_N_BLOCKS_COST[1]) * 32;
if (pythaDist < MAX) {//if we are more than MAX away, ignore the Y coordinate. It really doesn't matter how far away your Y coordinate is if you X coordinate is 1000 blocks away. if (pythaDist < MAX) {//if we are more than MAX away, ignore the Y coordinate. It really doesn't matter how far away your Y coordinate is if you X coordinate is 1000 blocks away.
//as we get closer, slowly reintroduce the Y coordinate as a heuristic cost //as we get closer, slowly reintroduce the Y coordinate as a heuristic cost
double multiplier = pythaDist < MIN ? 1 : 1 - (pythaDist - MIN) / (MAX - MIN); double multiplier = pythaDist < MIN ? 1 : 1 - (pythaDist - MIN) / (MAX - MIN);
if (yDiff < 0) {//pos.getY()-this.y<0 therefore pos.getY()<this.y, so target is above current if (yDiff < 0) {//pos.getY()-this.y<0 therefore pos.getY()<this.y, so target is above current
heuristic -= yDiff * (PLACE_ONE_BLOCK_COST * 0.7 + JUMP_ONE_BLOCK_COST);//target above current heuristic -= yDiff * (PLACE_ONE_BLOCK_COST * 0.7 + JUMP_ONE_BLOCK_COST);//target above current
} else { } else {
heuristic += yDiff * (10 + FALL_ONE_BLOCK_COST);//target below current heuristic += yDiff * (10 + FALL_N_BLOCKS_COST[1]);//target below current
} }
heuristic *= multiplier; heuristic *= multiplier;
heuristic += (1 - multiplier) * baseline; heuristic += (1 - multiplier) * baseline;

View File

@ -1,11 +1,9 @@
package baritone.bot.pathing.movement; package baritone.bot.pathing.movement;
public interface ActionCosts { public interface ActionCosts extends ActionCostsButOnlyTheOnesThatMakeMickeyDieInside {
/** /**
* These costs are measured roughly in ticks btw * These costs are measured roughly in ticks btw
* Blocks/Tick: 0.2806167m / tick
* Tick/Block: 3.563579787t
*/ */
double WALK_ONE_BLOCK_COST = 20 / 4.317; double WALK_ONE_BLOCK_COST = 20 / 4.317;
double WALK_ONE_IN_WATER_COST = 20 / 2.2; double WALK_ONE_IN_WATER_COST = 20 / 2.2;
@ -18,19 +16,10 @@ public interface ActionCosts {
* To walk off an edge you need to walk 0.5 to the edge then 0.3 to start falling off * To walk off an edge you need to walk 0.5 to the edge then 0.3 to start falling off
*/ */
double WALK_OFF_BLOCK_COST = WALK_ONE_BLOCK_COST * 0.8; double WALK_OFF_BLOCK_COST = WALK_ONE_BLOCK_COST * 0.8;
/** /**
* Doesn't include walking forwards, just the falling * To walk the rest of the way to be centered on the new block
* <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_ONE_BLOCK_COST = 5.11354; double CENTER_AFTER_FALL_COST = WALK_ONE_BLOCK_COST - WALK_OFF_BLOCK_COST;
double FALL_TWO_BLOCK_COST = 7.28283;
double FALL_THREE_BLOCK_COST = 8.96862;
/** /**
* It doesn't actually take ten ticks to place a block, this cost is so high * It doesn't actually take ten ticks to place a block, this cost is so high

View File

@ -0,0 +1,272 @@
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
};
}

View File

@ -0,0 +1,19 @@
package baritone.bot.pathing.movement;
import org.junit.Test;
import static baritone.bot.pathing.movement.ActionCostsButOnlyTheOnesThatMakeMickeyDieInside.FALL_N_BLOCKS_COST;
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
}
}
}