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.6k stars 365 forks source link

Improve AI to use magic or not #7798

Open fheroes2bugs opened 9 months ago

fheroes2bugs commented 9 months ago

Preliminary checks

Describe the problem requiring a solution

I found some kind of AI weak behavior (not using spell in batte).

Situation 1: I have 25/50 mana, end the turn, get 26/50 mana, I attack trolls and AI wins battle for me (he uses bless spell 1 time). 0 dead units. Situation 2: I have 25/50 mana, I visit witch doctor's hut, so the day after I have 26/60, I fight the same trolls, but now AI is not using spells, and I lose 2 phenixes...

At first look, hero in situation 2 in stronger, he got +1 knowledge, but AI compares current mana/maximum mana and decides not to use mana at all and I lose units.

Situation 1, where I just fight the trolls and have no dead units:

https://github.com/ihhub/fheroes2/assets/145407420/16853568-0e6f-432b-b841-c3907455e533

Situation 1, the battle:

https://github.com/ihhub/fheroes2/assets/145407420/f7fa3b47-c03f-4441-8b19-c65978559934

Situation 2, where I visit witch doctor's hut and then attack trolls and have 2 dead units:

https://github.com/ihhub/fheroes2/assets/145407420/e42cf7f2-c4cc-4c12-98a9-56b6619991ec

Situation2, the battle:

https://github.com/ihhub/fheroes2/assets/145407420/ce3ed29a-8e41-4c36-a600-26b5347ccf76

Describe the possible solution

Sure AI should use spells to get minimum dead units, no matter what is the balance current mana/full mana.

Additional info

visit object or not.zip

ihhub commented 9 months ago

This is too broad suggestion. I can name a bunch of situations where both logics would be valid. There is not golden rule how the AI should behave, unless we implement turn prediction mechanism.

Branikolog commented 9 months ago

Hi, @ihhub !

I had other similar complains regarding mana usage. The current logic is too straightforward and inflexible. In some cases AI can loose significant number of troops, just because he doesn't want to use spells. I have an idea of changing the AI spells usage according to difficulty level. So on easier difficulties AI should use spells quite rare, like 1-2 per battle, while on harder difficulty AI should use spells more often, but leaving 0~50% of mana (+/- according to the enemy strength) and make AI using spells more aggressively and frequent on expert/impossible mode. In the last mission of PoL campaign when fighting a hero with 1k Bone dragons, AI simply doesn't want to use spells, just because the army is much stronger and all creatures under mass slow keep walking allowing player to kite and damage them, while he can dispel/cure/haste and finish the battle more effectively.

@fheroes2bugs Don't forget, that each time you replay the battle with a little bit other actions you make before it could make the damage of all creatures completely different (you could even notice a luck even happening for other stack on your video). That could be also the reason of much higher losses.