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