Passive AI units despite local superiority

Field of Glory II is a turn-based tactical game set during the Rise of Rome from 280 BC to 25 BC.
roguedjack
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Oct 18, 2017 1:40 pm

Passive AI units despite local superiority

Post by roguedjack »

Hi,

First many thanks for this great game at a very nice price. Happy customer here!

I'd like to report a problem I observed in several games with the AI. I provide a screenshot and the save.

The AI "piles up" a bunch of units on the front of my units but does nothing with them for several turns, even when I shoot at them. They seem stuck forever.
I can use few units to block a bunch of AI units. The AI should press its local advantage.
I noticed it happens on the flanks and near rough/difficult terrain.
It can involve more than one group of units (eg: not only a cavalry group or an infantry group, but a mix of units).

In the example I provide my roman cavalry group can hold a much larger gallic cavalry group of equal quality just by staring at them.
I moved my horse archer to ZOC them to provoke a reaction as nothing happened for several turns.
By contrast in the same flank the gallic infantry is chasing away my other cav unit. Maybe the cav units try to path through the rough terrain and decide against, doing nothing? It should at least try to chase away my harassing horse archer unit. They seem to have gone braindead.

In another case I managed to hold a block of 3x2 various inferior units with one legion just by ZOCing their 3 frontal units. Again the AI did nothing, neither engaging with 3 units vs 1 nor manoeuvring its extra 3 units to flank, while it had ample space and time to do that. It seems the has AI evaluated the invididual fights as losing and does not realize it can gang up on me.

If other players are having this problem, hope my report helps fixing it!
Attachments
idle gallic cavalry on my left
idle gallic cavalry on my left
Screen_00000000.jpg (858.31 KiB) Viewed 3392 times
8.zip
zipped saved game - the battle ends soon but wanted to make sure it had the bug for several turns
(117.82 KiB) Downloaded 77 times
Last edited by roguedjack on Wed Oct 18, 2017 2:50 pm, edited 1 time in total.
"Rise Of AI" AI mod for Field Of Glory II
http://www.slitherine.com/forum/viewtopic.php?f=477&t=102040
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

Thanks
Richard Bodley Scott

Image
Adraeth
Sergeant First Class - Panzer IIIL
Sergeant First Class - Panzer IIIL
Posts: 358
Joined: Mon Jun 29, 2009 8:19 am

Re: Passive AI units despite local superiority

Post by Adraeth »

to richard, maybe the rough ground on the blue cavalry right might be the reason?
Cumandante
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Wed Sep 29, 2010 5:53 pm

Re: Passive AI units despite local superiority

Post by Cumandante »

I have also noticed some "stuck" behavior from some AI units.
Sometimes, when a unit is surrounded by skirmishers, the AI will only turn, but never charge to escape.

On one occasion, I managed to lock down a superior armoured cav unit by placing it between 1 italian foot and a couple skirmisher units. The cav unit didn't charge any of my units, and only turned to face the italian foot. I then showered them with several turns of missile fire, always without response, until the unit broke. Apparently the AI didn't like its chances of winning the charge, but it was still clearly the lesser of two evils. Unfortunately I can't remember if the italian foot were in rough terrain.
stockwellpete
Field of Glory Moderator
Field of Glory Moderator
Posts: 14500
Joined: Fri Oct 01, 2010 2:50 pm

Re: Passive AI units despite local superiority

Post by stockwellpete »

