Fix namespacing

This commit is contained in:
Howard Stark 2018-08-01 23:32:03 -04:00
parent 8837810e63
commit 0ac5cd9b4e
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
8 changed files with 0 additions and 396 deletions

View File

@ -1,31 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public interface Goal {
/**
* Does this position satisfy the goal?
*
* @param pos
* @return
*/
public boolean isInGoal(BlockPos pos);
/**
* Estimate the number of ticks it will take to get to the goal
*
* @param pos
* @return
*/
public double heuristic(BlockPos pos);
@Override
public String toString();
}

View File

@ -1,77 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import baritone.Baritone;
import baritone.pathfinding.actions.Action;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
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());
}
public GoalBlock(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public BlockPos pos() {
return new BlockPos(x, y, z);
}
@Override
public boolean isInGoal(BlockPos pos) {
return pos.getX() == this.x && pos.getY() == this.y && pos.getZ() == this.z;
}
static final double MIN = 20;
static final double MAX = 150;
@Override
public double heuristic(BlockPos pos) {
double xDiff = pos.getX() - this.x;
double yDiff = pos.getY() - this.y;
double zDiff = pos.getZ() - this.z;
return calculate(xDiff, yDiff, zDiff);
}
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;
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.
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
} else {
heuristic += yDiff * (10 + Action.FALL_ONE_BLOCK_COST);//target below current
}
heuristic *= multiplier;
heuristic += (1 - multiplier) * baseline;
} else {
heuristic += baseline;
}
heuristic += GoalXZ.calculate(xDiff, zDiff, pythaDist);
return heuristic;
}
@Override
public String toString() {
return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}";
}
}

View File

@ -1,59 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import java.util.Arrays;
import java.util.Collection;
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;
for (BlockPos pos : blocks) {
goals[i] = new GoalBlock(pos);
i++;
}
}
public Goal[] goals() {
return goals;
}
@Override
public boolean isInGoal(BlockPos pos) {
for (Goal g : goals) {
if (g.isInGoal(pos)) {
return true;
}
}
return false;
}
@Override
public double heuristic(BlockPos pos) {
double min = Double.MAX_VALUE;
for (Goal g : goals) {
min = Math.min(min, g.heuristic(pos));
}
return min;
}
@Override
public String toString() {
return "GoalComposite" + Arrays.toString(goals);
}
}

View File

@ -1,35 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import baritone.Baritone;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
/**
*
* @author avecowa
*/
public class GoalGetToBlock extends GoalComposite {
public static BlockPos goalPos;
public GoalGetToBlock(BlockPos pos) {
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++) {
sides[i] = pos.offset(EnumFacing.values()[i]);
}
return sides;
}
}

View File

@ -1,52 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import java.util.Arrays;
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();
}
this.from = from;
this.distanceSq = distance * distance;
}
@Override
public boolean isInGoal(BlockPos pos) {
for (BlockPos p : from) {
int diffX = pos.getX() - p.getX();
int diffZ = pos.getZ() - p.getZ();
double distSq = diffX * diffX + diffZ * diffZ;
if (distSq < distanceSq) {
return false;
}
}
return true;
}
@Override
public double heuristic(BlockPos pos) {//mostly copied from GoalBlock
double min = Double.MAX_VALUE;
for (BlockPos p : from) {
double h = GoalXZ.calculate(p.getX() - pos.getX(), p.getZ() - pos.getZ());
if (h < min) {
min = h;
}
}
return -min;
}
@Override
public String toString() {
return "GoalRunAwayFrom[" + Arrays.asList(from) + "]";
}
}

View File

@ -1,42 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
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;
double yDiff = pos.getY() - this.y;
if (yDiff < 0) {
yDiff++;
}
double zDiff = pos.getZ() - this.z;
return GoalBlock.calculate(xDiff, yDiff, zDiff);
}
@Override
public String toString() {
return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}";
}
}

View File

@ -1,68 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import baritone.pathfinding.actions.Action;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class GoalXZ implements Goal {
final int x;
final int z;
public GoalXZ(int x, int z) {
this.x = x;
this.z = z;
}
@Override
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);
return calculate(xDiff, zDiff, pythaDist);
}
public static double calculateOld(double xDiff, double zDiff, double pythaDist) {
double heuristic = 0;
heuristic += Math.abs(xDiff) * Action.WALK_ONE_BLOCK_COST * 1.1;//overestimate
heuristic += Math.abs(zDiff) * Action.WALK_ONE_BLOCK_COST * 1.1;
heuristic += pythaDist / 10 * Action.WALK_ONE_BLOCK_COST;
return heuristic;
}
*/
static final double sq = Math.sqrt(2);
public static double calculate(double xDiff, double zDiff, double pythaDist) {
double x = Math.abs(xDiff);
double z = Math.abs(zDiff);
double straight;
double diagonal;
if (x < z) {
straight = z - x;
diagonal = x;
} else {
straight = x - z;
diagonal = z;
}
diagonal *= sq;
return (diagonal + straight) * Action.WALK_ONE_BLOCK_COST;
}
@Override
public String toString() {
return "Goal{x=" + x + ",z=" + z + "}";
}
}

View File

@ -1,32 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baritone.pathfinding.goals;
import net.minecraft.util.math.BlockPos;
/**
*
* @author leijurv
*/
public class GoalYLevel implements Goal {
final int level;
public GoalYLevel(int level) {
this.level = level;
}
@Override
public boolean isInGoal(BlockPos pos) {
return pos.getY() == level;
}
@Override
public double heuristic(BlockPos pos) {
return 20 * Math.abs(pos.getY() - level);//the number 20 was chosen somewhat randomly.
//TODO fix that
}
@Override
public String toString() {
return "Goal{y=" + level + "}";
}
}