The pathfinding code uses an algorithm to weight all of the possible tiles to move to
Interesting.
In old style games (going back to real oldies like Reach for the Stars) pathfinding was not a dynamic calculation. You just simply calculated the total distance and divided by the speed and that's how many turns the move took, no more no less. However movement was not displayed along the traveled path and in essence scheduling a fleet or ship for movement essentially placed it in "hyperspace" for the calculated duration of turns making the ship/fleet unavailable until it "popped" back into existence at the destination in the appropriate turn.
Certainly having to display the ship/fleet over the course of its path and allowing for the possibility that the ship/fleets destination may change at each turn while also having to account for moving obstacles (i.e. other ships) makes the pathfinding problem far more difficult.
While I understand the increased difficulty that this kind of dynamic pathfinding entails I have also been frustrated by the inefficiencies of the current code that can result in causing an autopilot path to take an extra turn over the path a human can take.
However, one of the biggest source of “extra” moves that I see occur in the game result from something that I would think could be fixed, although how easy such a fix would be I have no clue.
When setting a course from a source to a destination in a Cartesian plane (assuming that the motion is not directly along one of the two main axes or the diagonal formed by these axes) the minimum course is contained within an envelope that is bounded by two different paths. One path is to first take the direct horizontal or vertical path and then take a direct diagonal path from the source to the destination. The other path is to first take the diagonal path followed by the horizontal/vertical path. These two paths form a parallelogram with the source and destination at opposite corners of the parallelogram. Any path that is contained within this parallelogram will also be a minimum path course as long as you always go towards the destination. This isn’t really a mathematical definition of a minimum path but I’m sure you get the picture.
The problem with pathfinding as I see it is that it tends to take one of the two outer boundaries of the parallelogram as its basic course and then deviates from it as it encounters an obstacle. The issue is that since the course is one of the outside borders of the bounds on a minimum path it often occurs that when an obstacle is encountered a detour must be taken that lengthens the total path. However if instead of insisting on traveling the boundary of the parallelogram, a path is negotiated more down the center axis of the parallelogram then there is much more freedom to negotiate around an obstacle without increasing it’s path length. Of course this results in a path that is less “smooth” to follow but it does result in greater likelihood that the ship/fleet arrives at the destination in the minimum time i.e. the same turn a human would get there.
Another possible algorithm to use is illustrated by the following example. Let’s say an autopilot path is selected from a source to a destination. Let’s also stipulate that the destination is to the left and down of the source and that the destination is further to the left of the source than it is down from the source. In this case the minimum path is any course that goes from source to destination that uses any combination of moves directly to the left or diagonally downward to the left. Movement in any of the other six possible directions results in an increase of the path length and should be avoided. Now given that most obstacles are simple one point obstructions then calculating a path three parsecs in advance will avoid most of the “extra” moves that I see the autopilot take. Clearly if multiple objects form a barrier then this won’t necessarily work, but most of the time I see the autopilot take extra moves is because it happens to choose the “wrong” way to go around a single point static object like a planet.