sanity checks in pathfinder

This commit is contained in:
Leijurv 2018-08-06 08:42:26 -07:00
parent d884c2dea8
commit dff3e1efe5
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -88,9 +88,15 @@ public class AStarPathFinder extends AbstractNodeCostSearch {
if (actionCost >= ActionCosts.COST_INF) { if (actionCost >= ActionCosts.COST_INF) {
continue; continue;
} }
if (actionCost <= 0) {
throw new IllegalStateException(movementToGetToNeighbor.getClass() + " " + movementToGetToNeighbor + " calculated implausible cost " + actionCost);
}
PathNode neighbor = getNodeAtPosition(movementToGetToNeighbor.getDest()); PathNode neighbor = getNodeAtPosition(movementToGetToNeighbor.getDest());
double tentativeCost = currentNode.cost + actionCost; double tentativeCost = currentNode.cost + actionCost;
if (tentativeCost < neighbor.cost) { if (tentativeCost < neighbor.cost) {
if (tentativeCost < 0) {
throw new IllegalStateException(movementToGetToNeighbor.getClass() + " " + movementToGetToNeighbor + " overflowed into negative " + actionCost + " " + neighbor.cost + " " + tentativeCost);
}
neighbor.previous = currentNode; neighbor.previous = currentNode;
neighbor.previousMovement = movementToGetToNeighbor; neighbor.previousMovement = movementToGetToNeighbor;
neighbor.cost = tentativeCost; neighbor.cost = tentativeCost;