I\'m creating a game with a 10,000 by 10,000 map.
I would like for a user to be able to set a location and have the computer instantly find the best path.
However, since
So even though there might be n^4
shortest paths on a square n by n map. storing all the paths doesn't necessarily require O(n^4)
space. The idea is that given two different target locations on the map and their shortest path trees, than the closer those two points are on the map, the more common elements will their shortest path trees have. This is especially true when using a planar map like a grid with obstacles.
So the idea is to store only some complete shortest path trees for a small set of target locations (may even be only one target location). For the rest of the target locations only the difference of its shortest path tree to one of the previously stored shortest path trees is stored.
Then the algorithm to find the shortest path from one location to a target is to load a fully stored shortest path tree and then apply some diffs to it to get the shortest path tree of the target location. Then only the current player position needs to be found on the shortest path tree which is O(n^2)
complexity.
I don't have any hard facts on how much storage space is needed for storing the shortest path trees and their diffs, but this could be in the range O(n^2 log(n^2))
. Loading one and appyling the diffs might only have time complexity of O(n^2)
.
The shortest path tree for a target location represents all the shortest path from every location on the map to the target location.
This solution may also keep the used shortest path tree in memory and apply diffs as necessary in order to get the new shortest path tree to use. Then the complexity of getting the shortest path tree is not bound by the size of the map, but just by the size of the diffs to be applied. This scenario might really work well for games like the original Sacred or Diablo.