OS/device including version: Ubuntu 18.04.4 LTS x86_64
Astar2D path finding is not consistent due to the use of OAHashMap. The tie breaker for choosing points that are equivalent in distance from any current point is decided by which was first iterated in the OAHashMap as seen here
I can understand the want for speed with the lookups, but having inconsistent results in pathfinding is not worth the cost in my opinion; I think we should consider adding the option for Astar to use an ordered set, such as the ordered_hash_map if not outright changing the graph to use it.
Visualizing this as a number pad, 1 on bottom left, 9 on the top right, 3 on the bottom right..
We get the first big standout result with the path from 9 to 1 breaking the ties at nodes 9 and 5 differently. On 9, it goes to 8 (left node), and on 5 it goes to 2 (bottom node), whereas on the path from 1 to 9, the ties broken are consistent. On 1 to 9, the ties are at 1 (going up to 4), and at 5 (again going up 8).
I'm not sure how much of a reproduction effect this has on say multiplayer games where 2 different clients need to recalculate the same path and ties are being handled on each machine, but this does have an affect on 2d grid games where the pathing just looks odd when it isn't consistent across diagonals.
Godot version: 3.2.stable
OS/device including version: Ubuntu 18.04.4 LTS x86_64
Astar2D path finding is not consistent due to the use of OAHashMap. The tie breaker for choosing points that are equivalent in distance from any current point is decided by which was first iterated in the OAHashMap as seen here
I can understand the want for speed with the lookups, but having inconsistent results in pathfinding is not worth the cost in my opinion; I think we should consider adding the option for Astar to use an ordered set, such as the ordered_hash_map if not outright changing the graph to use it.
Quick minimal setup to see the inconsistency.
Visualizing this as a number pad, 1 on bottom left, 9 on the top right, 3 on the bottom right.. We get the first big standout result with the path from 9 to 1 breaking the ties at nodes 9 and 5 differently. On 9, it goes to 8 (left node), and on 5 it goes to 2 (bottom node), whereas on the path from 1 to 9, the ties broken are consistent. On 1 to 9, the ties are at 1 (going up to 4), and at 5 (again going up 8).
I'm not sure how much of a reproduction effect this has on say multiplayer games where 2 different clients need to recalculate the same path and ties are being handled on each machine, but this does have an affect on 2d grid games where the pathing just looks odd when it isn't consistent across diagonals.