Some formatting.
Whatever: this class needs a kick to the head. Maybe I should make a new one that isn't singleton and thread-unsafe like this one. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@914 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -122,8 +122,7 @@ public class AStarPathUtil
|
|||||||
public static final int ADJACENT_COST = 10;
|
public static final int ADJACENT_COST = 10;
|
||||||
|
|
||||||
/** The cost to move diagonally. */
|
/** The cost to move diagonally. */
|
||||||
public static final int DIAGONAL_COST = (int)Math.sqrt(
|
public static final int DIAGONAL_COST = (int)Math.sqrt((ADJACENT_COST * ADJACENT_COST) * 2);
|
||||||
(ADJACENT_COST * ADJACENT_COST) * 2);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of <code>Point</code> objects representing a path from coordinates
|
* Return a list of <code>Point</code> objects representing a path from coordinates
|
||||||
@@ -147,8 +146,8 @@ public class AStarPathUtil
|
|||||||
* @return the list of points in the path, or null if no path could be found.
|
* @return the list of points in the path, or null if no path could be found.
|
||||||
*/
|
*/
|
||||||
public static List<Point> getPath (
|
public static List<Point> getPath (
|
||||||
TraversalPred tpred, Stepper stepper, Object trav, int longest,
|
TraversalPred tpred, Stepper stepper, Object trav, int longest,
|
||||||
int ax, int ay, int bx, int by, boolean partial)
|
int ax, int ay, int bx, int by, boolean partial)
|
||||||
{
|
{
|
||||||
Info info = new Info(tpred, trav, longest, bx, by);
|
Info info = new Info(tpred, trav, longest, bx, by);
|
||||||
|
|
||||||
@@ -199,8 +198,8 @@ public class AStarPathUtil
|
|||||||
return getNodePath(bestpath);
|
return getNodePath(bestpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no path found
|
// no path found
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -208,11 +207,10 @@ public class AStarPathUtil
|
|||||||
* eight cardinal directions.
|
* eight cardinal directions.
|
||||||
*/
|
*/
|
||||||
public static List<Point> getPath (
|
public static List<Point> getPath (
|
||||||
TraversalPred tpred, Object trav, int longest,
|
TraversalPred tpred, Object trav, int longest,
|
||||||
int ax, int ay, int bx, int by, boolean partial)
|
int ax, int ay, int bx, int by, boolean partial)
|
||||||
{
|
{
|
||||||
return getPath(
|
return getPath(tpred, new Stepper(), trav, longest, ax, ay, bx, by, partial);
|
||||||
tpred, new Stepper(), trav, longest, ax, ay, bx, by, partial);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,19 +240,18 @@ public class AStarPathUtil
|
|||||||
// calculate the new cost for this node
|
// calculate the new cost for this node
|
||||||
int newg = n.g + cost;
|
int newg = n.g + cost;
|
||||||
|
|
||||||
// make sure the cost is reasonable
|
// make sure the cost is reasonable
|
||||||
if (newg > info.maxcost) {
|
if (newg > info.maxcost) {
|
||||||
// Log.info("Rejected costly step.");
|
// Log.info("Rejected costly step.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve the node corresponding to this location
|
// retrieve the node corresponding to this location
|
||||||
Node np = info.getNode(x, y);
|
Node np = info.getNode(x, y);
|
||||||
|
|
||||||
// skip if it's already in the open or closed list or if its
|
// skip if it's already in the open or closed list or if its
|
||||||
// actual cost is less than the just-calculated cost
|
// actual cost is less than the just-calculated cost
|
||||||
if ((info.open.contains(np) || info.closed.contains(np)) &&
|
if ((info.open.contains(np) || info.closed.contains(np)) && np.g <= newg) {
|
||||||
np.g <= newg) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,8 +337,7 @@ public class AStarPathUtil
|
|||||||
/** The maximum cost of any path that we'll consider. */
|
/** The maximum cost of any path that we'll consider. */
|
||||||
public int maxcost;
|
public int maxcost;
|
||||||
|
|
||||||
public Info (TraversalPred tpred, Object trav,
|
public Info (TraversalPred tpred, Object trav, int longest, int destx, int desty)
|
||||||
int longest, int destx, int desty)
|
|
||||||
{
|
{
|
||||||
// save off references
|
// save off references
|
||||||
this.tpred = tpred;
|
this.tpred = tpred;
|
||||||
@@ -365,14 +361,11 @@ public class AStarPathUtil
|
|||||||
{
|
{
|
||||||
// not traversable if the destination itself fails test
|
// not traversable if the destination itself fails test
|
||||||
if (tpred instanceof ExtendedTraversalPred) {
|
if (tpred instanceof ExtendedTraversalPred) {
|
||||||
if (!((ExtendedTraversalPred)tpred).canTraverse(
|
if (!((ExtendedTraversalPred)tpred).canTraverse(trav, sx, sy, dx, dy)) {
|
||||||
trav, sx, sy, dx, dy)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!isTraversable(dx, dy)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (!isTraversable(dx, dy)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the step is diagonal, make sure the corners don't impede our progress
|
// if the step is diagonal, make sure the corners don't impede our progress
|
||||||
|
|||||||
Reference in New Issue
Block a user