Hi, I don't know if I should put this in script support/engine support as it is more of an algorithmic question than related to an engine but if you feel like it does not belong here, please move this thread. I'm working on a pathfinding algorithm for units in my battle system (engine is vx ace) and I have issues with computer-controlled units:
Take a grid with cells filled with units or empty such that no two units may share the same position (but some can cross other's position in their paths). Some cells may cost more than others to cross.
Take a unit in position x,y on the grid and you want to reach an empty position x',y' that I will call target.
Assume your unit is limited in move points in a single turn and cannot reach the target this turn.
Running a shortest path algorithm (like Dijkstra or A*) provides an optimal path from your unit to the target, but you have to cut the path returned because it's too long to cross in a single turn. However, the cut path may stop at a non-empty cell.
In that case, you may consider reducing even more the path.
What if you cut your path so much that a better alternative path may exist somewhere else?
How would you compute such better path while trying to minimize the calls to a shortest path algorithm?
Example here: the blue box is your unit, the blue cross is the target, the red boxes are other units you may cross (but not stay at). The light blue trail is the returned path by your first shortest path algorithm call and you can cross 3 cells per turn.
Obviously, here there is a better solution that we can get 'easily' by calling once again our shortest path algorithm and excluding at least the farthest red square. But a second call might not be enough in general.
Take a grid with cells filled with units or empty such that no two units may share the same position (but some can cross other's position in their paths). Some cells may cost more than others to cross.
Take a unit in position x,y on the grid and you want to reach an empty position x',y' that I will call target.
Assume your unit is limited in move points in a single turn and cannot reach the target this turn.
Running a shortest path algorithm (like Dijkstra or A*) provides an optimal path from your unit to the target, but you have to cut the path returned because it's too long to cross in a single turn. However, the cut path may stop at a non-empty cell.
In that case, you may consider reducing even more the path.
What if you cut your path so much that a better alternative path may exist somewhere else?
How would you compute such better path while trying to minimize the calls to a shortest path algorithm?
Example here: the blue box is your unit, the blue cross is the target, the red boxes are other units you may cross (but not stay at). The light blue trail is the returned path by your first shortest path algorithm call and you can cross 3 cells per turn.
Obviously, here there is a better solution that we can get 'easily' by calling once again our shortest path algorithm and excluding at least the farthest red square. But a second call might not be enough in general.