Ai turns

I optimized most expensive function in r3834. Apparently pathfinder was crippled by recalculating hero bonuses for every tile.

Huh… such cases should be covered bonus system caching. Wasn’t it working at all or was it just too slow?

Well, actually getting catched bonus was the function that caused significant CPU usage. Reading catched string is of course faster than navigating bonus tree, but still can take time if called thousands of times. Streams are slow.

I found another bottleneck specific to water-based maps only. Fixed in r3830.

Is it possible to change the enemy movement speed?

In the in-game settings menu there is an option, to change your own movement speed, but the movement speed for the enemy is disabled.

Additionally in Heroes II is an option the change the whole ai speed.

This option works for AI heroes as well.

Okay, are you happy with AI speed in 0.95b?

Nope. In case AI generates a lot of heroes with 1-4 creatures on a small area, it produces a lot of warnings like: Another allied hero stands in our way
and it becomes extremely slow. Makes me annoyed.

But this is exactly how it worked since 0.95 and no one reported such issue.

The AI is much faster than in previous version and this is definitely noticeable. But there is one thing that really bother me - heroes which belong to different players don’t fight each other.

+1 for Kantor
About AI, it definitely became better, but it becomes very slow in such cases I’ve described.
In scenarios where you play with Gelu everything is ok, in scenarios where you play with Sandro the area is quite limited and it becomes such a pain to wait 5-6 mins for 1 turn.

not quite
forum.vcmi.eu/download.php?id=660

I also noticed it. Even if my hero is much weaker, AI heroes pay no attention to mine hero and don’t kill him on map. And enemy heroes don’t recapture mines and dwellings taken from AI by me.

@ Warmonger: I’ve got one suggestion about AI turns:
sometimes there is a situation when a hero is blocked on one cell, he can’t move anywhere (for example due to scenario he is blocked and we need to free him), but he still eats some time trying to evaluate what to do - about 15-20 seconds, not that much, but a simple if-else condition for such situations can help to reduce this time, nice profit, little changes in the code :wink:

For example, right now he did 11 evaluations, changed goal and finished his turn without doing anything.

Hmmm, well, in fact i have this problem, too. I’m trying the RoE campaign, first scenario. The first AI turn now runs for about 1 hour, and it is still not ready. That is indeed way too long.

My PC is a laptop, a samsung R70. It is not the strongest, but should be well powerfull enough. As far as i have read in the log from previous tries it is as Warmonger said: 2 heroes meeting causes some endless loop.

I too tried the vcmi test map. AI turn still took quite some time, but it was only minutes, not hours.

Map size cannot be the problem. The first RoE scenario has a quite small map.

Recalculation: I doubt if it is really necessary to recalculate goals on every tile. It should be enough to once per round calculate all goals within sight and then simply move there. This does not change any conditions. Any tile visited should not change any game state until the hero reaches his final point. Map/game conditions may change during the next turn, so it is necessary to reevaluate any goals then, but it should not be necessary to reevaluate them each turn

I’ll give it a try during night. We’ll see if it is an endless loop or if it just takes too long. If it’s still busy tomorrow than it is probably an endless loop.

BTW, is there a “cheat code” to reveal the map? Seeing what the AI does might help finding out what exactly takes that long.

Yes there is
wiki.vcmi.eu/index.php?title=Cheat_codes

Thanks for the reply. I’ll try it in a few minutes.

I’ve let it run through the whole night. No end. So it seems to be an endless loop.

Well, it is not that easy to read, but it seems to be some kind of enless loop indeed. So what i observed: The tan hero moved into its home town (Terraneus) and then got stuck there. Here are some parts of the log:

17:25:01 DEBUG ai [7fb8cf7fd700] - Moving hero Xyron to tile 33 35 1
17:25:01 TRACE network [7fb8cf7fd700] - Sending a request “8MoveHero”. It’ll have an ID=61.
17:25:01 TRACE network [7fb8cf7fd700] - Sending to server a pack of type 8MoveHero
17:25:01 TRACE global [7fb8cf7fd700] - We’ll wait till request 61 is answered.

17:25:01 TRACE network [7fb8cd7f9700] - received server message of type 13PlayerBlocked, data: {CPack: type ‘96’}
17:25:01 TRACE network [7fb8cd7f9700] - Made first apply on cl
17:25:01 TRACE network [7fb8cd7f9700] - Applied on gs
17:25:01 TRACE ai [7fb8cd7f9700] - Entering virtual void VCAI::playerBlocked(int, bool): reason ‘1’, start ‘1’.
17:25:01 TRACE ai [7fb8cd7f9700] - Leaving virtual void VCAI::playerBlocked(int, bool).

That moved Xyron to the entrance field of the town.

