asBestPathfinder<G extends Goal<E> > method
Adapts this HeuristicPathfinder to a BestPathfinder.
When a Goal.node is used, toNode
is used to derive the heuristic,
otherwise orElse
is used. You should consider creating a sealed class
for your set of heuristics so pattern matching can be used.
Example
sealed class MyGoal implements Goal<MyNode> {
const MyGoal();
}
final adapted = astar.asBestPathfinder(
toNode: <T>(target) => toHeuristic(target),
orElse: <T>(start, goal) => switch (goal) {
TileTypeGoal t => doSomethingElse(t),
_ => Heuristic.zero(),
},
);
Implementation
BestPathfinder<E> asBestPathfinder<G extends Goal<E>>({
required Heuristic<T> Function<T extends E>(E) toNode,
required Heuristic<T> Function<T extends E>(E, G) orElse,
}) {
return _AsBestPathfinder(this, toNode, orElse);
}