PathGen
This class is responsible for generating a path (or several paths) on a Grid using a pathfinding algorithm. It's primarily intended for internal use within the Pathfinder library. For most external use cases, it's recommended to use a localized path generator instead.
Key Concepts
- Grid: The 2D environment on which the path is generated.
- Start and End Nodes: The pathfinding algorithm finds a path between a specified
startnode and anendnode on the grid. - A Algorithm (Implicit)**: The
findPath()method implements a variation of the A search algorithm, usingcost,heuristic, andfunctionvalues to evaluate nodes.
Methods
PathGen(Grid grid, Node start, Node end)
Constructs a new PathGen instance.
grid: TheGridon which the path will be generated.start: The startingNodefor the path.end: The endingNodefor the path.
findCoordPath()
Finds a path between the start and end nodes and returns it as a List of Coord objects. This is a convenience method that converts the Node path to Coord objects.
findPath()
Finds a path between the start and end nodes on the grid. This method implements the core pathfinding logic. It initializes open and closed lists, iteratively explores nodes, and reconstructs the path once the end node is reached. Throws IllegalArgumentException if start or end nodes are null.
retracePath(Node current)
Private helper method. Retraces the path from the current node back to the start node by following the parent links, populating the path list.
getLowestF()
Private helper method. Finds and returns the Node with the lowest function value from the openList. This is a key step in the A* algorithm.
getGrid()
Returns the Grid associated with this path generator.
getPath()
Returns the generated path as a List of Node objects. The path is returned in the correct order (from start to end).
getStart()
Returns the starting Node of the path.
getEnd()
Returns the ending Node of the path.