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 uses attacking spells to demolish a single creature #8234

Open Branikolog opened 9 months ago

Branikolog commented 9 months ago

Preliminary checks

Describe the problem requiring a solution

AI is using the "Cold ray" spell to demolish a single elf, while he can kill a couple or a stronger druid:

https://github.com/ihhub/fheroes2/assets/55348946/35efa063-2b2b-4697-bcbd-d35dd5f12d5d

https://github.com/ihhub/fheroes2/assets/55348946/fbb3c13c-7420-405e-95e9-478bca33a31e

Describe the possible solution

Current spell is too powerful to kill a single elf. If the damage was like 20 it could be a proper move, but 40 dmg of the Cold ray would be more effective to apply over other troops.

Additional info

nancyurkus42 (1).zip Ice ray.zip

oleg-derevenetz commented 9 months ago

There is a bonus for destroying the entire stack which depends on the total enemy army value, so in this case AI prefers to kill the entire stack rather than kill 1-2 units in other stacks.

Branikolog commented 9 months ago

@oleg-derevenetz Thanks for clarification! Is there anything we can improve here? Like consider the difference in killing amount of troops, since Cold ray seems to have power to kill > 2x time more troops than demolished single elf.

oleg-derevenetz commented 9 months ago

Like consider the difference in killing amount of troops, since Cold ray seems to have power to kill > 2x time more troops than demolished single elf.

It is already considered. It's a bonus, so it's added to the value of troops that are considered as potential targets, and so it turns out that in this case this bonus exceeds the benefits of killing troops in other stacks (1 Unicorn, 1 Druid, 2 Elves or 2 Dwarves that can be killed by 40 damage of Cold Ray, not much really).

FyiurAmron commented 8 months ago

@Branikolog when you realize that each stack that is alive even with a 1 unit in it is still able to win the fight, and that it can still e.g. remove the counterattack of 1000 giants, protect a side of other unit with itself, AI behaviour is completely in line with a reasonable human's behaviour - especially since the dwarves are the strongest stack anyway, and they have resistance and can't enter the castle yet. TBH, that elf should just go to e.g. cover the druids coupled with the unicorns, so AI is effectively preventing that strategy, and also creates more tactical options for its flyers.

It's not a bug, it's a feature.

Branikolog commented 8 months ago

@FyiurAmron In the most common case you, me or any other player should try to kill as much enemy troops as possible. At one example above AI has a much weaker army, so focus on dealing the maximum damage is a good way survive a few turns more and bring more losses to enemy. Killing 1 unicorn is much more beneficial than 1 elf in this regard. Also killing 1 druid seems rather reasonable for me too. When testing on other match ups with not such obvious dominance of one side AI tends to apply Cold Ray over the stack stronger than 1 elf. The reason I created an issue is that the AI logic seems questionable here and I'm worried whether everything works as intended. I'm not against demolishing 1 stack, but there should be an obvious reason for that: like 1 elf is blocking a shooter and gargoyles can deal much more damage when attacking a shooter in melee fight. Otherwise I suggest implementing an additional logic (or improve the existing, if such cases are already handled) that will force AI not to waste too powerful spells over weak creatures.

https://github.com/ihhub/fheroes2/assets/55348946/e7be8097-4dd7-4c2f-b11c-b12fd741ec18

FyiurAmron commented 8 months ago

@FyiurAmron In the most common case you, me or any other player should try to kill as much enemy troops as possible.

Honestly, it depends on how you define "as much" - in raw numbers, or in stacks. I'd still say in this case simply getting rid of a stack is better, due to how low the damage of the spell is compared to the strength of the biggest stack(s).

At one example above AI has a much weaker army, so focus on dealing the maximum damage is a good way survive a few turns more and bring more losses to enemy.

Like already mentioned, the difference in overall damage is so low that I would go for that single elf in this case. That elf is Very Fast, so it's a really worthwhile target, esp. since the defender doesn't have dragons, so that elf can basically block any single hex for a single turn, and also force the positioning of 1 flyer to kill it.

