简体   繁体   中英

Get the first move in the shortest path - 2d array - java

I have a 2d array (assume like the one below):

#....#.#
####.###
.....#.#
##..#.##

# = obstacle and . = empty

I have been able to calculate the shortest path from one point in the maze to another. However, instead of doing this, I would only like to get the first move of this calculated shortest path.

Is there a better way to do this rather than having to recalculate the whole shortest path again and again....

I am comfortable switching between a*, dijkstra and bfs.

Any suggests would be appreciated.

You can try to guess which of the available moves would get you closer to the end point using some heuristics. However, if you want to get the first move of the absolute shortest path, you have to calculate the whole path. You can try to use some memoization to improve your performance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM