Class PathfinderUtil
java.lang.Object
de.tomatengames.util.PathfinderUtil
Provides methods to find optimal paths on graphs using the A* algorithm.
- Since:
- 1.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA PathNode should represent a position (node in a graph) combined with the way to get there (edges) from the startpoint.static classA Map-like structure specifically forPathfinderUtil.PathNodes.static interfacePathfinderUtil.World<N extends PathfinderUtil.PathNode>Provides several functions used by thefindmethods. -
Method Summary
Modifier and TypeMethodDescriptionstatic <N extends PathfinderUtil.PathNode>
Nfind(N start, boolean all, PathfinderUtil.PositionMap<N> positionMap, PathfinderUtil.World<N> world) Finds a goal from the provided startpoint, using the providedPathfinderUtil.Worldto traverse the environment.static <N extends PathfinderUtil.PathNode>
Nfind(N start, PathfinderUtil.World<N> world) Finds a goal from the provided startpoint, using the providedPathfinderUtil.Worldto traverse the environment.static <N> List<N> Utility to list the PathNodes from the startpoint to the provided PathNode.static <N> voidtraverseAll(N node, Function<N, Iterator<N>> neighbors, Consumer<N> output) Utility to recursively find all PathNodes indirectly connected to the provided node.
-
Method Details
-
find
Finds a goal from the provided startpoint, using the providedPathfinderUtil.Worldto traverse the environment.- Type Parameters:
N- The specific type of PathNode used- Parameters:
start- The startpointworld- ThePathfinderUtil.World- Returns:
- A goal PathNode
- See Also:
-
find
public static <N extends PathfinderUtil.PathNode> N find(N start, boolean all, PathfinderUtil.PositionMap<N> positionMap, PathfinderUtil.World<N> world) Finds a goal from the provided startpoint, using the providedPathfinderUtil.Worldto traverse the environment. Set the parameterallto true to consider all optimal paths, enablingPathfinderUtil.World.preferOrigin(PathNode, PathNode)to choose from all the optimal paths. The providedPathfinderUtil.PositionMapwill be used to map any position to the cheapest PathNode that was yet found representing that position. An empty map should be provided here, but its contents may be interesting after this method returns (seePathfinderUtil.World.preferOrigin(PathNode, PathNode)).- Type Parameters:
N- The specific type of PathNode used- Parameters:
start- The startpointall- whether to visit all optimal pathspositionMap- ThePathfinderUtil.PositionMapworld- ThePathfinderUtil.World- Returns:
- A goal PathNode
-
listPath
Utility to list the PathNodes from the startpoint to the provided PathNode. Typically, a PathNode knows their original PathNode (previous), which this method obtains using the provided function.- Type Parameters:
N- The specific type of PathNode- Parameters:
node- The furthest PathNode, typically the found goalprevious- The function used to obtain a PathNodes previous PathNode, or null if the list is complete, which typically means that the input PathNode is the startpoint.- Returns:
- A list from the startpoint (first) up to the provided PathNode (last)
-
traverseAll
Utility to recursively find all PathNodes indirectly connected to the provided node. This may be useful for collecting all PathNodes involved in any path from start to goal when multiple possible paths were recorded.- Type Parameters:
N- The specific type of PathNode- Parameters:
node- The initial PathNode to start searching fromneighbors- The function providing the PathNodes directly connected to the input PathNodeoutput- The Consumer that all found PathNodes will be put into
-