public class AStarPathFinder extends java.lang.Object implements PathFinder
Constructor and Description |
---|
AStarPathFinder(PathBasedMap<? extends AbstractPathTile> map,
int maxSearchDistance,
boolean allowDiagMovement)
Create a path finder with the default heuristic - closest to target.
|
AStarPathFinder(PathBasedMap<? extends AbstractPathTile> map,
int maxSearchDistance,
boolean allowDiagMovement,
AStarHeuristic heuristic)
Create a path finder.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addToClosed(Node node)
Add a node to the closed list.
|
protected void |
addToOpen(Node node)
Add a node to the open list.
|
Path |
findPath(PathMover mover,
int sx,
int sy,
int tx,
int ty)
Find a path from the starting location provided (sx,sy) to the target
location (tx,ty) avoiding blockages and attempting to honour costs
provided by the tile map.
|
protected Node |
getFirstInOpen()
Get the first element from the open list.
|
float |
getHeuristicCost(PathMover mover,
int x,
int y,
int tx,
int ty)
Get the heuristic cost for the given location.
|
float |
getMovementCost(PathMover mover,
int sx,
int sy,
int tx,
int ty)
Get the cost to move through a given location.
|
protected boolean |
inClosedList(Node node)
Check if the node supplied is in the closed list.
|
protected boolean |
inOpenList(Node node)
Check if a node is in the open list.
|
protected boolean |
isValidLocation(PathMover mover,
int sx,
int sy,
int x,
int y)
Check if a given location is valid for the supplied mover.
|
protected void |
removeFromClosed(Node node)
Remove a node from the closed list.
|
protected void |
removeFromOpen(Node node)
Remove a node from the open list.
|
public AStarPathFinder(PathBasedMap<? extends AbstractPathTile> map, int maxSearchDistance, boolean allowDiagMovement)
map
- The map to be searched.maxSearchDistance
- The maximum depth we'll search before giving up.allowDiagMovement
- True if the search should try diaganol movement.public AStarPathFinder(PathBasedMap<? extends AbstractPathTile> map, int maxSearchDistance, boolean allowDiagMovement, AStarHeuristic heuristic)
heuristic
- The heuristic used to determine the search order of the map.map
- The map to be searched.maxSearchDistance
- The maximum depth we'll search before giving up.allowDiagMovement
- True if the search should try diaganol movement.public Path findPath(PathMover mover, int sx, int sy, int tx, int ty)
PathFinder
findPath
in interface PathFinder
mover
- The entity that will be moving along the path. This provides
a place to pass context information about the game entity doing the moving, e.g.
can it fly? can it swim etc.sx
- The x coordinate of the start location.sy
- The y coordinate of the start location.tx
- The x coordinate of the target location.ty
- Teh y coordinate of the target location.protected Node getFirstInOpen()
protected void addToOpen(Node node)
node
- The node to be added to the open list.protected boolean inOpenList(Node node)
node
- The node to check for.protected void removeFromOpen(Node node)
node
- The node to remove from the open list.protected void addToClosed(Node node)
node
- The node to add to the closed list.protected boolean inClosedList(Node node)
node
- The node to search for.protected void removeFromClosed(Node node)
node
- The node to remove from the closed list.protected boolean isValidLocation(PathMover mover, int sx, int sy, int x, int y)
mover
- The mover that would hold a given location.sx
- The starting x coordinate.sy
- The starting y coordinate.x
- The x coordinate of the location to check.y
- The y coordinate of the location to check.public float getMovementCost(PathMover mover, int sx, int sy, int tx, int ty)
mover
- The entity that is being moved.sx
- The x coordinate of the tile whose cost is being determined.sy
- The y coordiante of the tile whose cost is being determined.tx
- The x coordinate of the target location.ty
- The y coordinate of the target location.public float getHeuristicCost(PathMover mover, int x, int y, int tx, int ty)
mover
- The entity that is being movedx
- The x coordinate of the tile whose cost is being determinedy
- The y coordiante of the tile whose cost is being determinedtx
- The x coordinate of the target locationty
- The y coordinate of the target location