ascend cost
This commit is contained in:
parent
2edc7327ab
commit
bda2ef8269
@ -39,8 +39,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
|
||||
}
|
||||
currentlyRunning = this;
|
||||
long startTime = System.currentTimeMillis();
|
||||
boolean slowPath=true;
|
||||
long timeoutTime = startTime + (slowPath ? 40000 :4000);
|
||||
boolean slowPath = true;
|
||||
long timeoutTime = startTime + (slowPath ? 40000 : 4000);
|
||||
long lastPrintout = 0;
|
||||
int numNodes = 0;
|
||||
ToolSet ts = new ToolSet();
|
||||
@ -77,7 +77,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
|
||||
}
|
||||
//long costStart = System.nanoTime();
|
||||
// TODO cache cost
|
||||
double actionCost = movementToGetToNeighbor.calculateCost(ts);
|
||||
double actionCost = movementToGetToNeighbor.getCost(ts);
|
||||
//long costEnd = System.nanoTime();
|
||||
//System.out.println(movementToGetToNeighbor.getClass() + "" + (costEnd - costStart));
|
||||
if (actionCost >= ActionCosts.COST_INF) {
|
||||
|
@ -29,6 +29,8 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
*/
|
||||
public final BlockPos[] positionsToPlace;
|
||||
|
||||
private Double cost;
|
||||
|
||||
protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace) {
|
||||
this.src = src;
|
||||
this.dest = dest;
|
||||
@ -43,7 +45,61 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
// .setStatus(MovementStatus.WAITING);
|
||||
}
|
||||
|
||||
public abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
|
||||
public double getCost(ToolSet ts) {
|
||||
if (cost == null) {
|
||||
if (ts == null) {
|
||||
ts = new ToolSet();
|
||||
}
|
||||
cost = calculateCost(ts);
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
public double getTotalHardnessOfBlocksToBreak(ToolSet ts) {
|
||||
/*
|
||||
double sum = 0;
|
||||
HashSet<BlockPos> toBreak = new HashSet();
|
||||
for (BlockPos positionsToBreak1 : positionsToBreak) {
|
||||
toBreak.add(positionsToBreak1);
|
||||
if (this instanceof ActionFall) {//if we are digging straight down, assume we have already broken the sand above us
|
||||
continue;
|
||||
}
|
||||
BlockPos tmp = positionsToBreak1.up();
|
||||
while (canFall(tmp)) {
|
||||
toBreak.add(tmp);
|
||||
tmp = tmp.up();
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : toBreak) {
|
||||
sum += getHardness(ts, Baritone.get(pos), pos);
|
||||
if (sum >= COST_INF) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
if (!Baritone.allowBreakOrPlace || !Baritone.hasThrowaway) {
|
||||
for (int i = 0; i < blocksToPlace.length; i++) {
|
||||
if (!canWalkOn(positionsToPlace[i])) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
//^ the above implementation properly deals with falling blocks, TODO integrate
|
||||
double sum = 0;
|
||||
for (BlockPos pos : positionsToBreak) {
|
||||
sum += MovementHelper.getMiningDurationTicks(ts, BlockStateInterface.get(pos), pos);
|
||||
if (sum >= COST_INF) {
|
||||
return COST_INF;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
protected abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks
|
||||
|
||||
public double recalculateCost() {
|
||||
cost = null;
|
||||
return getCost(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the execution of the latest Movement
|
||||
@ -59,7 +115,7 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
// .setGoal());
|
||||
// }
|
||||
// }
|
||||
if(isFinished()) {
|
||||
if (isFinished()) {
|
||||
|
||||
}
|
||||
MovementState latestState = updateState(currentState);
|
||||
@ -80,12 +136,12 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
}
|
||||
|
||||
private boolean prepare(MovementState state) {
|
||||
if(state.getStatus() == MovementStatus.WAITING) {
|
||||
if (state.getStatus() == MovementStatus.WAITING) {
|
||||
return true;
|
||||
}
|
||||
Optional<BlockPos> cruftPos;
|
||||
for(BlockPos blockPos : positionsToBreak) {
|
||||
if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
|
||||
for (BlockPos blockPos : positionsToBreak) {
|
||||
if (MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
|
||||
|
||||
}
|
||||
}
|
||||
@ -117,7 +173,7 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
* @return
|
||||
*/
|
||||
public MovementState updateState(MovementState state) {
|
||||
if(!prepare(state))
|
||||
if (!prepare(state))
|
||||
return state.setStatus(MovementStatus.PREPPING);
|
||||
return state;
|
||||
}
|
||||
|
@ -207,4 +207,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
Minecraft.getMinecraft().player.inventory.currentItem = ts.getBestSlot(b);
|
||||
}
|
||||
|
||||
static boolean isAir(BlockPos pos) {
|
||||
return BlockStateInterface.get(pos).getBlock().equals(Blocks.AIR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,20 +2,60 @@ package baritone.bot.pathing.movement.movements;
|
||||
|
||||
import baritone.bot.InputOverrideHandler;
|
||||
import baritone.bot.pathing.movement.Movement;
|
||||
import baritone.bot.pathing.movement.MovementHelper;
|
||||
import baritone.bot.pathing.movement.MovementState;
|
||||
import baritone.bot.pathing.movement.MovementState.MovementStatus;
|
||||
import baritone.bot.utils.BlockStateInterface;
|
||||
import baritone.bot.utils.ToolSet;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementAscend extends Movement {
|
||||
BlockPos[] against = new BlockPos[3];
|
||||
|
||||
public MovementAscend(BlockPos src, BlockPos dest) {
|
||||
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, new BlockPos[]{dest.down()});
|
||||
|
||||
BlockPos placementLocation = positionsToPlace[0];//end.down()
|
||||
int i = 0;
|
||||
if (!placementLocation.north().equals(src)) {
|
||||
against[i] = placementLocation.north();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.south().equals(src)) {
|
||||
against[i] = placementLocation.south();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.east().equals(src)) {
|
||||
against[i] = placementLocation.east();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.west().equals(src)) {
|
||||
against[i] = placementLocation.west();
|
||||
i++;
|
||||
}
|
||||
//TODO: add ability to place against .down() as well as the cardinal directions
|
||||
//useful for when you are starting a staircase without anything to place against
|
||||
// Counterpoint to the above TODO ^ you should move then pillar instead of ascend
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calculateCost(ToolSet ts) {
|
||||
return 1;
|
||||
protected double calculateCost(ToolSet ts) {
|
||||
if (!MovementHelper.canWalkOn(positionsToPlace[0])) {
|
||||
if (!MovementHelper.isAir(positionsToPlace[0]) && !MovementHelper.isWater(positionsToPlace[0])) {
|
||||
return COST_INF;
|
||||
}
|
||||
for (BlockPos against1 : against) {
|
||||
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
|
||||
return JUMP_ONE_BLOCK_COST + WALK_ONE_BLOCK_COST + PLACE_ONE_BLOCK_COST + getTotalHardnessOfBlocksToBreak(ts);
|
||||
}
|
||||
}
|
||||
return COST_INF;
|
||||
}
|
||||
if (BlockStateInterface.get(src.up(3)).getBlock() instanceof BlockFalling) {//it would fall on us and possibly suffocate us
|
||||
return COST_INF;
|
||||
}
|
||||
return WALK_ONE_BLOCK_COST / 2 + Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST / 2) + getTotalHardnessOfBlocksToBreak(ts);//we walk half the block to get to the edge, then we walk the other half while simultaneously jumping (math.max because of how it's in parallel)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,7 +6,6 @@ import baritone.bot.pathing.movement.ActionCosts;
|
||||
import baritone.bot.pathing.movement.Movement;
|
||||
import baritone.bot.pathing.movement.MovementState;
|
||||
import baritone.bot.utils.BlockStateInterface;
|
||||
import baritone.bot.utils.ToolSet;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.Tuple;
|
||||
@ -115,7 +114,7 @@ public class PathExecutor extends Behavior {
|
||||
}
|
||||
}*/
|
||||
Movement movement = path.movements().get(pathPosition);
|
||||
if (movement.calculateCost(new ToolSet()) >= ActionCosts.COST_INF) {
|
||||
if (movement.recalculateCost() >= ActionCosts.COST_INF) {
|
||||
System.out.println("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||
pathPosition = path.length() + 3;
|
||||
failed = true;
|
||||
@ -134,8 +133,8 @@ public class PathExecutor extends Behavior {
|
||||
ticksOnCurrent = 0;
|
||||
} else {
|
||||
ticksOnCurrent++;
|
||||
if (ticksOnCurrent > movement.calculateCost(new ToolSet()) + 100) {
|
||||
System.out.println("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + movement.calculateCost(new ToolSet()) + "). Cancelling.");
|
||||
if (ticksOnCurrent > movement.recalculateCost() + 100) {
|
||||
System.out.println("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + movement.getCost(null) + "). Cancelling.");
|
||||
pathPosition = path.length() + 3;
|
||||
failed = true;
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user