…]
17:25:02 TRACE ai [7fb8cd7f9700] - Entering virtual void VCAI::heroMoved(const TryMoveHero&).
17:25:02 TRACE ai [7fb8cd7f9700] - Leaving virtual void VCAI::heroMoved(const TryMoveHero&).
17:25:02 TRACE network [7fb8cd7f9700] - Made second apply on cl
17:25:02 TRACE network [7fb8cd7f9700] - Listening…
17:25:02 TRACE network [7fb8cd7f9700] - received server message of type 9HeroVisit, data: {CPack: type ‘1’}
17:25:02 TRACE network [7fb8cd7f9700] - Made first apply on cl
17:25:02 TRACE network [7fb8cd7f9700] - Applied on gs
17:25:02 TRACE ai [7fb8cd7f9700] - Entering virtual void VCAI::heroVisit(const CGHeroInstance*, const CGObjectInstance*, bool): start ‘1’; obj ‘Terraneus, Dungeon’.
17:25:02 TRACE ai [7fb8cd7f9700] - Completing goal: FIND OBJ 1454 (Xyron)
17:25:02 TRACE ai [7fb8cd7f9700] - Leaving virtual void VCAI::heroVisit(const CGHeroInstance*, const CGObjectInstance*, bool).
…]
17:25:02 TRACE ai [7fb8cd7f9700] - Entering virtual void VCAI::heroVisitsTown(const CGHeroInstance*, const CGTownInstance*).
17:25:02 TRACE ai [7fb8cd7f9700] - Leaving virtual void VCAI::heroVisitsTown(const CGHeroInstance*, const CGTownInstance*).

Here obviously the first goal is done.

…]
17:25:02 TRACE ai [7fb8cf7fd700] - Entering void VCAI::performObjectInteraction(const CGObjectInstance*, HeroPtr): Hero Xyron and object Terraneus, Dungeon at 35 35 1.
17:25:02 TRACE ai [7fb8cf7fd700] - Completing goal: FIND OBJ 1454 (Xyron)
17:25:02 TRACE ai [7fb8cf7fd700] - Leaving void VCAI::performObjectInteraction(const CGObjectInstance*, HeroPtr).
17:25:02 TRACE ai [7fb8cf7fd700] - Completing goal: VISIT TILE (33 35 1) (Xyron)
17:25:02 DEBUG ai [7fb8cf7fd700] - Hero Xyron moved from 33 36 1 to 33 35 1. Returning 1.
17:25:02 TRACE ai [7fb8cf7fd700] - Completing goal: VISIT TILE (33 35 1) (Xyron)
17:25:02 DEBUG ai [7fb8cf7fd700] - Hero Xyron visited tile (33 35 1)

O.k., now Xyron did some interaction in Terraneus. Done.
Now the interesting part:

17:25:02 DEBUG ai [7fb8cf7fd700] - Striving to goal of type WIN
17:25:02 DEBUG ai [7fb8cf7fd700] - Considering goal WIN
17:25:02 DEBUG ai [7fb8cf7fd700] - Considering goal FIND OBJ 1454
17:25:02 DEBUG ai [7fb8cf7fd700] - Considering goal VISIT TILE (33 35 1)

Again? Xyron is already at tile 33 35 1.

…]
17:25:02 TRACE ai [7fb8cd7f9700] - Entering virtual void VCAI::requestRealized(PackageApplied*).
17:25:02 TRACE ai [7fb8cd7f9700] - Leaving virtual void VCAI::requestRealized(PackageApplied*).
17:25:02 TRACE network [7fb8cd7f9700] - Made second apply on cl
17:25:02 TRACE network [7fb8cd7f9700] - Listening…
17:25:02 DEBUG ai [7fb8cf7fd700] - Trying to realize VISIT TILE (33 35 1) (Xyron) (value 2.679)

This seems to be the start of the endless loop

…]
17:25:02 TRACE ai [7fb8cd7f9700] - Entering virtual void VCAI::requestRealized(PackageApplied*).
17:25:02 TRACE ai [7fb8cd7f9700] - Leaving virtual void VCAI::requestRealized(PackageApplied*).
17:25:02 TRACE network [7fb8cd7f9700] - Made second apply on cl
17:25:02 TRACE network [7fb8cd7f9700] - Listening…
17:25:02 DEBUG ai [7fb8cf7fd700] - Moving hero Xyron to tile 33 35 1
…]
17:25:02 TRACE ai [7fb8cf7fd700] - Entering void VCAI::performObjectInteraction(const CGObjectInstance*, HeroPtr): Hero Xyron and object Terraneus, Dungeon at 35 35 1.
17:25:02 TRACE ai [7fb8cf7fd700] - Completing goal: FIND OBJ 1454 (Xyron)
17:25:02 TRACE ai [7fb8cf7fd700] - Leaving void VCAI::performObjectInteraction(const CGObjectInstance*, HeroPtr).
17:25:02 TRACE ai [7fb8cf7fd700] - Completing goal: VISIT TILE (33 35 1) (Xyron)
17:25:02 DEBUG ai [7fb8cf7fd700] - Hero Xyron moved from 33 35 1 to 33 35 1. Returning 1.
17:25:02 TRACE ai [7fb8cf7fd700] - Completing goal: VISIT TILE (33 35 1) (Xyron)
17:25:02 DEBUG ai [7fb8cf7fd700] - Hero Xyron visited tile (33 35 1)
17:25:02 DEBUG ai [7fb8cf7fd700] - Striving to goal of type WIN
17:25:02 DEBUG ai [7fb8cf7fd700] - Considering goal WIN
17:25:02 DEBUG ai [7fb8cf7fd700] - Considering goal FIND OBJ 1454
17:25:02 DEBUG ai [7fb8cf7fd700] - Considering goal VISIT TILE (33 35 1)
…]

And then again and again.

I do not know what kind of interaction Xyron is doing here, but either he is doing it over and over again or there are thousands of interactions to be done in this town. This never ends.

I hope this might help. BTW, at least here it is always (100%) this way. So you might find the exactly same behaviour if you try it yourself. The map is the first scenario in the “good” RoE campaign. My computer is a Samsung R70 laptop, and my OS is Ubuntu 14 (current latest version).

Regards (and good luck)
Siegfried