Fix all old code refs in Goal classes
This commit is contained in:
parent
46f76df2af
commit
3ddc5ad115
@ -12,25 +12,28 @@ import net.minecraft.util.math.BlockPos;
|
||||
* @author leijurv
|
||||
*/
|
||||
public interface Goal {
|
||||
|
||||
/**
|
||||
* Does this position satisfy the goal?
|
||||
* Returns whether or not the specified position
|
||||
* meets the requirement for this goal based.
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
* @param pos The position
|
||||
* @return Whether or not it satisfies this goal
|
||||
*/
|
||||
public boolean isInGoal(BlockPos pos);
|
||||
boolean isInGoal(BlockPos pos);
|
||||
|
||||
/**
|
||||
* Estimate the number of ticks it will take to get to the goal
|
||||
*
|
||||
* @param pos
|
||||
* @return
|
||||
* @param pos The
|
||||
* @return The estimate number of ticks to satisfy the goal
|
||||
*/
|
||||
public double heuristic(BlockPos pos);
|
||||
double heuristic(BlockPos pos);
|
||||
|
||||
/**
|
||||
* Summarize the goal
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String toString();
|
||||
String toString();
|
||||
}
|
||||
|
@ -5,8 +5,7 @@
|
||||
*/
|
||||
package baritone.bot.pathing.goals;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.pathfinding.actions.Action;
|
||||
import baritone.bot.pathing.actions.ActionCosts;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
@ -17,10 +16,6 @@ public class GoalBlock implements Goal {
|
||||
|
||||
final int x, y, z;
|
||||
|
||||
public GoalBlock() {
|
||||
this(Baritone.playerFeet);
|
||||
}
|
||||
|
||||
public GoalBlock(BlockPos pos) {
|
||||
this(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
@ -57,14 +52,14 @@ public class GoalBlock implements Goal {
|
||||
public static double calculate(double xDiff, double yDiff, double zDiff) {
|
||||
double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
||||
double heuristic = 0;
|
||||
double baseline = (Action.PLACE_ONE_BLOCK_COST + Action.FALL_ONE_BLOCK_COST) * 32;
|
||||
double baseline = (ActionCosts.PLACE_ONE_BLOCK_COST + ActionCosts.FALL_ONE_BLOCK_COST) * 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.
|
||||
//as we get closer, slowly reintroduce the Y coordinate as a heuristic cost
|
||||
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
|
||||
heuristic -= yDiff * (Action.PLACE_ONE_BLOCK_COST * 0.7 + Action.JUMP_ONE_BLOCK_COST);//target above current
|
||||
heuristic -= yDiff * (ActionCosts.PLACE_ONE_BLOCK_COST * 0.7 + ActionCosts.JUMP_ONE_BLOCK_COST);//target above current
|
||||
} else {
|
||||
heuristic += yDiff * (10 + Action.FALL_ONE_BLOCK_COST);//target below current
|
||||
heuristic += yDiff * (10 + ActionCosts.FALL_ONE_BLOCK_COST);//target below current
|
||||
}
|
||||
heuristic *= multiplier;
|
||||
heuristic += (1 - multiplier) * baseline;
|
||||
@ -75,9 +70,4 @@ public class GoalBlock implements Goal {
|
||||
heuristic += GoalXZ.calculate(xDiff, zDiff, pythaDist);
|
||||
return heuristic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}";
|
||||
}
|
||||
}
|
||||
|
@ -16,16 +16,20 @@ import net.minecraft.util.math.BlockPos;
|
||||
* @author avecowa
|
||||
*/
|
||||
public class GoalComposite implements Goal {
|
||||
|
||||
public final Goal[] goals;
|
||||
|
||||
public GoalComposite(Goal... goals) {
|
||||
this.goals = goals;
|
||||
}
|
||||
|
||||
public GoalComposite(BlockPos... blocks) {
|
||||
goals = new Goal[blocks.length];
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
goals[i] = new GoalBlock(blocks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public GoalComposite(Collection<BlockPos> blocks) {
|
||||
goals = new Goal[blocks.size()];
|
||||
int i = 0;
|
||||
@ -34,9 +38,11 @@ public class GoalComposite implements Goal {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public Goal[] goals() {
|
||||
return goals;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGoal(BlockPos pos) {
|
||||
for (Goal g : goals) {
|
||||
@ -46,6 +52,7 @@ public class GoalComposite implements Goal {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(BlockPos pos) {
|
||||
double min = Double.MAX_VALUE;
|
||||
@ -54,6 +61,7 @@ public class GoalComposite implements Goal {
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalComposite" + Arrays.toString(goals);
|
||||
|
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package baritone.bot.pathing.goals;
|
||||
|
||||
import baritone.Baritone;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
@ -22,10 +21,6 @@ public class GoalGetToBlock extends GoalComposite {
|
||||
super(ajacentBlocks(goalPos = pos));
|
||||
}
|
||||
|
||||
public GoalGetToBlock() {
|
||||
this(Baritone.playerFeet);
|
||||
}
|
||||
|
||||
public static BlockPos[] ajacentBlocks(BlockPos pos) {
|
||||
BlockPos[] sides = new BlockPos[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
|
@ -13,8 +13,11 @@ import net.minecraft.util.math.BlockPos;
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalRunAway implements Goal {
|
||||
|
||||
public final BlockPos[] from;
|
||||
|
||||
final double distanceSq;
|
||||
|
||||
public GoalRunAway(double distance, BlockPos... from) {
|
||||
if (from.length == 0) {
|
||||
throw new IllegalArgumentException();
|
||||
@ -22,6 +25,7 @@ public class GoalRunAway implements Goal {
|
||||
this.from = from;
|
||||
this.distanceSq = distance * distance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGoal(BlockPos pos) {
|
||||
for (BlockPos p : from) {
|
||||
@ -34,6 +38,7 @@ public class GoalRunAway implements Goal {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(BlockPos pos) {//mostly copied from GoalBlock
|
||||
double min = Double.MAX_VALUE;
|
||||
@ -45,6 +50,7 @@ public class GoalRunAway implements Goal {
|
||||
}
|
||||
return -min;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalRunAwayFrom[" + Arrays.asList(from) + "]";
|
||||
|
@ -13,19 +13,24 @@ import net.minecraft.util.math.BlockPos;
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalTwoBlocks implements Goal {
|
||||
|
||||
final int x, y, z;
|
||||
|
||||
public GoalTwoBlocks(BlockPos pos) {
|
||||
this(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
public GoalTwoBlocks(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGoal(BlockPos pos) {
|
||||
return pos.getX() == this.x && (pos.getY() == this.y || pos.getY() == this.y - 1) && pos.getZ() == this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(BlockPos pos) {
|
||||
double xDiff = pos.getX() - this.x;
|
||||
@ -36,6 +41,7 @@ public class GoalTwoBlocks implements Goal {
|
||||
double zDiff = pos.getZ() - this.z;
|
||||
return GoalBlock.calculate(xDiff, yDiff, zDiff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}";
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
package baritone.bot.pathing.goals;
|
||||
|
||||
import baritone.pathfinding.actions.Action;
|
||||
import baritone.bot.pathing.actions.ActionCosts;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
@ -13,8 +13,9 @@ import net.minecraft.util.math.BlockPos;
|
||||
* @author leijurv
|
||||
*/
|
||||
public class GoalXZ implements Goal {
|
||||
final int x;
|
||||
final int z;
|
||||
|
||||
final int x, z;
|
||||
|
||||
public GoalXZ(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
@ -23,15 +24,18 @@ public class GoalXZ implements Goal {
|
||||
public boolean isInGoal(BlockPos pos) {
|
||||
return pos.getX() == x && pos.getZ() == z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(BlockPos pos) {//mostly copied from GoalBlock
|
||||
double xDiff = pos.getX() - this.x;
|
||||
double zDiff = pos.getZ() - this.z;
|
||||
return calculate(xDiff, zDiff);
|
||||
}
|
||||
|
||||
public static double calculate(double xDiff, double zDiff) {
|
||||
return calculate(xDiff, zDiff, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
public static double calculate(double xDiff, double zDiff) {
|
||||
double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
||||
@ -45,7 +49,9 @@ public class GoalXZ implements Goal {
|
||||
return heuristic;
|
||||
}
|
||||
*/
|
||||
|
||||
static final double sq = Math.sqrt(2);
|
||||
|
||||
public static double calculate(double xDiff, double zDiff, double pythaDist) {
|
||||
//This is a combination of pythagorean and manhattan distance
|
||||
//It takes into account the fact that pathing can either walk diagonally or forwards
|
||||
@ -64,8 +70,9 @@ public class GoalXZ implements Goal {
|
||||
diagonal = z;
|
||||
}
|
||||
diagonal *= sq;
|
||||
return (diagonal + straight) * Action.WALK_ONE_BLOCK_COST;
|
||||
return (diagonal + straight) * ActionCosts.WALK_ONE_BLOCK_COST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goal{x=" + x + ",z=" + z + "}";
|
||||
|
Loading…
Reference in New Issue
Block a user