Adventure AI - plans and challenges

Way at the expense of the original heroes, I heard that there he sees the map immediately.

Current AI looks very stable. Just passed 13 months with 4 players without crash and no serious issues. I’d leave it as it is for next release. How about dev build soon?

Give it to me. And I’ll find you the error :smiley:

I try to handle spawning new objects on adventure map, especially week of double creatures. However, with the following code uncommented, game freezes for good after few objects have spawned. Probably threading issue.

void VCAI::newObject(const CGObjectInstance * obj)
{
	LOG_TRACE(logAi);
	NET_EVENT_HANDLER;
	if(obj->isVisitable())
		addVisitableObj(obj);

	//AI should reconsider strategy when spawning monsters block the way and free reserved objects

	//FIXME: AI tends to freeze forever on a week of double growth if this code is active 
	//auto safeCopy = reservedHeroesMap;
	//for (auto hero : safeCopy)
	//{
	//	auto h = hero.first;
	//	for (auto reservedObj : hero.second)
	//	{
	//		auto pos = reservedObj->visitablePos();
	//		if (!(isAccessibleForHero(pos, h) && isSafeToVisit(h, pos)))
	//		{
	//			erase_if_present (reservedObjs, reservedObj);
	//			for(auto &p : reservedHeroesMap)
	//				erase_if_present (p.second, reservedObj);
	//		}
	//	}
	//}
}

The code looks innocent enough. One possible reason for freeze might be if you request an action from callback when in the event handler function. But that doesn’t seem to be the case here.

Could you paste the stacktraces at the freeze moment?

To all testers: in order to effectively debug AI, you need to enable AI console output.

I uploaded mod “adventure AI trace” to our repository. It shuld help users to configure the console.

Oh my, I just figured out a serious issue. Actually, value returned by fuzzy engine is always the same for every type of input, regardless its value. Not sure for how long this issue has been around, but probably not from the very beginning.

Bad thing: It doesn’t work at all.
Good thing: AI can work much better once fixed.

That reminded me of another possible issue - this TODO note I made some time ago:
github.com/vcmi/vcmi/blob/maste … s.cpp#L161

In short this is status of victory/loss conditons in AI:

  • Some not implemented conditions, most notably “flag all objects of type” and “destroy all objects of type”.
  • AI will only try to complete first detected goal. That “for” loop iterates over all possible goals but only first one will be evaluated by AI.
  • Proper detection of human-specific victory/loss conditions and possibly AI-specific conditions (not applicable to H3 but already allowed in vcmi).

I can try to implement last one but first two I’d rather leave to somebody else.

Engine allows to consider multiple goal already, however many pieces are still missing.

For example, to get Grail, AI could consider all known Obelisks and pick the closest one. However, if the win condition is to “gather resources”, AI won’t benefit from it, since resources gathering (and saving) is somehwat simplified.

Got it. Seems that centroid algorithm fails is the positions of terms are too far away (even thoug they overlap). Rules must densily fill entire value range for it to work.

One question to Tow that bothers me recently:

Does function isAccessibleForHero return true for tiles that are guarded / blocked by removable objects?

No.
Function isAccessibleForHero relies on CGPathNode::reachable that returns true when the path between target and hero is fully cleared. So any removable (blockvis) objects, neutral monsters zone of control and similar obstacles will make map areas unreachable.
The only exceptions are monoliths, boats and subterranean gates — pathfinder is now smart enough to use them.

This is why VCAI has concept of Sector — set of tiles that would if reachable if guards/visitable objects would be passable.

Ahh, so that’s why AI gets lost sometimes and does not advance. Will need to find a way to implement it correctly.

Still, if AI is already quite effective, it will get really smooth once this severe issue is fixed :slight_smile:

Okay, it’s ready. I’m sure you will love new AI performance, especially on random maps :slight_smile:

An endless loop during AI turn. Just finish your turn and have fun.
Games.tar.gz (1.01 MB)

I have a proposal to “teach the AI ​​to” improve archers and elves to the software level.
No tears can not see when he runs from 40-50 not improved eg elves. And it would be healthy if he tried to improve in the second week of the game while playing vampires necropolis.
Raise the priority of these buildings were used very well.

Cool, but there is no “priority” at all. AI simply builds first building from the list each turn.

Currently my aim to to improve AI enough to clear Jebus. In fact, it already can succeed at this :slight_smile:

Will check.

Norms of output to the center by Jebus ~ 123, 124. AI now knows that too? :smiley: :smiley:

I played map on Android.
My hero went near enemy castle (there were no units left to buy in it). My hero was not strong (5 nixes and some low-level gang). Enemy hero near the castle altrough went by his business, And I took castle without fight.
This seems to be not realized branch of decision for enemy hero?

Is it so now?
I have a suggestion that AI must try to build buildings for shooters and high level monsters first. Even if AI is given lot of resources, he still will buy low level first (as I checked on Android game).