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.74k stars 377 forks source link

AI misuses wirlpools #8105

Open kitovyj opened 11 months ago

kitovyj commented 11 months ago

Preliminary checks

Platform

Windows

Describe the bug

Myra wants to attack Gem being just a few tiles away from her and uses a wirlpool instead of going around it. That is very suboptimal in this case.

Save file

uses wirlpool wrong way.zip

Additional info

No response

oleg-derevenetz commented 11 months ago

Technically the way through the Whirlpool is shorter - path through the Whirlpool takes ~700 movement points while path around the Whirlpool takes ~850 movement points, so, strictly speaking, this is not a bug. AI (in terms of pathfinding) always thinks that it will be lucky and it will always get into the right whirlpool, but this, of course, does not always happen. There are multiple ways to fix this, for example:

  1. Let AI "cheat" with Whirlpools, just like it now "cheating" with Summon Boat spell, but with the Summon Boat it's "microcheat", while here it would be "real cheat";
  2. Impose some AI-only penalties for Whirlpools.

Each of these have its own "pros" and "cons". For now, I will reclassify this issue as a request for improvement.

kitovyj commented 11 months ago

Technically the way through the Whirlpool is shorter - path through the Whirlpool takes ~700 movement points while path around the Whirlpool takes ~850 movement points, so, strictly speaking, this is not a bug. AI (in terms of pathfinding) always thinks that it will be lucky and it will always get into the right whirlpool, but this, of course, does not always happen. There are multiple ways to fix this, for example:

  1. Let AI "cheat" with Whirlpools, just like it now "cheating" with Summon Boat spell, but with the Summon Boat it's "microcheat", while here it would be "real cheat";
  2. Impose some AI-only penalties for Whirlpools.

Each of these have its own "pros" and "cons". For now, I will reclassify this issue as a request for improvement.

I think natural solution here would be a small penalty. This map contains 4 wirlpools and very often AI gets trapped trying to get correct exit, loosing time and army. At least definitely wirlpool should not be used if AI expects to get out of the same wirlpool - that will almost never work in terms of spending less movement points, even if there are only 2 wirlpools in the map.

oleg-derevenetz commented 11 months ago

Hi @kitovyj

At least definitely wirlpool should not be used if AI expects to get out of the same wirlpool - that will almost never work in terms of spending less movement points, even if there are only 2 wirlpools in the map.

On the contrary, it will always work when there are only 2 whirlpools on the map :) That's one of the reasons why the question with penalty is not so obvious.

kitovyj commented 11 months ago

Hi @kitovyj

At least definitely wirlpool should not be used if AI expects to get out of the same wirlpool - that will almost never work in terms of spending less movement points, even if there are only 2 wirlpools in the map.

On the contrary, it will always work when there are only 2 whirlpools on the map :) Really? But hero can get out at the same tile of the original wirlpool again? The tile he surfaces is random, right?

oleg-derevenetz commented 11 months ago

@kitovyj

Really? But hero can get out at the same tile of the original wirlpool again? The tile he surfaces is random, right?

No, it's not random. You can test this yourself :)

kitovyj commented 11 months ago

@kitovyj

Really? But hero can get out at the same tile of the original wirlpool again? The tile he surfaces is random, right?

No, it's not random. You can test this yourself :)

Ok) Anyway, using wirlpool to get to another side of the same wirlpool I would penalize. AI tries to do that really often and it looks quite weird.

kitovyj commented 11 months ago

@kitovyj

Really? But hero can get out at the same tile of the original wirlpool again? The tile he surfaces is random, right?

No, it's not random. You can test this yourself :)

In principle the penalty may depend on the amount of the wirlpools and the level of the creature the hero can potentially lose.

Branikolog commented 11 months ago

Hi, @kitovyj and @oleg-derevenetz I personally prefer AI cheating with whirlpools. Because human players do always cheat: reload if they lost some troops, use spacebar, while AI can't. If AI would jump to the destination point instantly, this would also shorten AI turn time so no more complains from players, that AI is looking like a "stuck" in whirlpools jumping for a long time.

oleg-derevenetz commented 11 months ago

