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.71k stars 375 forks source link

Combat, AI tends to prioritize the strongest stack without considering its flying ability/higher speed #9225

Open Branikolog opened 4 days ago

Branikolog commented 4 days ago

Preliminary checks

Describe the problem requiring a solution

https://github.com/user-attachments/assets/1fc1c0e3-59e5-431e-a8e0-9c43aba1dc1e

The current AI allows player to kite him using flying creatures.

Describe the possible solution

I expect AI to focus on slower stack, especially if it is ranged troops. Unless AI can reach the flying one within the current move of course. Also AI can split his troops and focus several enemies at once: running with all his stacks after the genie or stack of Rocs has no sense - he never reaches it until player decides to go for melee himself.

Additional info

No response

zenseii commented 4 days ago

I believe this issue is related to the one we have about implementing an AI which plans more steps ahead. In addition it sounds like to solve this we would need to teach the AI to make an overall coordinated battle plan for all its troops and not just one and one in isolation which is mostly what it does now.

Branikolog commented 4 days ago

Hi, @zenseii Yeah, battle planning is a huge task to work on. In my opinion, with the current AI we can just try to add special pattern for troops not to chase the flying stack, if the flying stack does not attack anyone and focus on slow/walking/ranged troops. I believe AI should focus on flying troop only if it is in the attacking range on the current round or just stands on the close hex to any other allied troops (potentially blocking allied shooters).

oleg-derevenetz commented 4 days ago

In my opinion, with the current AI we can just try to add special pattern for troops not to chase the flying stack, if the flying stack does not attack anyone and focus on slow/walking/ranged troops.

A similar logic already existed, but it did not work for several reasons:

  1. Penalty for trying to catch faster units was too low (this issue was mostly related to comparison between flying and non-flying units);
  2. The wrong speed was used when comparing the speed of non-flying units.

There are multiple "speeds" of units in the game:

  1. The "natural" one (from the unit's characteristics);
  2. The "battle" one (the "natural" one affected by Slow/Haste/Paralyze/Blind/Petrify spells);
  3. The "turn order" one (the "battle" one that becomes zero when unit already had its turn).

That logic used the "turn order" speed instead of the "battle" speed. When the turn order reached a slower unit, the faster units, naturally, already had their turn, so their "turn order" speed was zero, and slower units always thought they were faster, even if they weren't.