Serious AI Bugs

Warhammer 40,000: Gladius Relics of War brings you to a world of terror and violence. Four factions will engage in a brutal war for dominance over the planets resources.
Post Reply
Me1andMe2
Private First Class - Opel Blitz
Private First Class - Opel Blitz
Posts: 1
Joined: Fri Jul 27, 2018 1:37 pm

Serious AI Bugs

Post by Me1andMe2 »

After having same FFA with the AI i was pretty disappointed by how bad it performed. Since in 1v1 it acts kinda competent I decided to investigate why the FFA experience is so bad. So I put some Ais on the map and watched them. Here are some things that I found:

1)The AI blocks itself ( in advance: I cant prove this but the results pretty much point to this)
I think you all saw the AI “dance” where it moves some of its units back and some forth. At first I though it was pulling it units back to heal but upon close inspection I noticed that often this is not the case as full hp units were pulled back. I also noticed that it got worse the bigger its army grew so I watcher closer and I think I figured out what is happening. The AI moves its units back so that it can use all of it’s units in a meaningful way. Let me explain

The steps are pretty easy:
1. There is a unit the ai wants to attack
2. It(the AI) sees it has units in range
3. It fills the squares in front of the unit with its units (there is already an issue here we will come back later to this)
4. Units that are not in range of attacking and have no other target either move up or stand still
5. It attacks the unit. (so far so good)
6. Next Turn (The target unit is still alive)
7. It wants to attack the unit again
8. It sees it has units in range
9. It sees the squares that enable some units to attack the target is blocked by its own troops
10. It moves the units back to make place for the other units to attack the target
11. and so on

This means this will get worse and worse the more units the AI has and the smaller/inaccessible the target I. I have seen the AI taking more than 60 turns to defeat a city located at the coast that had no defenders except the units it produced while the other AI had a full army(including baneblades). A human player could have taken the city in 5 turns max.

Solution: Don’t retreat units that are blocking your units but instead advance them and the Ai needs to learn how to properly surround

2)The AI has a unit cap
Pretty simple even with ample resources stored and a good income the ai will stop producing units after is has a certain amount.
This is one of the reason why the AI with bigger cheats perform even worse in FFA. Both will reach the cap and this will result in a stalemate

Solution: No unit cap for AI

3)The AI doesn’t use Loyalty Buildings to improve it resources
pretty disappointed as this is a pure math related thing and that’s one thing that AI should be good at.
When your city starts pumping out 100+ resources it should realize that 6 loyalty gives 12+ resources(which is the same resource to energy ratio other building have) while also giving production.

Solution: Add Loyalty resource gain into consideration instead of only avoiding negative loyalty

4)The AI doesn’t settles if enemies are close
There seems to be a check that the AI cant settle if enemies are close.
Had a situation where 1 AI was sitting at only 2 cities despite having an abundance of resources(2000+ of all of them). They were in a fight with an AI city that was fairly close. After they destroyed the city (no other units where left) the AI settled 3 cities simultaneously.
Another problem seems to be that the AI doesn’t send its settlers into directions where there are no enemies. The settlers will always follow its armies and therefore quickly end up with enemies it its vicinity and stop expanding.

Quick example: AI A is in the lower left corne B in the lower right. After discovering each other they will send their troops in the fastest way possible to each other bases quickly filling its way with troops which will cause the to stop expanding especially if the distance is short. However all of the north half of the map would be save to expand though but the AI will ignore it.

Solution: Put in proper risk evaluation for placing cities and give the ai the ability to expand into directions that it currently has no units in but explored.

5)AI can deadlock itself
Granted I only saw this happen one time but the AI managed to get negative energy and exactly 0 ore and food income but 400 in the bank. The AI just stopped and did nothing for the next 30 turns after which it got killed.

Solution: Building something at ½ should be considered better than building nothing and being stuck


I hope this helps and maybe in the future we can have some ffa’s that are as good as the rest of the game :3.
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

I agree that as of now for a somewhat experienced player who know's what they are doing, the default-game-mode, FFA, is basically unloseable regardless of difficulty because of the many shortcomings of the AI.
It didn't seem so bad when I first started but the more I know about the game the worse the AI appears in comparison.