Killing 1 unicorn is much more beneficial than 1 elf in this regard. Also killing 1 druid seems rather reasonable for me too.

I wouldn't agree. It's a castle siege, so I'd leave the unicorns, they're only blocking the dwarves and making it harder for the attacker. 3 or 2, it's also mostly irrelevant, it's not like a difference between 3 or 2 Black Dragons, raw damage output of unicorns is very high for a lev 5 unit, but still quite low overall in this case. BTW, proc of blind is the same whether it's 3, 2 or 1 uni. (this rule did change a bit for some procs in HoMM3)

As to the druid - it won't matter, it's probably dead due to flyers. That 40 dam is not relevant there.

I thus still say that AI did the right choice here, taking everything into account.

When testing on other match ups with not such obvious dominance of one side AI tends to apply Cold Ray over the stack stronger than 1 elf. The reason I created an issue is that the AI logic seems questionable here and I'm worried whether everything works as intended. I'm not against demolishing 1 stack, but there should be an obvious reason for that: like 1 elf is blocking a shooter and gargoyles can deal much more damage when attacking a shooter in melee fight. Otherwise I suggest implementing an additional logic (or improve the existing, if such cases are already handled) that will force AI not to waste too powerful spells over weak creatures.

Key word "too powerful spell". 40 dam is not "too powerful". Like I said, this is a really fun and good AI behaviour IMVHO. Makes it a little less predictable and a little more "human". Also, it does the job - less stacks, better tactical outcome (with blind e.g.).

I mean, I completely understand what you're aiming at, but AI is mirroring here what I was actually doing for years (or decades, to be more precise) in both HoMM2 & HoMM3, with really good results. If I can e.g. kill a 10 unit stack or reduce a 20 unit stack to 8, the decision would be based on whether I'm expecting that unit to do any noticeable damage in that turn or not. If not, I'd just wipe the stack. If yes (e.g. I'm intending to attack it), then a softening is obviously better. It can be argued about in general, sure, but it's not a bug or something that should be simply "fixed" IMVHO. Maybe improved, though.

If anything, I would wait with the spell for a later part of the turn in this case, that's the real optimization that's missing here IMO.

Branikolog commented 8 months ago

@FyiurAmron

Key word "too powerful spell". 40 dam is not "too powerful"

Depending on how much damage is wasted for nowhere: elf has just 15HP and with this spell a unicorn could be killed or ~1,5 druids. If AI decided to demolish a stack of 1 elf with a spell with 20 -25 damage - this would be a nice decision. But 40... Is questionable (unless AI uses this spell to demolish a stack to allow other troop with a potentially more harmful attack reach a troop behind the stack as I spoke above).

Killing 1 unicorn is much more beneficial than 1 elf in this regard. Also killing 1 druid seems rather reasonable for me too.

I wouldn't agree. It's a castle siege, so I'd leave the unicorns, they're only blocking the dwarves and making it harder for the attacker. 3 or 2, it's also mostly irrelevant, it's not like a difference between 3 or 2 Black Dragons, raw damage output of unicorns is very high for a lev 5 unit, but still quite low overall in this case. BTW, proc of blind is the same whether it's 3, 2 or 1 uni. (this rule did change a bit for some procs in HoMM3)

It depends on the overall battle flow: if defending AI has no chances to win - there's no point to get rid of those 1troop weak stacks and focus on demolishing stronger troops or killing more creatures in a single hit, especially considering the fact, that overwhelming enemy troops are going to rush the defenders in most cases. In the current situation 62.5% of the spell damage was lost to nowhere. AI has no chance of wining so bringing the greatest losses is what average player would do. Demolishing a single elf... Enemy would just split 1 more elf out the other stack of 13 elves up to the next battle.

Have you watched my attached video from the last comment? AI tends to kill that 1 elf even with a 100dmg spell. The value for demolishing a stack with such exceeding damage should be lowered.

