ihhub / fheroes2

fheroes2 is a recreation of Heroes of Might and Magic II game engine.
https://ihhub.github.io/fheroes2/
GNU General Public License v2.0
2.58k stars 359 forks source link

AI is stuck dancing in a whirlpool #7297

Open Stiivi opened 1 year ago

Stiivi commented 1 year ago

Preliminary checks

Platform

macOS

Describe the bug

In maps with whirlpools, usually where there is more of them, the AI has a strong tendency to get stuck in a weird "dance" for a while. When they enter the whirlpool they immediately enter another tile of the "exit" whirlpool and repeat that several times. It does not look like they are trying to emerge at certain location, since they tend to exit the whirlpool even if they re-emerge at a location that they already visited during the "dance".

Attached is a save file. To reproduce: just end the turn several times without doing nothing and observe the AI.

Save file

whirlpool.sav.zip

Additional info

No response

oleg-derevenetz commented 1 year ago

AI-controlled heroes pave their paths through the whirlpools as if these whirlpools are directly connected. But because of random nature of whirlpools, these heroes most likely will end up in the wrong place (not where they originally planned), so they will re-assess their targets after each whirlpool "teleportation". If such a hero wants to reach some specific target regardless of environment/fog discovery, he will continue to try the whirlpools until he arrives at the right place. Since targets are re-assessed each time, he may at some point choose a different target near some already visited whirlpool (for example, because he spent some extra movement points in these whirlpools and original target is now too "far").

oleg-derevenetz commented 1 year ago

I looked at the AI's actions several times within a few turns after loading the save file and haven't seen anything particularly suspicious yet.

Stiivi commented 1 year ago

AI-controlled heroes pave their paths through the whirlpools as if these whirlpools are directly connected. But because of random nature of whirlpools, these heroes most likely will end up in the wrong place (not where they originally planned), so they will re-assess their targets after each whirlpool "teleportation". If such a hero wants to reach some specific target regardless of environment/fog discovery, he will continue to try the whirlpools until he arrives at the right place. Since targets are re-assessed each time, he may at some point choose a different target near some already visited whirlpool (for example, because he spent some extra movement points in these whirlpools and original target is now too "far").

This explanation makes sense. I am not considering this issue to be a bug, just a behaviour that sometimes adds a bit of annoyance when multiple computer players are swirling in the whirlpool - going left-right-left-right in whirlpools (say we have 3: A, B and C) A→B→A→B→C→A→Exit ...

I am not quite sure though what a good solution for this would be. Maybe a counter and no re-entry after one, two or number_of_whirpools_in_the_map teleportations? I do not have a good understanding of the overall world map AI, so it is hard for me to judge.

I might try to get a save-game where multiple boats are out in the sea.

dood-apo commented 5 months ago

@oleg-derevenetz I agree that multiple whirlpool entering by AI is acceptable. However, AI should just re-enter the whirlpool without leaving the tile. Currently AI loses movement points to get out of the whirlpool tile and to step right back into it.

oleg-derevenetz commented 5 months ago

Hi @dood-apo

However, AI should just re-enter the whirlpool without leaving the tile. Currently AI loses movement points to get out of the whirlpool tile and to step right back into it.

There was no such mechanics in the original HoMM2, it is human-only "improvement" in fheroes2 (so-called "spacebar mechanics") which was borrowed from HoMM3. There are discussions about the possibility of extending this behavior to AI, because there are maps made with the expectation that AI has difficulty transferring heroes and reinforcements between different parts of the map due to the random nature of Stone Liths and Whirlpools, and the ability to get to the right point right away without wasting extra movement points will break such maps. So the current AI behavior is intentional.