So as an AI-enthusiast I have been thinking a lot about what the AI does wrong and how it could be improved.

Your post is some really great input. Especially the first point, which I also noticed but never have been able to track down what is the apparant reason for that weird behavior where the AI retreats units from the frontline with apparently no reason.

I'd like to comment on your points and give some input from my perspective and then add some points on my own. This will be a long post.

1)
When fixing that shuffling would be as easy as to prevent that vacating of spaces that other units can use unless the units standing on them are actually severely hurt, this would be a great way to improve combat-performance easily. But long term I'd like to see a complete revamp of how the AI uses their units in combat.

I can propose an algorithm for that.
The whole proceudre should be split into several phases and for each phase there should be a priority-list in which order the units execute them.

1. Retreat-phase. In this phase the AI should retreat damaged units behind the frontline. Ideally towards units that have the ability to heal them or towards outposts. I'm not entirealy sure how to determine whether a unit is qualified for retreating or should stay on the frontline as slightly damaged units should obviously stay while heavily damaged ones should run. The threshold here is debatable.

2. Positioning-phase. In this phase each unit should strife for a position that allows them to attack as many potential targets as possible. The important thing here is the order in which this should be executed. Units with shorter range and a better "tankyness" should be prioritized before units with longer range and those more squishy. If stats are similar then units with better mobility (overall reachable tiles) should move before units with lower mobility as those moving first then can vacate tiles and allow more mobility to the others. Units who's weapons have the trait that they lose accuracy when they move should obviously skip this phase when they already have targets in range. Same for support-units. I'd grant them a separate phase.

3. Support-phase. Units which are supporters, like Painboys, Enginseers and Crypteks shouldn't have moved yet. They should act now. Determine which of their support-abilities is best and pick a target they can reach and use it on. They should usually walk up to a unit that retreated during retreat-phase and heal them.

4. Attack-phase. Once again ordering here is the most important thing to not waste any damage. Units that have fewer possible targets should act first for obvious reasons. Regardless of their range. For units with the same target-count the ones which have blast-effects on their weapons should go first. Units that have several possible targets should of course prioritize dealing killing blows and if no killing-blow can be dealt simply do whatever does most damage multiplied by cost of the target as dealing the same damage to a more costly unit is more valuable. When several killing-blows are possible then the more expensive unit should be prefered of course.
Units that have a multitude of attack-options, like the C'Than for example should of course use the attack/target-combination that is most efficient in the terms discussed before. This also means not wasting a cooldown if a killing-blow can be achieved without.

I think with this revamp of the AI's tactical phase it could vastly increase their overall damage-output with the same units.

2)
If what you say about the unit-cap is true, then this is extremely laughable and should be immediately changed! But it actually would explain why in these FFAs almost never someone seems to snowball out of control. I mean I can see other possible reasons for that too but this clearly might be one of them.
Not much else to say to this point.

3)
Exactly that. I've posted a formula before of how you can determine whether a Loyalty-building is more effective at the current-loyalty-value than any of the other buildings. And as you say: AI only builds loyalty when it is below 0 and not according to when math suggests it should.

Here's my post on that:

I did some math on when it's better to go for Loyalty vs. making other buildings.
The obvious first: The lower the loyalty the more useful loyalty is and the higher loyalty the more usefull are non-loyalty-buildings
However, as soon as you have 18 non-loyalty-buildings loyalty always is better unless you hit the cap of 50.
To figure it out for your current building-count and loyalty you do the following math:
non-loyalty-building-count * (loyalty + 56)/50 - (non-loyalty-building-count + 1) * (loyalty+50)/50

If the result is > 0 then it's better to build a loyalty-building. If the result is < 0 then it's better to build another building.

Edit: You should obviously substract the amount of pop-providing buildings from the non-loyalty-building-count since those don't scale with loyalty. And as we know from dev-post we should try to always have 5 more pop-slots than pop as otherwise growth suffers.

In other words: If your Loyalty is 0 you'll want to start adding loyalty-buildings once you have 9 non-loyalty/non-habitat-buildings. But by the time you reach 18 non-loyalty/non-habitat-buildings you'd want your loyalty pretty-much at the cap. You obviously do not consider the loyatly that would get you above the cap in that formula.

