Class AbstractPathfinder

java.lang.Object
de.bsommerfeld.pathetic.engine.pathfinder.AbstractPathfinder
All Implemented Interfaces:
de.bsommerfeld.pathetic.api.pathing.Pathfinder
Direct Known Subclasses:
AStarPathfinder

public abstract class AbstractPathfinder extends Object implements de.bsommerfeld.pathetic.api.pathing.Pathfinder
Provides a skeletal implementation of the Pathfinder interface, defining common behavior for pathfinding algorithms.

This pathfinder operates by iteratively processing nodes from an open set (priority queue) until the target is reached or other termination conditions are met. It supports asynchronous execution and customizable hooks for observing the pathfinding steps. The "tick-wise" nature mentioned previously refers to each main loop iteration processing one node.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final List<de.bsommerfeld.pathetic.api.pathing.processing.CostProcessor>
     
    protected static final Set<de.bsommerfeld.pathetic.api.wrapper.PathPosition>
     
    protected final de.bsommerfeld.pathetic.api.provider.NavigationPointProvider
     
    protected final de.bsommerfeld.pathetic.api.pathing.INeighborStrategy
     
    protected final de.bsommerfeld.pathetic.api.pathing.configuration.PathfinderConfiguration
     
    protected final List<de.bsommerfeld.pathetic.api.pathing.processing.ValidationProcessor>
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractPathfinder(de.bsommerfeld.pathetic.api.pathing.configuration.PathfinderConfiguration pathfinderConfiguration)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Node
    createStartNode(de.bsommerfeld.pathetic.api.wrapper.PathPosition startPos, de.bsommerfeld.pathetic.api.wrapper.PathPosition targetPos)
    Creates the initial Node for the start position.
    protected abstract Node
    Extracts the node with the lowest cost from the open set and retrieves the corresponding Node object.
    de.bsommerfeld.pathetic.api.pathing.PathfindingSearch
    findPath(de.bsommerfeld.pathetic.api.wrapper.PathPosition start, de.bsommerfeld.pathetic.api.wrapper.PathPosition target, de.bsommerfeld.pathetic.api.pathing.context.EnvironmentContext environmentContext)
     
    protected abstract void
    Prepares the algorithm-specific initial setup required before executing the pathfinding logic.
    protected abstract void
    insertStartNode(Node node, double fCost, MinHeap openSet)
    Inserts the start node into the open set and updates any internal mapping.
    protected abstract void
    Marks the given node as expanded (i.e., added to the "closed set").
    protected abstract void
    Abstract method for algorithm-specific cleanup, called after pathfinding execution.
    protected abstract void
    processSuccessors(de.bsommerfeld.pathetic.api.wrapper.PathPosition requestStart, de.bsommerfeld.pathetic.api.wrapper.PathPosition requestTarget, Node currentNode, MinHeap openSet, de.bsommerfeld.pathetic.api.pathing.processing.context.SearchContext searchContext)
    Abstract method representing the core logic of processing successor nodes for a given currentNode.
    protected de.bsommerfeld.pathetic.api.pathing.result.Path
    reconstructPath(de.bsommerfeld.pathetic.api.wrapper.PathPosition start, de.bsommerfeld.pathetic.api.wrapper.PathPosition target, Node endNode)
    Reconstructs the path by tracing back from the given end node to the start node.
    void
    registerPathfindingHook(de.bsommerfeld.pathetic.api.pathing.hook.PathfinderHook hook)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface de.bsommerfeld.pathetic.api.pathing.Pathfinder

    findPath
  • Field Details

    • EMPTY_PATH_POSITIONS

      protected static final Set<de.bsommerfeld.pathetic.api.wrapper.PathPosition> EMPTY_PATH_POSITIONS
    • pathfinderConfiguration

      protected final de.bsommerfeld.pathetic.api.pathing.configuration.PathfinderConfiguration pathfinderConfiguration
    • validationProcessors

      protected final List<de.bsommerfeld.pathetic.api.pathing.processing.ValidationProcessor> validationProcessors
    • costProcessors

      protected final List<de.bsommerfeld.pathetic.api.pathing.processing.CostProcessor> costProcessors
    • neighborStrategy

      protected final de.bsommerfeld.pathetic.api.pathing.INeighborStrategy neighborStrategy
  • Constructor Details

    • AbstractPathfinder

      protected AbstractPathfinder(de.bsommerfeld.pathetic.api.pathing.configuration.PathfinderConfiguration pathfinderConfiguration)
  • Method Details

    • findPath

      public de.bsommerfeld.pathetic.api.pathing.PathfindingSearch findPath(de.bsommerfeld.pathetic.api.wrapper.PathPosition start, de.bsommerfeld.pathetic.api.wrapper.PathPosition target, de.bsommerfeld.pathetic.api.pathing.context.EnvironmentContext environmentContext)
      Specified by:
      findPath in interface de.bsommerfeld.pathetic.api.pathing.Pathfinder
    • registerPathfindingHook

      public void registerPathfindingHook(de.bsommerfeld.pathetic.api.pathing.hook.PathfinderHook hook)
      Specified by:
      registerPathfindingHook in interface de.bsommerfeld.pathetic.api.pathing.Pathfinder
    • createStartNode

      protected Node createStartNode(de.bsommerfeld.pathetic.api.wrapper.PathPosition startPos, de.bsommerfeld.pathetic.api.wrapper.PathPosition targetPos)
      Creates the initial Node for the start position.
      Parameters:
      startPos - The effective start position.
      targetPos - The effective target position.
      Returns:
      The created start node.
    • reconstructPath

      protected de.bsommerfeld.pathetic.api.pathing.result.Path reconstructPath(de.bsommerfeld.pathetic.api.wrapper.PathPosition start, de.bsommerfeld.pathetic.api.wrapper.PathPosition target, Node endNode)
      Reconstructs the path by tracing back from the given end node to the start node.
      Parameters:
      endNode - The node from which to trace back.
      Returns:
      The reconstructed Path.
    • insertStartNode

      protected abstract void insertStartNode(Node node, double fCost, MinHeap openSet)
      Inserts the start node into the open set and updates any internal mapping.
    • extractBestNode

      protected abstract Node extractBestNode(MinHeap openSet)
      Extracts the node with the lowest cost from the open set and retrieves the corresponding Node object.
    • initializeSearch

      protected abstract void initializeSearch()
      Prepares the algorithm-specific initial setup required before executing the pathfinding logic. This method is designed to be overridden by subclasses to implement their respective initialization logic, such as setting up data structures, precomputing values, or resetting internal state. It is called at the beginning of a pathfinding request.
    • markNodeAsExpanded

      protected abstract void markNodeAsExpanded(Node node)
      Marks the given node as expanded (i.e., added to the "closed set"). Subclasses should implement this to update their specific closed set mechanism.
      Parameters:
      node - The node that has been taken from the open set and is being expanded.
    • performAlgorithmCleanup

      protected abstract void performAlgorithmCleanup()
      Abstract method for algorithm-specific cleanup, called after pathfinding execution. To be implemented by subclasses like AStarPathfinder.
    • processSuccessors

      protected abstract void processSuccessors(de.bsommerfeld.pathetic.api.wrapper.PathPosition requestStart, de.bsommerfeld.pathetic.api.wrapper.PathPosition requestTarget, Node currentNode, MinHeap openSet, de.bsommerfeld.pathetic.api.pathing.processing.context.SearchContext searchContext)
      Abstract method representing the core logic of processing successor nodes for a given currentNode. Implementations (like A*) should:
      1. Generate potential successor positions.
      2. Create Node objects for these successors.
      3. Validate these nodes (e.g., traversability, bounds, visited status). This is where processors will hook in.
      4. Calculate their G and H costs. G-costs will be influenced by cost processors.
      5. Add valid successor nodes with their F-costs to the openSet.
      Parameters:
      requestStart - The original start PathPosition of the pathfinding request.
      requestTarget - The original target PathPosition of the pathfinding request.
      currentNode - The current Node being expanded.
      openSet - The priority queue (open set) to add new successor nodes to.