public class GridAStar extends AbstractPathfinder<GridNode,java.util.List<java.util.List<GridNode>>>
| Constructor and Description |
|---|
GridAStar()
Class constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
computeBestPath(GridNode node,
GridNode neighbor)
Determines whether to set a neighbor's parent to the node or to the node's parent.
|
protected int |
distanceBetweenNodes(GridNode a,
GridNode b)
Returns the approximate distance between two nodes in the search area.
|
java.util.List<GridNode> |
findPath(java.util.List<java.util.List<GridNode>> searchArea,
GridNode start,
GridNode dest)
Returns a List representing the path between two nodes in a two-dimensional search space.
|
protected int |
getManhattanDistance(GridNode a,
GridNode b)
Returns the distance between two nodes using the Manhattan method of adding up the
x distance and the y distance together.
|
void |
printPath(java.util.List<java.util.List<GridNode>> searchArea,
java.util.List<GridNode> path) |
void |
printSearchArea(java.util.List<java.util.List<GridNode>> searchArea) |
protected java.util.List<GridNode> |
reconstructPath(GridNode start,
GridNode dest)
Reconstructs the path by traversing from the destination node back through each parent
node until the start node is reached.
|
public java.util.List<GridNode> findPath(java.util.List<java.util.List<GridNode>> searchArea, GridNode start, GridNode dest)
findPath in interface Pathfinder<GridNode,java.util.List<java.util.List<GridNode>>>findPath in class AbstractPathfinder<GridNode,java.util.List<java.util.List<GridNode>>>start - the start node for the path search and must inherit from Nodedest - the destination node for the path search and must inherit from NodeList,
HashSet,
PriorityQueue,
reconstructPath(GridNode, GridNode),
computeBestPath(GridNode, GridNode)protected void computeBestPath(GridNode node, GridNode neighbor)
node - the current node being visited in the path searchneighbor - a neighbor of nodeList,
distanceBetweenNodes(GridNode, GridNode)protected int distanceBetweenNodes(GridNode a, GridNode b)
a - first nodeb - second nodeMathprotected int getManhattanDistance(GridNode a, GridNode b)
a - first nodeb - second nodeprotected java.util.List<GridNode> reconstructPath(GridNode start, GridNode dest)
start - the node used as the starting point for the path searchdest - the destination node that ends the path searchpublic void printSearchArea(java.util.List<java.util.List<GridNode>> searchArea)