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.72k stars 376 forks source link

Battle: computer attacks me first and lose the battle #8206

Closed fheroes2bugs closed 6 months ago

fheroes2bugs commented 10 months ago

Preliminary checks

Describe the problem requiring a solution

My hero and computer hero have nearly equal army. But for unknown reason computer decides to attack me and ... he loses the battle. Here is red hero attacking my hero:

https://github.com/ihhub/fheroes2/assets/145407420/be9a6415-4ebc-4799-8357-9d9f30cd0ff8

Describe the possible solution

Computer should calculate his power more accurate, he must not attack enemy if he has equal power.

Additional info

Version 1.0.11 Save: suicide.zip

oleg-derevenetz commented 10 months ago

Computer should calculate his power more accurate, he must not attack enemy if he has equal power.

From an AI perspective, the power is not the same here because of the spells. Although the set of spells is comparable for both heroes, your hero has just one spell point, so he in fact is not able to cast battle spells, while AI hero has 55 spell points. AI in this case relied on spells and I must say he was close to victory. It is impossible to calculate everything with 100% accuracy.

fheroes2bugs commented 10 months ago

Computer should calculate his power more accurate, he must not attack enemy if he has equal power.

From an AI perspective, the power is not the same here because of the spells. Although the set of spells is comparable for both heroes, your hero has just one spell point, so he in fact is not able to cast battle spells, while AI hero has 55 spell points. AI in this case relied on spells and I must say he was close to victory. It is impossible to calculate everything with 100% accuracy.

Before attacking other heroes computer can do some "phantom fight" keep it in memory, and if result is not suitable (computer loses hero) then not to attack.

ihhub commented 10 months ago

Computer should calculate his power more accurate, he must not attack enemy if he has equal power.

From an AI perspective, the power is not the same here because of the spells. Although the set of spells is comparable for both heroes, your hero has just one spell point, so he in fact is not able to cast battle spells, while AI hero has 55 spell points. AI in this case relied on spells and I must say he was close to victory. It is impossible to calculate everything with 100% accuracy.

Before attacking other heroes computer can do some "phantom fight" keep it in memory, and if result is not suitable (computer loses hero) then not to attack.

That's called cheating.

oleg-derevenetz commented 10 months ago

That's called cheating.

And also it's costly and useless against a human player because the AI vs AI battle is conducted far from the manner in which a human player plays. If AI-controlled hero has defeated another AI-controlled hero, it does not mean at all that it will defeat the same hero, but controlled by a human.

fheroes2bugs commented 10 months ago

And also it's costly and useless against a human player because the AI vs AI battle is conducted far from in the same manner in which a human player plays. If AI-controlled hero has defeated another AI-controlled hero, it does not mean at all that it will defeat the same hero, but controlled by a human.

I'd say the opposite. At the moment, at the battle, computer (hero/neutral creatures) is very strong, I always get better result if I perform fast battle. There are some rare cases like #8182 or #7952 but they are very rare and you should be very experienced to remember it. So if computer wins computer, then he will win human too. If human is not using some smart spells like blind or berserk etc or using some known weakness like issues 8182 and 7952...

Aslo, if computer can see how much mana I have - isn't he cheating? Can't we perform cheating with "phantom fight" only for impossible diffuculty? I play the expert difficulty map with and impossible game difficulty and enemy just suicides me. There are not much ways to get AI more stronger and I see it is exactly suitable way.

oleg-derevenetz commented 10 months ago

So if computer wins computer, then he will win human too

According to my experience, AI plays far from my typical results. I'm always wondering when @Branikolog say that AI is "too smart" and should be nerfed for auto battles. AI can be easily distracted from approaching and blocking the archers, it cannot use some spells at all (like Teleport) or cannot use another spells that can win the battle by themselves (like Berserk) in a "good enough" manner, etc. Experienced human player just acts differently. Also, as I already said, performing the full battle is a very costly operation.

Branikolog commented 10 months ago

According to my experience, AI plays far from my typical results. I'm always wondering when @Branikolog say that AI is "too smart" and should be nerfed for auto battles. AI can be easily distracted from approaching and blocking the archers, it cannot use some spells at all (like Teleport) or cannot use another spells that can win the battle by themselves (like Berserk) in a "good enough" manner, etc. Experienced human player just acts differently. Also, as I already said, performing the full battle is a very costly operation.

According to my observations (streamers or even my own experience), instant battle AI proposes a really good battle outcome quite often, which players don't even expect to be achieved themselves and they gladly accept it. This is valid for me and quite skilled streamers (I consider us as above average players). If we speak about not so skilled player - he will use instant battle results in 80% of cases. Half a year ago I watched a speedrun of SW campaign, where the speedrunner managed to finish the whole campaign in about 1+ hour, where he played barely 10 manual battles. the rest was won by the instant battle AI. :)

zenseii commented 10 months ago

I'd like to add that the reason you can speed run or play with only instant battle results is because the AI's adventure map logic isn't on par with an average human player yet. If you play better on the adventure map, then you can safely accept the few extra losses from doing a battle in auto mode, compared to manually battling them out and getting fewer losses.

