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.58k stars 359 forks source link

Battle: calculate which stack is the best for current battle #7945

Open fheroes2bugs opened 8 months ago

fheroes2bugs commented 8 months ago

Preliminary checks

Describe the problem requiring a solution

I am red player and I attack the purple hero. I have 12 green dragons, but in situation where all dragons are in 1 stack I win:

https://github.com/ihhub/fheroes2/assets/145407420/762d2d2c-e3bd-4f4b-874a-09fe5d1a25da

And in situation where dragons are in equal stack, I lose:

https://github.com/ihhub/fheroes2/assets/145407420/ad68be89-2282-4910-8053-025bdd5756fe

Well that is just the mechanics of the game, but if we give control to computer, before attacking that purple player, will he do equal stacks or in 1 stack? Can not try it by my own, but I am sure, that computer does not calculate variations of stacks.

Describe the possible solution

Before attacking the orher hero, AI should calculate which combination is the best for the current battle. For example, to get a starting point, calculate 2 situations:

  1. All creatures in 1 stack
  2. All creatures in equal stacks.

Additional info

version 1.09

save: 1 stack or 5.zip

fheroes2bugs commented 8 months ago

Another example:

Before the battle centaurs could divede by 2 stacks, so they would deal maximum damage and kill 1 archimage or my centaurs. If they are divided by 5 stacks, they deal 0 damage (in dead units).

https://github.com/ihhub/fheroes2/assets/145407420/333a5d3a-f700-4af3-a772-6a15177e83cc

PS - may be, this "before battle calculations" should be done only for hard/expert difficulty.

version 1.09 save: stacks of centaurs.zip

ihhub commented 8 months ago

Hi @idshibanov , I believe we need to add an extra value for killing monsters that are going to make their move during current turn, while calculating an outcome for an AI monster attack.

oleg-derevenetz commented 8 months ago

Before the battle centaurs could divede by 2 stacks, so they would deal maximum damage and kill 1 archimage or my centaurs. If they are divided by 5 stacks, they deal 0 damage (in dead units).

Battle formations of neutral armies (as well as object guardians) are fixed and never depend on who they are fighting, but only on the tile on which they are located. This is how it works in the original game. It is unlikely that this will change.

fheroes2bugs commented 8 months ago

Before the battle centaurs could divede by 2 stacks, so they would deal maximum damage and kill 1 archimage or my centaurs. If they are divided by 5 stacks, they deal 0 damage (in dead units).

Battle formations of neutral armies (as well as object guardians) are fixed and never depend on who they are fighting, but only on the tile on which they are located. This is how it works in the original game. It is unlikely that this will change.

In heroes3 monsters can divide to deal maximum damage, so in heroes 2 it looks like not working as it should. Isn't the aim to do the maximum hard AI? In adventure map, at the moment, AI just calculates the priority of object to visit/attack it or not, it would be hard to fix the whole logic of adventure map... But to do battles harder is easily achievable, so if not adventure map, then may be to do battles harder for player...

oleg-derevenetz commented 8 months ago

In heroes3 monsters can divide to deal maximum damage, so in heroes 2 it looks like not working as it should.

In HoMM IV, the fog of war does not work the same way as in HoMM2 or HoMM3, but this does not mean that in HoMM2/3 it "doesn't work as it should".

In adventure map, at the moment, AI just calculates the priority of object to visit/attack it or not, it would be hard to fix the whole logic of adventure map...

What do you mean by "fix"?

But to do battles harder is easily achievable, so if not adventure map, then may be to do battles harder for player...

What do you mean by "easily achievable"?

fheroes2bugs commented 8 months ago

In HoMM IV, the fog of war does not work the same way as in HoMM2 or HoMM3, but this does not mean that in HoMM2/3 it "doesn't work as it should".

If AI in HOMM IV or HOMM V would be stronger then in heroes 2/3 then we could borrow the logic from it to create stronger AI. The "impossible" level should be "impossible" not caused by difference in resources, but caused by lack of skill by human player.

What do you mean by "fix"?

I mean, all the issues with adventure map, like #7774 #7775 #7773 when computer calculates the objects, but not calculating will the visiting object bring him win faster or it is useless for win.

What do you mean by "easily achievable"?

I mean, in my opinion, make computer stronger in battle is more easy, then rework the logic in adventure map for stronger AI.

oleg-derevenetz commented 8 months ago

but not calculating will the visiting object bring him win faster or it is useless for win.

These are just general words about nothing.

I mean, in my opinion, make computer stronger in battle is more easy, then rework the logic in adventure map for stronger AI.

To have an opinion, you need to have an understanding of how exactly AI works now, and why it works the way it does. Then, when specific idea appear, it will be possible for you to offer a working proof-of-concept, on the basis of which it is possible to demonstrate some new approach, as well as what advantages it brings, and give an opportunity to evaluate its disadvantages. For now, general words about "fix" and "easily achievable" are nothing but just words.

fheroes2bugs commented 8 months ago

I mean, in my opinion, make computer stronger in battle is more easy, then rework the logic in adventure map for stronger AI.

Said this because of #7773 where computer could defeat me in 1 turn, but used to walk around, do nothing and don't defeat me (computer had much stronger army)

To have an opinion, you need to have an understanding of how exactly AI works now, and why it works the way it does. Then, when specific idea appear, it will be possible for you to offer a working proof-of-concept, on the basis of which it is possible to demonstrate some new approach, as well as what advantages it brings, and give an opportunity to evaluate its disadvantages. For now, general words about "fix" and "easily achievable" are nothing but just words.

Yes, I don't know the code at the moment, but soon will learn a bit more C++ and hope could help the project.