public class GridAStar extends AbstractPathfinder<GridNode,java.util.List<java.util.List<GridNode>>>
| Constructor and Description |
|---|
GridAStar() |
| 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)
Prints the search area along with the given path in an easy-to-view format.
|
void |
printSearchArea(java.util.List<java.util.List<GridNode>> searchArea)
Prints the given search area in an easy-to-view format.
|
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>>>searchArea - a 2D list holding all of the GridNodes that describe the spacestart - the start node for the path search and must inherit from Nodedest - the destination node for the path search and must inherit from Nodeprotected void computeBestPath(GridNode node, GridNode neighbor)
node - the current node being visited in the path searchneighbor - a neighbor of nodeprotected int distanceBetweenNodes(GridNode a, GridNode b)
a - first nodeb - second nodeprotected 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)
searchArea - a 2D list holding all of the GridNodes that describe the spacepublic void printPath(java.util.List<java.util.List<GridNode>> searchArea, java.util.List<GridNode> path)
searchArea - a 2D list holding all of the GridNodes that describe the spacepath - the path that is printed over the search area