I've implemented AStar in Java and it works ok for an area with obstacles where the chosen destination is reachable.
However, when the destination is unreachable, the calculated "path" is in no way to the closest location (to the unreachable location) but is instead some random path.
Is there a feasible way to tweak AStar into finding the path to the closest location to an unreachable destination?
Answer
Keep track of the node with the lowest EstimatedDistanceToEnd
(ie. the lowest h(x)
), and if no end-node is reachable to backtrack from, backtrack from that node instead.
No comments:
Post a Comment