That would be an easy way to increase the AI's economical strength.

4)
I personally haven't paid much attention to the AI's colonization-behavior so I cannot really comment on that. It surely is something that needs to be taken care of.

5)
I've also seen the AI deadlock itself and first thought that the problem lies more within the game-mechanics. But this is not actually the case. As a player you can easily get out of these kind of deadlocks if you use the minus-buttons on the buildings wisely to switch off those you don't need to resolve the crisis.
Teaching the AI to do the same shouldn't be too hard.
If you run out of energy (or ore for necrons), you switch of unit-production-, then research-, then food- and eventually influence-buildings. It is imporant to keep the hab-blocks running.
If you do that you will avoid getting the -50% on everything that will cripple you completely and then you simply make more energy/ore-buildings.
Also with smart planning this should only ever happen if you lose a specialized city.

6)
What I personally identified as one of the major-weak-spot about the AI besides it's terrible tactical-capabilities and lack of combat-outcome-predictions is that it doesn't seem to have the slightest clue of how to determine how good a unit is. My impression is that it randomly builds the things it has unlocked regardless of what the enemy fields.
But the way the damage-calculations work in Gladius this means you'll likely end up with units that are completely useless against your enemies' roster.

That's why I'd suggest to determine the score of which unit to build by using an algorithm that compares each of your available units against a cost-weighted average of what your opponents have. I also wouldn't consider that cheating as it is merely a means of simulating player-experience.

Let me try to write some pseudo-code here:

Code: Select all

float highestscore = 0;
unittype bestunit = null;
foreach(unit in availableunits) {
	float score = 0;
	float totalenemycost = 0;
	foreach(enemyunit in enemyunits) {
		score += SimulateCombat(unit, enemyunit) / unit.cost;
		totalenemycost += enemyunit.cost * enemyunit.count;
	}
	score *= totalenemycost;
	if(score > highestscore) {
		highescore = score;
		bestunit = unit;
	}
}

float SimulateCombat(unit, enemyunit) {
	if(getDamage(unit, enemyunit, true *meleerange*/) == 0 && getDamage(enemyunit, unit, true *meleerange*/) == 0) {
		return 0.5;
	}
	myhealth = unit.maxhp;
	enemyhealth = enemyunit.maxhp;
	//unit that outranges enemy gets a free shot in simulation
	if(unit.range > enemyunit.range) {
		enemyhealth -= getDamage(unit, enemyunit, false /*meleerange*/);
	}
	if(enemyunit.range > unit.range) {
		myhealth -= getDamage(enemyunit, unit, false /*meleerange*/);
	}
	while(myhealth > 0 || enemyhealth > 0) {
		//I am aware, that remaining health is most likely taken into account in order to determine the amount of attacks as many units scale with group-size but I don't want to overcomplicate the pseudocode 
		myhealth -= getDamage(enemyunit, unit, true *meleerange*/);
		enemyhealth -= getDamage(unit, enemyunit, true *meleerange*/);
	}
	if(myhealth < 0 && enemyhealth < 0) {
		return 0.5;
	}
	else if(myhealth < 0) {
		return 0.5 - 0.5*enemyhealth/enemyunit.maxhp;
	}
	else {
		return 0.5 + 0.5*myhealth/unit.maxhp;
	}
}
Not sure if there's some logical-errors in it as I obviously can't test it. But something along those lines should allow the AI to determine the overall usefullness of their units and make sure they build the most suitable ones. But I think I can already predict that which ones that would be, which gets us to an even easier way to determine a score for unit usefulness compared to other units:
score = (armor + armorpen + maxrange) * damage * health / cost;

Of course this isn't accurate at all but it is super simple and should still get decent results if it has to go quickly.

Of course there's plenty of other things in which I have ideas of how to improve the AI but this post is already getting a little lengthy, so maybe I'll save that for later.

