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 TypeMethodDescriptiondoubleestimateRemainingCost(N node) Estimates the remaining cost to reach the goal from the provided node.voidinsertNeighbors(N node, Collection<N> neighbors) Adds the neighbor nodes of the provided node to the provided Collection.booleanDetermines whether the provided node represents a goal position.booleanpositionEqual(N node1, N node2) Determines whether the provided nodes represent the same position (node in a graph).intpositionHash(N node) Calculates a hash of the position (node in a graph) represented by the provided node.default booleanpreferOrigin(N present, N proposal) Chooses between two nodes with equal cost representing the same position.
-
Method Details
-
positionHash
Calculates a hash of the position (node in a graph) represented by the provided node. Similar toObject.hashCode(), but supposed to only consider the represented position.- Parameters:
node- The node containing the position to hash- Returns:
- The hash
-
positionEqual
Determines whether the provided nodes represent the same position (node in a graph). Similar toObject.equals(Object), but supposed to only consider the represented position.- Parameters:
node1- A nodenode2- Another node- Returns:
- whether the provided nodes represent the same position
-
insertNeighbors
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 nodeneighbors- The Collection to put the original nodes neighbors into
-
estimateRemainingCost
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
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
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 inPathfinderUtil.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 returnedproposal- 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.PositionMapafterPathfinderUtil.find(PathNode, boolean, PositionMap, World)to really find a path adhering to the defined preference.
-