Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI strange behavior : a hero leaves the castle and goes back #7565

Open
2 tasks done
kitovyj opened this issue Aug 17, 2023 · 8 comments
Open
2 tasks done

AI strange behavior : a hero leaves the castle and goes back #7565

kitovyj opened this issue Aug 17, 2023 · 8 comments
Labels
AI Artificial intelligence behaviour improvement New feature, request or improvement

Comments

@kitovyj
Copy link

kitovyj commented Aug 17, 2023

Preliminary checks

Platform

Windows

Describe the bug

AI strange behavior : green hero Atlas leaves the castle and goes back. All fog should be long time discovered by the moment. Please note also strange behaviour of red hero Kilburn - his fog also should be discovered at that point. The second save shows similar situation - this time Atlas leaves its castle to visit Demon cave that is long time empty and I bet he should know it.

Save file

does-nothing.zip
demonhole.zip

Additional info

No response

@kitovyj kitovyj added the bug Something doesn't work label Aug 17, 2023
@oleg-derevenetz
Copy link
Collaborator

oleg-derevenetz commented Aug 18, 2023

green hero Atlas leaves the castle and goes back

Atlas attacks Vampires for experience. There is nothing strange in this behavior.

Please note also strange behaviour of red hero Kilburn - his fog also should be discovered at that point.

But it's not (at least, not enough). He goes to take the ore mine near the Hillstone, but then he sees the Dawn with decent army and decides that his castle is in danger.

Atlas leaves its castle to visit Demon cave that is long time empty and I bet he should know it.

That's not really the case. Atlas leaves his castle to try to capture Blackburn, and his path is just paved through the empty Demon Cave. But visiting this object (in fact, any object) forces him to stop and re-assess his targets, and he decides to go back to his castle.

@kitovyj
Copy link
Author

kitovyj commented Aug 18, 2023

green hero Atlas leaves the castle and goes back

Atlas attacks Vampires for experience. There is nothing strange in this behavior.

I see! Somehow I missed that there is Vampires stack there.

Please note also strange behaviour of red hero Kilburn - his fog also should be discovered at that point.

But it's not (at least, not enough). He goes to take the ore mine near the Hillstone, but then he sees the Dawn with decent army and decides that his castle is in danger.

Got it!

Atlas leaves its castle to visit Demon cave that is long time empty and I bet he should know it.

That's not really the case. Atlas leaves his castle to try to capture Blackburn, and his path is just paved through the empty Demon Cave. But visiting this object (in fact, any object) forces him to stop and re-assess his targets, and he decides to go back to his castle.

Thank you for the clarifications. In general, maybe it's possible to make AI not recalculate priorities if the game state remains unchanged after the event: declined demon cave used just for a passage, text message event, event deducing resources when there is nothing to deduce, passing through a well having already maximum spell points, passing through the observartion tower visited before etc. Otherwise it creates an impression that AI visits the same object multiple times, going to it and then returning back to defend the castle. Also it would save some processor time.

@oleg-derevenetz
Copy link
Collaborator

if the game state remains unchanged

In fact, the state of the game does not remain unchanged - hero is in a different place now, so the distances between him and other objects on the map have changed, and the evaluation of objects is always scaled depending on the distance from the hero to these objects, for some objects their value decreases slower with the distance to them, and for some objects their value decreases faster. Evaluating an object is a bit complicated.

@kitovyj
Copy link
Author

kitovyj commented Aug 18, 2023

if the game state remains unchanged

In fact, the state of the game does not remain unchanged - hero is in a different place now, so the distances between him and other objects on the map have changed, and the evaluation of objects is always scaled depending on the distance from the hero to these objects, for some objects their value decreases slower with the distance to them, and for some objects their value decreases faster. Evaluating an object is a bit complicated.

Yes, I saw that non-linear distance penalty. In principle, we can imagine a situation when a hero made just one step outside a castle returns back if we force recalculation for some reason. But the "ideal" target choosing algorithm should be invariant to the hero position until the hero still on the originally selected path to the target. I think the omission of the unnecessary prority recalculation can at least improve the current "non-ideal" solver.

@kitovyj
Copy link
Author

kitovyj commented Aug 18, 2023

if the game state remains unchanged

In fact, the state of the game does not remain unchanged - hero is in a different place now, so the distances between him and other objects on the map have changed, and the evaluation of objects is always scaled depending on the distance from the hero to these objects, for some objects their value decreases slower with the distance to them, and for some objects their value decreases faster. Evaluating an object is a bit complicated.

What if we interpret distance as "pathLength - heroMovePointsRemaining". Then that factor becomes invariant till the hero is on the path during the same turn. Recalculation then should not change the target (at least due to distance change, the castle defense factor of course would still play a role...).

@oleg-derevenetz
Copy link
Collaborator

oleg-derevenetz commented Aug 18, 2023

What if we interpret distance as "pathLength - heroMovePointsRemaining". Then that factor becomes invariant till the hero is on the path during the same turn. Recalculation then should not change the target.

There is no recalculation while the hero moves. But when he interacts with an "action object", he automatically stops and then recalculates his targets, because during such an interaction his army can decrease (due to a battle) or increase (due to hiring new creatures), he can get additional stats, additional mana, and so on. The path he takes can pass right through objects (it doesn't matter if they are empty or not), through wandering monsters or even enemy heroes - as long as the AI pathfinder believes that this hero is strong enough for this. There are many different parameters besides distance alone. If the hero went to a guarded enemy castle through an object/monsters/hero that he should go through with a fight (and win according to the pathfinder estimation), but if the fight was in fact not so successful, and the hero lost too much army, then there may not be any point in going to this castle at all, but maybe there is some another castle (a little less developed and a little further away but worse guarded), then the target can be changed to that castle. Here we can either come up with some other evaluation method or make sure that the hero does not stop at empty objects, which looks more like a temporary patch, rather than a normal solution.

@drevoborod
Copy link
Contributor

drevoborod commented Aug 19, 2023

Seems like the hero returned to the castle from daemon's cave because AI "thinks" that there is some threat close enough to the caslte, right? And if the hero would continue moving, he would be too far to protect it? The question is: why the AI couldn't predict it before he sent the hero outside of the castle? I mean that if there was no Daemon cave which forced the AI to recalculate threats, he could make wrong decision by sending hero somewhere when he was needed to protect the castle. So seems like it could be better if AI could predict changing of situation for every position of planned hero's move (during one turn, of course, when no external curcumstances were changed). Of course, it should be more resource-consuming, but who cares? :) At the time AI "thinking" is extremely fast even on my ancient low-end tablet, so we have some power reserve.

@oleg-derevenetz
Copy link
Collaborator

In fact, this issue does not contain any bugs, but boils down to a vague wish for more efficient AI functioning without any specific technical proposals. It is difficult to regard this even as a request for improvement, but for now let's reclassify it this way.

@oleg-derevenetz oleg-derevenetz added improvement New feature, request or improvement AI Artificial intelligence behaviour and removed bug Something doesn't work labels Aug 20, 2023
@oleg-derevenetz oleg-derevenetz added this to the Beyond OG scope milestone Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI Artificial intelligence behaviour improvement New feature, request or improvement
Projects
None yet
Development

No branches or pull requests

3 participants