GoalBlock heuristic fix

This commit is contained in:
Leijurv 2018-08-19 14:08:16 -07:00
parent 8db6438d16
commit 1b957dc336
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -87,23 +87,12 @@ public class GoalBlock implements Goal {
} }
public static double calculate(double xDiff, int yDiff, double zDiff) { public static double calculate(double xDiff, int yDiff, double zDiff) {
double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
double heuristic = 0; double heuristic = 0;
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
double multiplier;
if (pythaDist < MIN) {
multiplier = 1;
} else {
multiplier = 1 - (pythaDist - MIN) / (MAX - MIN);
}
// if yDiff is 1 that means that pos.getY()-this.y==1 which means that we're 1 block below where we should be // if yDiff is 1 that means that pos.getY()-this.y==1 which means that we're 1 block below where we should be
// therefore going from 0,0,0 to a GoalYLevel of pos.getY()-this.y is accurate // therefore going from 0,0,0 to a GoalYLevel of pos.getY()-this.y is accurate
heuristic += new GoalYLevel(yDiff).heuristic(new BlockPos(0, 0, 0)); heuristic += new GoalYLevel(yDiff).heuristic(new BlockPos(0, 0, 0));
heuristic *= multiplier;
}
//use the pythagorean and manhattan mixture from GoalXZ //use the pythagorean and manhattan mixture from GoalXZ
heuristic += GoalXZ.calculate(xDiff, zDiff); heuristic += GoalXZ.calculate(xDiff, zDiff);
return heuristic; return heuristic;