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

Combat, AI behavior, AI should try to keep its powerful heroes by making them flee before the end of a combat, especially when they also have artifacts (0.9.9 4551) #4585

Open LeHerosInconnu opened 2 years ago

LeHerosInconnu commented 2 years ago

Preliminary checks

Platform

Windows

Describe the bug

In fheroes2, the AI should try to keep its powerful heroes by making them flee before the end of a combat, especially when they also have artifacts. Myrini is quite a strong hero, and the AI does not make her flee before the end of the combat.

In fheroes2:

https://user-images.githubusercontent.com/43583994/140625794-2001ab4a-5275-46c7-a76a-6db9b58655ad.mp4

Halon attacks Myrini.

Save file

Here is the save file: Before attack disrupting ray_.zip

Additional info

Game started with version 0.9.8 4544 and continued with version 0.9.9 4551.

Edit 2022/11/03.

Another save for this (version 0.9.20 5949): AI hero should flee 01.zip

In fheroes2:

https://user-images.githubusercontent.com/43583994/199723651-a677988f-2ca8-4bab-8338-41bf38bb1b19.mp4

vincent-grosbois commented 2 years ago

The issue with this is the heuristic used for fleeing Basically it compares the relative army strengths. When yours is < 0.1 , you flee. This really doesn't work well here for instance where at the end the ratio between army strengths is still fairly high (I think it's something like 0.3 for 3 titans vs 1)

To me we should also add another heuristic for fleeing, where for instance when the our total army HP is below 100-200, we flee even when the ratio is 0.5

what do you all think?

LeHerosInconnu commented 2 years ago

Hello @vincent-grosbois,

The issue with this is the heuristic used for fleeing Basically it compares the relative army strengths. When yours is < 0.1 , you flee. This really doesn't work well here for instance where at the end the ratio between army strengths is still fairly high (I think it's something like 0.3 for 3 titans vs 1)

To me we should also add another heuristic for fleeing, where for instance when the our total army HP is below 100-200, we flee even when the ratio is 0.5

what do you all think?

I am really not familiar with the functioning and coding of an AI (or anything else), :) but here is the way I proceed before making one of my heroes flee. The goal being to make a maximum of loss of creatures to the opposite hero without giving him uselessly experience points. But I don't know if this is easily doable for the AI behavior. So, that's just my two cents. :)

It depend principally on the damage possibilities of the hero and the opposing troops. For example, if the hero who should flee has four troops left with less than 100 hit points in total and the opposing hero can decimate one troop with a damage spell and one troop with a physical attack. I also take into account the morale of the opposing troops in case they can play several times and decimate another troop, as well as the speed of the opposing troops if they are going to play first the next turn, and the morale of the troops of the hero who should flee, if their morale is negative it may not be possible to play before one of the opposing troops the next turn. And all this under the condition that the hero who should flee can inflict the loss of opposing creatures the next turn either by magic or by physical attack (e.g. decimate another Titan (or even a lesser creature) with a spell or with a physical attack before fleeing).

LeHerosInconnu commented 1 year ago

Another save for this.

In fheroes2:

AI hero should flee 001

AI hero should flee 002

https://github.com/ihhub/fheroes2/assets/43583994/56cd33ea-4dba-4216-881b-b627a517dad6

Here is the save file (1.0.4 7247): Strong AI hero no flee 01.zip

LeHerosInconnu commented 1 year ago

Another save for this.

In fheroes2:

https://github.com/ihhub/fheroes2/assets/43583994/df53611c-8cc6-4e96-97e7-ca487b3a644f

Here is the save file (1.0.4 7265): End the turn. AI should flee 10.zip