this would also shorten AI turn time so no more complains from players, that AI is looking like a "stuck" in whirlpools jumping for a long time

8114 should help in this regard. This is also related not just to Whirlpools, but also to Stone Liths, which are also random in nature by design.

Branikolog commented 11 months ago

@oleg-derevenetz

https://github.com/ihhub/fheroes2/pull/8114 should help in this regard.

Absolutely yes, I'm aware of this useful improvement, you've done recently. 👍

This is also related not just to Whirlpools, but also to Stone Liths, which are also random in nature by design.

I personally consider Stone Liths operation mechanics as really of bad design: randomly jumping between stone liths to reach the needed one is really annoying. I've seen multiple times players just spending a minute or so to appear in the proper place. If I'm not mistaken we've discussed somewhere a future opportunity to allow a player to choose the exit of the liths he want. So implementing this for AI would be necessary too, if we come up with this improvement. In the future. :)

oleg-derevenetz commented 11 months ago

I personally consider Stone Liths operation mechanics as really of bad design: randomly jumping between stone liths to reach the needed one is really annoying.

Map creators can use this to limit or slow down the ability to attack or transfer reinforcements from one part of the map to another. At least for AI players :)

kitovyj commented 11 months ago

Hi, @kitovyj and @oleg-derevenetz I personally prefer AI cheating with whirlpools. Because human players do always cheat: reload if they lost some troops, use spacebar, while AI can't. If AI would jump to the destination point instantly, this would also shorten AI turn time so no more complains from players, that AI is looking like a "stuck" in whirlpools jumping for a long time.

No, please no cheating. It kills all the fun. I don't reload and I don't want AI to cheat. It's better to make it smarter rather than cheat.

oleg-derevenetz commented 11 months ago

No, please no cheating. It kills all the fun. I don't reload and I don't want AI to cheat. It's better to make it smarter rather than cheat.

If, nevertheless, a decision is made to implement the spacebar operation for AI (at the moment, there are concerns that this will break some maps), then it makes sense to implement this mechanics as an instantaneous movement to the desired endpoint, and in no other way.

FyiurAmron commented 10 months ago

TBH, how is it "cheating" if a player can do it? The fact that e.g. the AI in Heroes 2 didn't do something originally doesn't IMVHO make introducing that behaviour "a cheat". One can argue that the game mechanic interpretation assigned to the teleports by some players (i.e. that they should be "re-entered" and "re-exited" to trigger "without cheating") doesn't really make too much sense nowadays. If the teleports would be e.g. otherwise limited to a single random use per day - sure, that could be considered cheating, both by player (save-load) and AI (by allowing it the selection freely as described above).

That's not the case, however.

tl;dr what @Branikolog says about player UX is spot-on.

I personally consider Stone Liths operation mechanics as really of bad design: randomly jumping between stone liths to reach the needed one is really annoying. I've seen multiple times players just spending a minute or so to appear in the proper place. If I'm not mistaken we've discussed somewhere a future opportunity to allow a player to choose the exit of the liths he want.

I wouldn't go as far as to call this "cheating", though. It's not giving the AI additional 100k gold. It's not "free movement points". It's replicating the mechanics that humans use anyway - I haven't heard anyone in Heroes 3 call the "spacebar" trick "a cheat", after they introduced it in AB. 3DO did it for a good reason IMVHO: because it makes the game better.

Branikolog commented 10 months ago

I wouldn't go as far as to call this "cheating", though. It's not giving the AI additional 100k gold. It's not "free movement points". It's replicating the mechanics that humans use anyway

This goes without saying that allowing AI hero to appear in the needed place on his will would save a player a couple of moments watching those jumps through all the exits of whirpools/stone liths.

kitovyj commented 10 months ago

I have just realized that 'spacebar' doesn't eat move points. But that makes random exit point senseless. Shouldn't spacebar be not free in principle? Otherwise it is senseless.

FyiurAmron commented 10 months ago

@kitovyj it worked like that ever since it was introduced, because that's how NWC/3DO devs envisioned it. Whether or not it's senseless is obviously open to debate, but IMVHO it's the only workaround for not being able to select the exit directly that there is.