I'm working on a personal project that requires solving the well-known shortest-path problem.
I have 256x256 tiles maps like the following:
I'm only interested in white (walkable) areas. The rest are either walls or voids on the map.
Running a simple Dijkstra or A-star algorithm produces a path like this one:
However, it takes more time than expected. When I draw every visited tile I get these images, depending on the algorithm used:
Visited tiles while finding shortest path 1
Visited tiles while finding shortest path 2
I know there is almost infinite research on pathfinding, and that's great unless you don't know where to start. The problem is quite simple, I think. The cost of every arc is simply the Euclidean distance between them. These maps have portals that shorten the path length, but I didn't add them yet. The path doesn't have to be the shortest one, either, just a reasonable one is fine.
I noticed that I could break the problem into 3 simpler problems, but to do this I need this kind of modification on the map:
Now, the walkable areas are the gray ones. Finding the shortest path between any pair of gray points is almost free, even with bare Dijkstra.
The partition of the problem would look like this, when trying to connect points A and B:
- Find the closest gray point to A. Let's call this point Ag.
- Find the closest gray point to B. Let's call this point Bg.
- Find the shortest path for these pair of points: (A-Ag) (Ag-Bg) (Bg-B).
- The concatenation of these 3 paths are the solution to my problem.
A and Ag should be (almost) linearly reachable to one another, the same with B and Bg. It's possible that the closest gray point to A is on the other side of a wall, so we should find the next closest Ag point. But this is just an idea.
The concrete question is: Is there an algorithm to make such simplification on the map? or what shortest path algorith would you suggest?
Thanks!