Adraeth wrote:to richard, maybe the rough ground on the blue cavalry right might be the reason?
Yes, I think it probably is. Sometimes the AI is passive like this, other times it seems to be very deliberate and slow about doing something quite obvious (even occasionally missing flank attacks on enemy units that are already engaged. So I now find myself trying to help the AI in some situations. So in the example given, I wouldn't take advantage of the AI by firing with my skirmisher while my two units were holding up a bigger force, I would charge my cavalry in so as to cause the melee that should really be happening anyway. Most people playing Blue would engage the enemy with their first two units and then try and flank with the others.
stockwellpete
Field of Glory Moderator
Field of Glory Moderator
Posts: 14500
Joined: Fri Oct 01, 2010 2:50 pm

Re: Passive AI units despite local superiority

Post by stockwellpete »

Cumandante wrote:I have also noticed some "stuck" behavior from some AI units.
Sometimes, when a unit is surrounded by skirmishers, the AI will only turn, but never charge to escape.

On one occasion, I managed to lock down a superior armoured cav unit by placing it between 1 italian foot and a couple skirmisher units. The cav unit didn't charge any of my units, and only turned to face the italian foot. I then showered them with several turns of missile fire, always without response, until the unit broke. Apparently the AI didn't like its chances of winning the charge, but it was still clearly the lesser of two evils. Unfortunately I can't remember if the italian foot were in rough terrain.
We had this issue come up (and the one shown in the first post) in the beta and it is to do with the AI only assessing what is the best for the individual unit rather than being able to assess what might be best overall for the army if a unit was to take a certain course of action. So probably your Italian foot was on some sort of terrain, although steady Italian Foot would do OK against most cavalry. Most players, in the situation you are describing, would want to get the cavalry unit in melee somewhere to get away from the skirmishers.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

Adraeth wrote:to richard, maybe the rough ground on the blue cavalry right might be the reason?
I suspect so yes.
Richard Bodley Scott

Image
roguedjack
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Oct 18, 2017 1:40 pm

Re: Passive AI units despite local superiority

Post by roguedjack »

I think I found and fixed part of the problem in AI scripts, at least for a situation like the 2 gallic cav units in the zoc of my cavs not doing anything.
If I read and understood the AI code and logs correctly, here's what happened and how I presumably fixed it.
Be advised that the fix modifies the way the AI evaluates some charges, so it has far reaching consequences and might be a very bad idea in the overall scheme of things!
I think the AI code was intended to work like that, but I might be completly wrong!

What happened - short version:
The AI wrongly thinks its cavs can shoot at my cavs and reduce the chances of performing a slightly disadvantagous charge even more to give more chance to shooting them instead.
But as they cannot shoot, they end up doing nothing.

What happened - long version:
I enabled logs (the debuglog flag and f6) and added more logs to monitor how the AI evaluated its gallic cav units.
It evaluated the cav on cav charges as -3 giving a 4% only chance to charge.
In AI.tools here is the code in AI_ChanceOfCharging that I think wrongly triggers and kills its charge chance evaluation.

Code: Select all

// If unit has a shooting advantage which is greater than its close combat advantage (if any), it is much less likely to charge.
if (shootingMargin > closeCombatMargin)
{
	chargeChance /= 5;
}
It triggered for its gallic cav units targeting my roman cavs (shootMargin = 0 and closeCombatMargin = -3)
So this can triggers even if the AI unit has no shooting capability.
Because of this, the charge has a chance of 4% instead of 20% (the base chance for closeCombatMargin < 0).
Net effect is the AI will very rarely perform slightly loosing charges.
Bad charges (closeCombatMargin <= -25) triggers the same reduction and have 10/5=2% chance.

The change
I added a condition to test for missile capability. I think this is what the AI programmer intended.
To other users : don't do this, unless you know how to backup and restore game files!!

Code: Select all

// If unit has a shooting advantage which is greater than its close combat advantage (if any), it is much less likely to charge.
if (shootingMargin > closeCombatMargin && MaximumRange(me) > 0)
{
    chargeChance /= 5;
}
What happens after the change
In my case, it sometimes correctly charge or engage my cav units (20% chance).
It still does not do anything with its units next to my horse archer cav, but at least it makes use of the other ones more frequently.
"Rise Of AI" AI mod for Field Of Glory II
http://www.slitherine.com/forum/viewtopic.php?f=477&t=102040
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

Thanks for this analysis.

I think you are probably right about the issue and the correction.

I will look into it further.
Richard Bodley Scott

Image
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

This fix has been adopted for the second 1.0.2 patch. (It was too late to get into the first 1.0.1 patch build)

Note that the bug only made the chances of charging lower if the AI unit would be at a disadvantage and neither side had any shooting capability. Even without the bug the chances of charging will still be fairly low.

For example if the AI unit is Noble Cavalry, and the player unit is Armoured noble cavalry, the chances of the AI noble cavalry charging should be 20% but was reduced by the bug to 4% as per roguejack's situation.

Many thanks roguejack for discovering this flaw in my logic.
Richard Bodley Scott

Image
roguedjack
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Oct 18, 2017 1:40 pm

Re: Passive AI units despite local superiority

Post by roguedjack »

That's great! Glad i could help!
The AI is very enjoyable to play against by the way, many thanks for doing all this work on the AI.
"Rise Of AI" AI mod for Field Of Glory II
http://www.slitherine.com/forum/viewtopic.php?f=477&t=102040
roguedjack
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Oct 18, 2017 1:40 pm

Re: Passive AI units despite local superiority

Post by roguedjack »

Hi, it's me again!

I continue to investigate the AI and have a question about GetRouteCostUsingThreat.

Does ignoreUnit=1 on GetRouteCostUsingThreat means "ignore target, and if you cannot find a path, try again with ignoring friends".
The doc in BATTLESCRIPT.TXT only says "ignore target". To ignore all units you have to pass 2, as used in some places in the AI code.
I'm asking because routes with ignoreUnit=1 go through friends when it cannot reach the target directly. I tested this a lot and I am pretty sure of it.

This is what happens to the gallic cav on the back in my example. They tried to go straight through their friends to reach their target, that's why they didnt move at all.

For reference here is the code I used to test paths in MoveAIUnit

Code: Select all

					// we want to get a route to the target (taking threat into account) ignore the tile on the unit, we just want the best route.
					route = GetRouteCostUsingThreat(me, GetUnitX(target), GetUnitY(target), 0, 1, side);
					// RJ AI
					// TEST if route bumps immediatly into a friend. this should not happen since the flag is set to only ignore the target.
					// might be WAD though?
					if (GetCheckRouteLength() > 1)
					{
						i = GetUnitOnTile(GetCheckRouteX(1), GetCheckRouteY(1));
						if (i != -1 && i != me)
						{
							if (GetUnitSide(i) == side)
							{
								DebugLogX("!! route immediatly bumps into a friend -- me, routex, routey, blocker ", me, GetCheckRouteX(1), GetCheckRouteY(1), i);
							}
						}
					}
					// END RJ AI
Thanks for your time!
"Rise Of AI" AI mod for Field Of Glory II
http://www.slitherine.com/forum/viewtopic.php?f=477&t=102040
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

Thanks.

Essentially the engine routeing functions are imperfect in that they will not take much of a deviation to try to avoid units. If they can't find a route avoiding units without taking a significant deviation (I am not sure how far the algorithm is willing to deviate, since I am unable to look at the engine algorithms), they will just route through those units as if ignoreUnit == 2.

You are right that this is probably the cause of the problem.

I will ask the engine programmer if he can make a variant version that tries harder to route round units (if ignoreUnit != 2). I suspect he won't want to alter how the current function works in case it causes unexpected effects in other games.
Richard Bodley Scott

Image
roguedjack
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Oct 18, 2017 1:40 pm

Re: Passive AI units despite local superiority

Post by roguedjack »

That makes sense.

I'm testing a cheesy workaround by adding a moderate threat value in MakeThreatMap on tiles with friendly units to make the pathfinder avoid bumping into them. So far it works reasonably well and helps group of units manoeuvring around when close to the enemy.
"Rise Of AI" AI mod for Field Of Glory II
http://www.slitherine.com/forum/viewtopic.php?f=477&t=102040
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

roguedjack wrote:That makes sense.

I'm testing a cheesy workaround by adding a moderate threat value in MakeThreatMap on tiles with friendly units to make the pathfinder avoid bumping into them. So far it works reasonably well and helps group of units manoeuvring around when close to the enemy.
Well I would love to see it when you are happy it is as good as you can get it.
Richard Bodley Scott

Image
Cumandante
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Wed Sep 29, 2010 5:53 pm

Re: Passive AI units despite local superiority

Post by Cumandante »

I have another example of passive AI behavior:
engage.jpg
engage.jpg (889.71 KiB) Viewed 3029 times
That stalemate has lasted for at least 3 AI turns, with neither of us making a move. The AI has not attempted to flank (no flank bonus in that village) nor overpower my unit. Those 2 units at the back could be used to attack me somewhere else.
rbodleyscott
Field of Glory 2
Field of Glory 2
Posts: 28047
Joined: Sun Dec 04, 2005 6:25 pm

Re: Passive AI units despite local superiority

Post by rbodleyscott »

Cumandante wrote:I have another example of passive AI behavior:
engage.jpg
That stalemate has lasted for at least 3 AI turns, with neither of us making a move. The AI has not attempted to flank (no flank bonus in that village) nor overpower my unit. Those 2 units at the back could be used to attack me somewhere else.
Thanks. This is probably due to the same issues that roguedjack has identified.
Richard Bodley Scott

Image
roguedjack
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 127
Joined: Wed Oct 18, 2017 1:40 pm

Re: Passive AI units despite local superiority

Post by roguedjack »

Hi, some news. I'm sort of hijacking my own thread.
One AI code change leading to the other I basically ended up doing an AI mod.

About the "getting stuck" problem, I'm trying various stuff not just a threat map modification. But it is hard to get right, because sometimes you actually want the AI to stay behind other troops instead of going around them. Everything is hard to get even slightly right in fact :mrgreen:
I'm also doing different turn ordering, target selection and other stuff. For instance the AI will resolve melee dues on its own when it wants to, like the player can, instead of waiting for the end of the turn for autoresolve. It changes AI battle dynamics.

So I thought, if I can get an ok result, I'll made a copy of the Rise of Rome campaign with my custom AI in it. So people playing SP can try something different, still play MP safely and it doesnt mess the game files.

If/when I'm reasonably happy with version 1.0, how do I make the AI campaign available, post it in mods forum?
"Rise Of AI" AI mod for Field Of Glory II
http://www.slitherine.com/forum/viewtopic.php?f=477&t=102040
pipfromslitherine
Site Admin
Site Admin
Posts: 9706
Joined: Wed Mar 23, 2005 10:35 pm

Re: Passive AI units despite local superiority

Post by pipfromslitherine »

Generally you would post it so that forum-goers can kick it around. When it has had some testing you can let us know that you are happy if we want to add it to the official download list ingame.

Cheers

Pip
follow me on Twitter here
hjc
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 114
Joined: Mon Apr 30, 2012 6:05 am

Re: Passive AI units despite local superiority

Post by hjc »

This seems like it might be a thread where people know the answer: what is the maximum number of local variables that can be declared within a function? I've seen reference in scripts to not exceeding a maximum, re-using (with care!) variables due to this constraint.

Edit - never mind, I think the answer is 32.
Post Reply

Return to “Field of Glory II”