baritone/src/main/java/baritone/pathing/calc/PathNode.java

116 lines
3.3 KiB
Java
Raw Normal View History

2018-08-08 03:16:53 +00:00
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
2018-08-08 03:16:53 +00:00
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
2018-08-08 03:16:53 +00:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2018-08-08 03:16:53 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
2018-08-08 03:16:53 +00:00
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-22 20:15:56 +00:00
package baritone.pathing.calc;
2018-08-01 15:34:35 +00:00
2018-08-22 20:15:56 +00:00
import baritone.pathing.goals.Goal;
2018-09-10 16:22:32 +00:00
import baritone.pathing.movement.ActionCosts;
2018-08-22 20:15:56 +00:00
import baritone.pathing.movement.Movement;
import baritone.utils.pathing.BetterBlockPos;
2018-08-01 15:34:35 +00:00
/**
2018-08-02 15:07:10 +00:00
* A node in the path, containing the cost and steps to get to it.
2018-08-01 15:34:35 +00:00
*
* @author leijurv
*/
2018-09-08 15:15:10 +00:00
public final class PathNode {
2018-08-03 20:31:33 +00:00
2018-08-03 16:52:25 +00:00
/**
* The position of this node
*/
2018-08-14 17:47:31 +00:00
final BetterBlockPos pos;
2018-08-03 16:52:25 +00:00
/**
* The goal it's going towards
*/
2018-08-01 15:34:35 +00:00
final Goal goal;
2018-08-03 03:48:21 +00:00
2018-08-03 16:52:25 +00:00
/**
* Cached, should always be equal to goal.heuristic(pos)
*/
2018-08-01 15:34:35 +00:00
final double estimatedCostToGoal;
2018-08-02 15:07:10 +00:00
2018-08-03 16:52:25 +00:00
/**
* Total cost of getting from start to here
* Mutable and changed by PathFinder
*/
2018-08-02 15:07:10 +00:00
double cost;
2018-08-03 03:48:21 +00:00
2018-08-03 16:52:25 +00:00
/**
* Should always be equal to estimatedCosttoGoal + cost
* Mutable and changed by PathFinder
*/
public double combinedCost;
2018-08-03 16:52:25 +00:00
/**
* In the graph search, what previous node contributed to the cost
* Mutable and changed by PathFinder
*/
2018-08-02 15:07:10 +00:00
PathNode previous;
2018-08-03 03:48:21 +00:00
2018-08-03 16:52:25 +00:00
/**
* In the graph search, what previous movement (edge) was taken to get to here
* Mutable and changed by PathFinder
*/
2018-08-02 22:35:36 +00:00
Movement previousMovement;
2018-08-02 15:07:10 +00:00
/**
* Is this a member of the open set in A*? (only used during pathfinding)
* Instead of doing a costly member check in the open set, cache membership in each node individually too.
2018-08-02 15:07:10 +00:00
*/
2018-08-01 15:34:35 +00:00
boolean isOpen;
2018-08-03 03:48:21 +00:00
2018-08-13 23:59:59 +00:00
/**
* Where is this node in the array flattenization of the binary heap? Needed for decrease-key operations.
*/
public int heapPosition;
2018-08-14 17:47:31 +00:00
public PathNode(BetterBlockPos pos, Goal goal) {
2018-08-01 15:34:35 +00:00
this.pos = pos;
this.previous = null;
2018-09-10 16:22:32 +00:00
this.cost = ActionCosts.COST_INF;
2018-08-01 15:34:35 +00:00
this.goal = goal;
this.estimatedCostToGoal = goal.heuristic(pos);
2018-08-02 22:35:36 +00:00
this.previousMovement = null;
2018-08-01 15:34:35 +00:00
this.isOpen = false;
}
2018-08-02 15:07:10 +00:00
2018-08-03 03:48:21 +00:00
/**
* TODO: Possibly reimplement hashCode and equals. They are necessary for this class to function but they could be done better
*
* @return The hash code value for this {@link PathNode}
*/
2018-08-01 15:34:35 +00:00
@Override
2018-08-03 03:48:21 +00:00
public int hashCode() {
2018-08-19 16:37:35 +00:00
return pos.hashCode() * 7 + 3;
2018-08-14 15:28:35 +00:00
}
2018-08-01 15:34:35 +00:00
@Override
2018-08-03 03:48:21 +00:00
public boolean equals(Object obj) {
2018-08-14 00:03:48 +00:00
// GOTTA GO FAST
// ALL THESE CHECKS ARE FOR PEOPLE WHO WANT SLOW CODE
// SKRT SKRT
2018-09-08 04:32:25 +00:00
//if (obj == null || !(obj instanceof PathNode)) {
2018-08-14 00:03:48 +00:00
// return false;
2018-09-08 04:32:25 +00:00
//}
2018-08-14 00:03:48 +00:00
//final PathNode other = (PathNode) obj;
//return Objects.equals(this.pos, other.pos) && Objects.equals(this.goal, other.goal);
return this.pos.equals(((PathNode) obj).pos);
2018-08-01 15:34:35 +00:00
}
}