File-By-File
PathGen

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 start node and an end node on the grid.
  • A Algorithm (Implicit)**: The findPath() method implements a variation of the A search algorithm, using cost, heuristic, and function values to evaluate nodes.

Methods

PathGen(Grid grid, Node start, Node end)

Constructs a new PathGen instance.

  • grid: The Grid on which the path will be generated.
  • start: The starting Node for the path.
  • end: The ending Node for 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.