I'd also like to mention that I have actually asked Slitherine/proxy-studios to grant me access to their source-code as I'd happily implement and test my ideas myself to take that burden off of them. And it's not like I don't have any credentials in that regard. Infact I've done the same exact thing for Pandora: First-Contact, a previous game of them, before.
I'm promising this: I will make the Gladius-AI really good, if they let me. I'm full of ideas and very determined. This post merely scratches the surface.
ErissN6
1st Lieutenant - Grenadier
1st Lieutenant - Grenadier
Posts: 788
Joined: Wed Nov 20, 2013 11:34 pm
Location: France

Re: Serious AI Bugs

Post by ErissN6 »

However I prefer a game with a too bad AI than a too good one.
A good AI is not the stronger. Playing against a strong AI should be loosing, only a better programmed AI should win.
What's making the usefulness of an AI for a game is the simulating of personnality (simulating a human player and/or the fails of alien behaviour). So, per example, a non retreating harmed unit could be a feature, simulating a too strong pride.
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

In my local build issues 2) and 3) are fixed.
Issue 5) should be a lot rarer aswell.
Those three issues were all intertwined and while there's still a lot of potential for improvement, it's looking somewhat good in the economy-management department.

I'll revisit it once the other issues start looking better.

1) is next thing I want to look at.

Here's a few screenshot from the AI-only-testgame, that I just finished.

It was on Easy-Difficulty (Default-Loyalty) and one of each faction.

The necron snowballed.

That's what his army looked like one turn before victory:

Edit: Apparently attaching more than one image per post is a little buggy.
Attachments
Gladius004.jpg
Gladius004.jpg (631.86 KiB) Viewed 3680 times
Gladius003.jpg
Gladius003.jpg (566.98 KiB) Viewed 3683 times
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

When looking at that screenshot, I might want to take a look at how my changes impacted tech-selection. I was not really aware but it seems like a lot of unit-types, especially heros, were skipped. The scores for those probably still scale with the amount of existing units in that category. So a similar issue to "2) Unit cap", just with research.
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

Your theory for 1) is incorrect.

The true reason is the following:

The AI runs several cycles and in each cycle they consider all possible options.

Using abilities, moving somewhere, attacking something and healing (including retreating when they are threatened).

Now the problem is that when they have moved and attacked the only thing they still have left to do is healing. So healing always wins regardless of how little damage has been taken.

And since they can't perform it anymore they queue it as action for the next turn.

And so when the next turn starts, they retreat immediately.

The obvious solution was to not consider healing when there are no movement-points. However, when they actually should retreat, not queuing this already the turn before means that they don't run immediately and may be taken out by other units due to simultaneous movement.

So I currently have a workaround/compromise: When they have no movement left, they only consider the heal-action when their health is below 75%. That might even be a little high still but it already looks a lot better. I'll experiment more with that but there's a more pressing issue which I most likely caused by something else: They sometimes stop doing anything at all. I need to find out the cause of this.

If I can find it, I am confident that I can get the first iteration of my improved unit-handling into the next patch. If not it'll likely take a little longer.
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

Definitely not unit-capped anymore! :D
Attachments
Gladius016.jpg
Gladius016.jpg (702.89 KiB) Viewed 3587 times
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

Gladius042.jpg
Gladius042.jpg (506.64 KiB) Viewed 3465 times
Made some progress on AI unit-composition and economy-management.

This is what the highest-difficulty now looks like to me.
Take into consideration that this is turn 66.
bssybeep
Administrative Corporal - SdKfz 232 8Rad
Administrative Corporal - SdKfz 232 8Rad
Posts: 170
Joined: Thu Jun 19, 2008 10:34 pm

Re: Serious AI Bugs

Post by bssybeep »

For item #2, maybe have the AI unit cap be a tunable option. I like a AI unit cap because it prevents the AI from cheating by spamming endless units. A human player would / could not spam all those units, neither should the AI.
Xilmi
Pandora Community Developer
Pandora Community Developer
Posts: 523
Joined: Fri May 23, 2014 3:21 pm

Re: Serious AI Bugs

Post by Xilmi »

If the human player gives himself the same resource-advantage as the high difficulty-levels provide to the AI, he can just do the same thing.
Post Reply

Return to “Warhammer 40,000: Gladius - Relics of War”