FyiurAmron commented 8 months ago

if defending AI has no chances to win

I think this is the crux here. How can the AI reasonably know that without simulating the outcome? And how can the AI reliably simulate the outcome if they shouldn't know exactly how strong is the attacker (e.g. spellbook) beforehand, without "cheating" and just use the brute game data? I mean, sure, this case is kinda extreme with the amount of dwarves etc., but TBH if the defending hero would be strong enough and would clean the board of the shooters quick enough first, I'd say this could be a close call. (hail of shots from fully upgraded castle defenses + slowing the dwarves + maybe some lightning etc.) - I'm not saying it's winnable here, but in general I could fabricate a setting that wouldn't be too OP that would allow the defender to win with this exact army. To put it the other way around, I've won with AI having the same army disparity but the other way around, especially in castle defense. True, it's a lot easier to cheese castle defense in HoMM3, but it's still doable in HoMM2, just a lot harder.

AI has no chance of wining

see my point above.

Have you watched my attached video from the last comment? AI tends to kill that 1 elf even with a 100dmg spell. The value for demolishing a stack with such exceeding damage should be lowered.

see

It can be argued about in general, sure, but it's not a bug or something that should be simply "fixed" IMVHO. Maybe improved, though.

I fully agree that 100 dam for 1 elf is an overkill most of the time, including this case, and I fully agree the bonus for stack kill could and probably should be tweaked. I'm not saying the exact value is perfect ATM, I'm just saying that IMVHO an AI action rating bonus for stack wipe should stay (just maybe a smaller one). Bear in mind you can easily make this go the other way around by lowering too much - you can then go splitting units to small stacks to "fool" the AI to ignore them as too weak for spells, and then just Resurrect True etc. (a lot harder when multiple stacks are killed instead)

Branikolog commented 8 months ago

@FyiurAmron

I think this is the crux here. How can the AI reasonably know that without simulating the outcome? And how can the AI reliably simulate the outcome if they shouldn't know exactly how strong is the attacker (e.g. spellbook) beforehand, without "cheating" and just use the brute game data? I mean, sure, this case is kinda extreme with the amount of dwarves etc., but TBH if the defending hero would be strong enough and would clean the board of the shooters quick enough first, I'd say this could be a close call. (hail of shots from fully upgraded castle defenses + slowing the dwarves + maybe some lightning etc.) - I'm not saying it's winnable here, but in general I could fabricate a setting that wouldn't be too OP that would allow the defender to win with this exact army. To put it the other way around, I've won with AI having the same army disparity but the other way around, especially in castle defense. True, it's a lot easier to cheese castle defense in HoMM3, but it's still doable in HoMM2, just a lot harder.

There's already strength estimation implemented in fheroes2 AI. Even spells and hero skills are considered. Surely it is not really a precise comparison, but I was talking about significant overwhelming.

I fully agree that 100 dam for 1 elf is an overkill most of the time, including this case, and I fully agree the bonus for stack kill could and probably should be tweaked. I'm not saying the exact value is perfect ATM, I'm just saying that IMVHO an AI action rating bonus for stack wipe should stay (just maybe a smaller one). Bear in mind you can easily make this go the other way around by lowering too much - you can then go splitting units to small stacks to "fool" the AI to ignore them as too weak for spells, and then just Resurrect True etc. (a lot harder when multiple stacks are killed instead)

This is just what I'm talking about and the purpose I've created the issue.

FyiurAmron commented 8 months ago

There's already strength estimation implemented in fheroes2 AI. Even spells and hero skills are considered. Surely it is not really a precise comparison, but I was talking about significant overwhelming.

Well, adjectives always tend to be subjective, but I get what you're aiming at now. +1

This is just what I'm talking about and the purpose I've created the issue.

Yeah, I was kinda focusing on your initial point from the first post instead, but overall I agree with you on the later points, the latter case you provide is somewhat strange and there is certainly room for tweaking.