Interface PathfinderUtil.World<N extends PathfinderUtil.PathNode>

Type Parameters:
N - The specific type of PathNode
Enclosing class:
PathfinderUtil

public static interface PathfinderUtil.World<N extends PathfinderUtil.PathNode>
Provides several functions used by the find methods. It should represent the graph and the goal to find.
Since:
1.5
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Estimates the remaining cost to reach the goal from the provided node.
    void
    insertNeighbors(N node, Collection<N> neighbors)
    Adds the neighbor nodes of the provided node to the provided Collection.
    boolean
    isGoal(N node)
    Determines whether the provided node represents a goal position.
    boolean
    positionEqual(N node1, N node2)
    Determines whether the provided nodes represent the same position (node in a graph).
    int
    Calculates a hash of the position (node in a graph) represented by the provided node.
    default boolean
    preferOrigin(N present, N proposal)
    Chooses between two nodes with equal cost representing the same position.
  • Method Details

    • positionHash

      int positionHash(N node)
      Calculates a hash of the position (node in a graph) represented by the provided node. Similar to Object.hashCode(), but supposed to only consider the represented position.
      Parameters:
      node - The node containing the position to hash
      Returns:
      The hash
    • positionEqual

      boolean positionEqual(N node1, N node2)
      Determines whether the provided nodes represent the same position (node in a graph). Similar to Object.equals(Object), but supposed to only consider the represented position.
      Parameters:
      node1 - A node
      node2 - Another node
      Returns:
      whether the provided nodes represent the same position
    • insertNeighbors

      void insertNeighbors(N node, Collection<N> neighbors)
      Adds the neighbor nodes of the provided node to the provided Collection. The resulting PathNodes are typically linked to the input node as their "previous" PathNode.
      Parameters:
      node - The original node
      neighbors - The Collection to put the original nodes neighbors into
    • estimateRemainingCost

      double estimateRemainingCost(N node)
      Estimates the remaining cost to reach the goal from the provided node. This is the heuristic function.
      Parameters:
      node - The node to estimate the remaining cost from
      Returns:
      An estimate of the remaining cost to reach the goal
    • isGoal

      boolean isGoal(N node)
      Determines whether the provided node represents a goal position. This typically compares the provided node to one specific goal position.
      Parameters:
      node - The node to test
      Returns:
      whether the provided node represents a goal position
    • preferOrigin

      default boolean preferOrigin(N present, N proposal)
      Chooses between two nodes with equal cost representing the same position. When this is implemented, visiting all optimal paths is typically desired by setting all=true in PathfinderUtil.find(PathNode, boolean, PositionMap, World). This can also be used to record all available choices by merging the proposed node into the present node and returning false. To simply find one arbitrary optimal path, you do not need to implement or care about this.
      Parameters:
      present - The present node to be kept when false is returned
      proposal - The proposed node to replace the present node with when true is returned
      Returns:
      false if the present node is to be kept, true if the proposed node should be used instead. Defaults to false. Note that when choosing to replace the present node (by returning true), PathNodes are no longer guaranteed to be created from their preferred origin PathNodes, possibly requiring you to retrieve every replaced node from the final PathfinderUtil.PositionMap after PathfinderUtil.find(PathNode, boolean, PositionMap, World) to really find a path adhering to the defined preference.