The main, or most influential, shortcomings of the battle AI, as far as I've experienced, are these:

  1. If threatened it will use spells on its first creature's turn instead of waiting until you've cast a spell to see if there's a better spell to cast, like casting Bless on a creature that will act after several others have gone - But, this is EXACTLY the way I see most human Heroes 2 players play too. I've lost count of how many times I've watched a human player cast Blind during the battle's first turn, only to be completely surprised by the AI dispelling it immediately the turn after.
  2. It will stand still and accept your barrage of lightning bolts thinking that the only way you can hurt it is with your few troops that it considers much weaker than its troops - Most human players will realize that they need to change their tactic in this case. This has been addressed.
  3. It doesn't make decisions thinking some battle rounds ahead - Most human players think at most one battle round ahead. Teaching the AI this is quite complex logic.
  4. Not avoiding to expose itself to multi-hex attacks and spells. - Most human players take this into account to some extent.

All in all though, for most players, these aren't bad decisions that will ultimately lead to the AI losing the game.

Instead, the adventure map shortcomings are much greater, and they are the main reason the AI can easily be beat, because if you play effectively on the adventure map then your army will be much greater than the AI's, to the extent that these suboptimal battle decisions are irrelevant. Most players struggle when the AI has a greater army.

oleg-derevenetz commented 10 months ago

It will stand still and accept your barrage of lightning bolts thinking that the only way you can hurt it is with your few troops that it considers much weaker than its troops

Well, actually, AI takes into account your attack spells as "shooters value" in addition to the value of your actual stacks of shooters, and this will influence its behavior, AI will go offensive if you have advantage in the shooters value even if you don't have any actual shooters, like in the last video from this comment:

https://github.com/ihhub/fheroes2/pull/8047#issuecomment-1867614686

However, there are always buts and ifs and corner cases, so...

zenseii commented 10 months ago

@oleg-derevenetz.

Well, actually, AI takes into account your attack spells as "shooters value"

Thanks for pointing that out! The AI has been evolving quicker than I'm able to keep track. This means that there are even fewer holes in the battle AI's tactics.

Nevertheless, I've also experienced being attacked by an AI player where the instant result showed them losing. Upon replaying that match and turning on AUTO, it showed that the AI lost because my troops got good morale and probably some good damage rolls.

This is nothing that needs to be fixed. I'm afraid the AI will become too defensive if we try to account for such possibilities when it is deciding whether to attack. These cases happen for human players too, but they have the luxury to reload and retry.

zenseii commented 10 months ago

Actually, looking at that battle again, I can see that one of the AI flaws I had forgot to mention - exposing itself to multi-hex attacks, had a significant impact on the outcome. I suppose the AI correctly estimated that it would win the battle, but during the battle it didn't avoid the double-hex attack from your phoenixes.

In other words, improving that logic of the AI is a better target than letting the AI cheat.

fheroes2bugs commented 10 months ago

I'm afraid the AI will become too defensive if we try to account for such possibilities when it is deciding whether to attack

You have main hero... will you attack enemy hero, that has the near equal army? Well, if it is map 1 on 1 or on map when only 2 players left... it can be done. But on map with 6 players when you attack strong enemy, your main forces will be destroyed and other 4 players will destroy you and computer you have attacked. There is no chance to win if you lose your whole army, and other 4 players didn't perform such an hasty move, isn't it?..

oleg-derevenetz commented 10 months ago

This is nothing that needs to be fixed.

If this is going to improve over time, it's unlikely by pre-playing battles. This is not only mega-expensive, but also impossible to cache. When comparing the calculated power of armies, you can firmly rely on the fact that the power of armies with which you have not interacted does not change on your turn, and you should only recalculate the power of your army and make a comparison with a pre-cached value of an enemy (or neutral) army. In the case of pre-played battles, you will have to conduct them again with any change in the power of your army, leveling up the hero, learning new spells, and so on, the results of early battles can no longer be relied upon. In short, this is hardly an option.

kitovyj commented 10 months ago

Please don't let AI cheat. It kills all the fun. That is what they did in Heroes V, AI never loses a battle there, they don't even perform a real battle against neutrals, just deducing the army size according to the estimated losses. That looks weird and feels boring.

fheroes2bugs commented 10 months ago

Please don't let AI cheat. It kills all the fun. That is what they did in Heroes V, AI never loses a battle there, they don't even perform a real battle against neutrals, just deducing the army size according to the estimated losses. That looks weird and feels boring.

What about make strong AI only for impossible diffuculty? Easy/normal/hard/expert could have fun with stupid AI that loses the battle and do other "fun" moves.

kitovyj commented 10 months ago

Please don't let AI cheat. It kills all the fun. That is what they did in Heroes V, AI never loses a battle there, they don't even perform a real battle against neutrals, just deducing the army size according to the estimated losses. That looks weird and feels boring.

What about make strong AI only for impossible diffuculty? Easy/normal/hard/expert could have fun with stupid AI that loses the battle and do other "fun" moves.

Sure, then let's just give AI 100k gold and 10 dragons at the beginning. Or maybe 10x monster health and +3 permanent luck? It's not that difficult to make the game hard to win. Making AI an interesting opponent is a different thing.

ihhub commented 6 months ago

This issue could have been fixed with the latest changes in AI defence logic and double hex creature behavior. I assume that Sprites would attack Phoenix rather than defending Grand Elves.

I am closing this issue as completed.