The Big Question - How Does The AI Choose Which Units To Build?

Oz: When you test changing the AI strategies, I think it could be interesting if you tested both sensible and insensible flaggings. Eg, run one test when the 4.6.1 unit has "Offense" and the 6.4.1 one "Defense".

I think it's interesting that the player's governors exlusively built the most aggressive unit. Since governors in normal games tend to want to build defenders all the time, this would seem to suggest that AI strategy flags do indeed have an effect. Looking forward to see what the governors'll do once this unit loses the defense strategy.
 
Well, the results (apart from your city governor!) were better than I had expected. :)
Interesting that the 5-5-1 unit was built far less than 6-4-1 and 4-6-1 versions.

Hmmm....I wonder what would happen with exactly the same experiment, but the unit choices were say 7-3-1, 6-4-1, & 5-5-1.
Would the 5-5-1 still be fewer than the others, or would the 'middle choice' (i.e. the 6-4-1) be picked the least, because there is a unit with a better attack, and another unit with a better defence?
 
I think The Last Conformist had a good idea there. I also don't think you need to care so much about regicide, in my (very limited) experience the AI doesn't really care about the kings, they just fortify them in the capital.
Otherwise: :thumbsup:
 
Interesting first test. I'd like to see a bunch more tests on this very simple position before getting too wild, though.

Recommended tests:

1. Flag 6/4/1 offensive, 5/5/1 both, and 4/6/1 defensive (logical) and see what happens.
2. Test simply whether the AI will build better units. Give it options between 8/8/1, 4/4/1, and 2/2/1 all with the same cost and flags and see what it builds.
3. Similar test but more extreme...7/3/1, 5/5/1, and 3/7/1 as units.

There are SO MANY variables, it's important to limit them as much as possible as often as possible, until we get a good idea of what's going on.

I also think being at war with a civ and changing what ratio of units it has makes the testing much more problematic, as we don't see if the AI's trying to maintain a certain ratio of defensive units:cities or offensive units:defensive units or anything, unless we get exact casualty rates, too.

Arathorn
 
To All,

Agreed! --

1. Yeah, testing with "Regicide" is probably a waste of time.

2. Next iteration: some combo of Kyrten's and Arathorn's ideas.

3. @The Last Conformist -- good / interesting idea re: "sensible" and "insensible" flags.

Also, I'm assuming my target of "equivalency" = ~ +/- 10% is satisfactory ... ?

EVERYONE please give some thoughts (i.e., "best guesses") on what I think will be the next two steps:

1. increased MF

2. artillery

again please assume that the "base" (and now clearly very notional) unit is a 5-5-1.

Much Thanks For All The Feedback, Encouragement, Etc.,

-Oz.
 
Based on ACW experience, the AI seems value high movement values highly on offensive units.

When I think of it, the reg'lar game AI tends not to build alot of Medieval Infantry, prefering Knights instead. This too would seem to suggest a high valuation of mobility, since the Medievals are 43% cheaper for the same attack value.
 
Well, that's just logical isn't it? It not only give you the ability to move fast, it give you the ability to retreat. That's worth alot.
If only we had a 'retreat' flag, regardless of the movement factor.
 
I agree with all the experiment suggestions so far, but I strongly suspect that any 'middle choice' units will be picked the least.

After all, out of an option of say 6-4-1, 5-5-1, 4-6-1, wouldn't you pick the first for it's attack advantage, the last for it's defence advantage, and largely ignore the 'middle choice' of 5-5-1?

And if you were a programmer, wouldn't you factor just such a decision into the AI?
 
Originally posted by Kryten
I agree with all the experiment suggestions so far, but I strongly suspect that any 'middle choice' units will be picked the least.

After all, out of an option of say 6-4-1, 5-5-1, 4-6-1, wouldn't you pick the first for it's attack advantage, the last for it's defence advantage, and largely ignore the 'middle choice' of 5-5-1?

And if you were a programmer, wouldn't you factor just such a decision into the AI?

Kryten, me bucko, I fear you and I (and all our merry group) are simply far too rational for all this ...

TEST #2

Values for "Warrior", "Archer", and "Swordsman" were kept the same as Test #1 (6/4/1; 5/5/1; 4/6/1) with the addition that the 6/4/1 was flagged "Offensive", the 5/5/1 was flagged both "Offensive" and "Defensive", and the 4/6/1 was flagged just "Defensive"

Build results over 20 turns:

Romans (Yours Truly -- or, rather, His Governor):

25 Warriors (~42% total force) 2 Archers (~3%) and 33 Swordsmen (~55%)

Greeks:

24 Warriors (~24%) 19 Archers (~33%) 17 Swordsmen (~28%)

Egyptians:

19 Warriors (~33%) 17 Archers (~28%) 24 Swordsmen (~40%)

Observations:
1. My Humble Governor Aside, the "midground" 5/5/1 was close enough to 1/3rd the force for jazz and government work.
2. The Player's Governor works in mysterious ways ...


TEST #3

Values for "Warrior", "Archer", and "Swordsman" were changed to 7/3/1; 5/5/1; 3/7/1; the 7/3/1 was flagged "Offensive", the 5/5/1 was flagged both "Offensive" and "Defensive", and the 3/7/1 was flagged just "Defensive"

Build results over 20 turns:

Romans (Yours Truly -- or, once again, His Governor):

11 Warriors (~18% total force) 5 Archers (~8%) and 44 Swordsmen (~73%) (The Roman capitol built ONLY Swordsmen!)

Greeks:

23 Warriors (~38%) 19 Archers (~33%) 18 Swordsmen (~30%)

Egyptians:

14 Warriors (~23%) 23 Archers (~38%) 23 Swordsmen (~38%)

Observations:
1. Despite the wider spread in A/D values, distribution (once again excepting the Player's Governor) remains roughly equivalent to the narrower spread -- although, for reasons unknown, the ratio of Greek builds in Tests 2 & 3 were all but identical, the Egyptian varied noticeably; personally, I'm willing to assume that the AI for each Civ was "interpreting" its strategic situation differently and building accordingly.
2. Defensive units (3/7/1s) seemed to be atttacked less frequently than the 4/6/1s of Test #2, although I freely admit this is a subjective statement on my part.

And Now The Complete Freakout: Test #4

This was Arathorn's suggestion to give each unit good, moderate, and poor units -- in this case, Warrior = 7/7/1, Archer = 5/5/1, and Swordsman = 3/3/1 -- all flagged both "Offensive" and "Defensive".

I almost didn't run this test -- heck, I've been a programmer, and the result should have been obvious :cry: ...

I stopped after only 10 turns --

My loyal Romans built nothing but 7/7/1s.

The Greeks built 21 Warriors 9 Archers -- nearly 1/3 inferior troops :eek:

For their part -- the Egyptians built 24 Warriors, 4 Archers, and 2 Swordsmen ...:cringe:

This last test totally throws me off, as I can offer absolutely no theory as to why any of the inferior troops would have been built at all ... Unless of course there is indeed a "tiny" randomizing factor just to keep things "interesting" ...

Perplexedly Yours,

Oz
 
Originally posted by ozymandias
...This last test totally throws me off, as I can offer absolutely no theory as to why any of the inferior troops would have been built at all ... Unless of course there is indeed a "tiny" randomizing factor just to keep things "interesting" ...
There is a way to test this. Try with "Random Seed" off, and replay some of the turns, with exactly the same moves.
It's strange that the governor doesn't do the same as the AI. :hmm:
 
Originally posted by mrtn
Well, that's just logical isn't it? It not only give you the ability to move fast, it give you the ability to retreat. That's worth alot.

I didn't offer any opinions as to how logical it was.

In the regular game, it seems to work out OK.

In ACW, clearly the retreat ability isn't worth enough to compensate for that corresponding one-move units have 250% better defense and 43% better offense, at lower cost. Yet, the AI tends to favour the mounted units.

Oz: The only reasonable conclusion from your 4th test would indeed seem to be that there's an element of randomness in the decision. Hm, that also explains why the AI sometimes builds Longbowmen despite being able to build Medievals.

And finally some wishful thinking; This testing oughtn't be necessary; Soren should be telling us how the AI "thinks"!:scan:

Since that's apparently isn't about to happen, I'd once again want to express my gratitude to Oz for carrying out these tests.
 
Very good work oz. :goodjob:
Like The Last Conformist, I too would like to thank you for all your efforts in this matter.

Well, the results are very encouraging, if somewhat mystifying! :D

I am especially interested in the outcome of experiment number #4.
As you know, I am very keen on having an extra type of unit in addition to heavy infantry and fast cavalry to represent the supporting light skirmishing foot troops used throughout the ages (with weak attack, minimal defence, and a defensive bombarding ability, such as Slingers, Javelinmen, Archers, Crossbowmen, Napoleonic Light Infantry, and such like....in order to encourage a little bit of ‘combined arms tactics’ within the game).
Ideally, the build ratios we need for ‘realistic’ armies is something like 1 mounted and 1 light infantry for every 4 heavy infantry....and experiment #4 has such a ratio! :)
Of course, it all depends upon how much the AI values fast units.

So I wonder if I could trouble you to make a further experiment:-
What would the AI build if experiment #4 was repeated, but the ‘inferior’ units had faster movement....say 7-7-1, 5-5-2, 3-3-3 for example?
(I’m betting that the AI does not take into account the different speeds of various 'fast' units: all it knows is that ‘fast’ have a speed greater than 1....but I could be wrong.
I have been so far. :lol: )
 
Originally posted by Kryten
but I could be wrong.
I have been so far. :lol: )

Don't hurt yourself ! :D

More seriously, well, I have been following this thread with great interest ! Thanks for all the testing. There are indeed very useful info here for scenarios.
 
I'm worried about the small sample sizes. It's really hard to draw meaningful trends from so few trials. 120? 60? Makes it really difficult to spot trends....

My guess at this point (emphasize guess) is that once the AI has decided to build a unit, it does something vaguely like the following.....

1. Decide offense/defense based on some arcane "reason" that I would like to determine eventually but not now.

2. Look at all units of that type and weight them somehow -- probably based on A/D/M, cost, extra values, etc. This weighting is very important and what we're trying to get at, sorta. Again, a guess at weighting is something like double the dominant value (attack for offense, defend for defense) plus the lesser value, with the whole thing doubled for the unit(s) with the highest dominant value. Then, a die is rolled to pick between them, determined by the weighting value above.

3. Build that unit and repeat.

We can't really get any kind of a handle on the weighting, though, without bigger test runs, with better/different control. Now, it's not fair to ask Ozy to run all the tests, but it would be nice if they were similar. Ozy, will you post the .bix and map file you're using? Then, we can edit them and do independent trials/tests?

In tests 2 and 3, what was the ratio of offense/defense amongst the "middle" group (archers)? Were they half and half? More defense? More offense? What? That's an important question.

I'm also worried that even in these very simple tests, our signal-to-noise ratio won't be very high and we might miss things. Plus, we still have an awful lot of variables going on at once. I think fewer variables would be good.

My proposed next test(s):
- Like test 4 but with just two units -- 7/7/1 and 5/5/1 with about 50 turns and no war.
- Like above but with 6/6/1 vs. 5/5/1 and then 8/8/1 vs. 5/5/1. Or maybe start with 2/2/1 vs. 1/1/1 and then go to 3/3/1 vs. 1/1/1.

Once we get the simplest case figured out, we can move on to more complex situations....

Arathorn
 
Just two comments:

1. I am not surprised the AI behaves somewhat differently for the player. Some of the global decisions based on the current situation, which might influence instructions to city governors (i.e. build often/never), may be ignored.

2. The randomness in unit building is very reasonable (not only for flavor). In these simple examples (assuming an identical cost), the choices seem obvious. However, when confronted with units that offer different capabilities it would seriously weaken the AI to build only the one with the best weighted sum, whatever the algorithm, since the weights should really, one every occasion, be sampled from distributions that reflect the current situation in the game. If you don't know how to obtain these distributions in a proper way, it is still better to introduce some randomness even if the assumptions are not optimal.
 
Originally posted by The Last Conformist
OK, I did a little test on the AI's treatment of dual-strategy units.

I modded the Bab Bowman to have both the Offense and Defense AI Strategies, and forced them to build only Bowmen. In the first test, they were given a starting force of four Archer, in the later one of four Spearmen.

In both cases, the AI flagged all Bowmen it built as "OFFENSE". It seemed to ignore the Defense setting on the Bowmen totally. The Spearmen went on defensive business as usual in the later test.

Well, I was playing a game where I owned every single resource, and the AI had Riflemen (from Nationalism) and the funny thing is, they attacked me with their Riflemen, ignoring the "Defensive" setting on the unit, and attacked. The only thing that I can see as to why is the Riflemen had a better attack than the longbowman. Plus, when all defensive units in an AI city fail, I will always find their attackers defending the city, just in case. It seems to me that the AI does whatever it can to defend a city, and kill you. The "Offensive" or "Defensive" settings seem to me to be guidlines, not rules that the AI will not break.

And it also seems that they flood the board with their UU's, and outside of defending their cities, will build only those as long as they can.
 
Riflemen have the Offense flag too, and while we may disagree about the cost-benefit aspect, I don't think we're going to disagree with the AI that 4.6.1 Rifles are better attackers than 4.1.1 Longbows.

I'm not sure what you mean with the attackers "defending" the city. The way the game selects which unit will defend against a given attack totally ignores any AI or player strategies; it goes straight after a combination of HP and Defense strength*. The AI will sometimes fortify attackers in cities, but I don't know what governs this.

But the confusing thing in my test was that the AI flagged all Offense/Defense units as OFFENSE, despite that it realistically ought to've been in greater need of defenders in the former test.

In an unexpected twist, which I failed to mention in the post you're quoting, the AI moved it's first Bowman out of the city, leaving a fortified Archer as garrison.
__________________
* Has anyone verified what this combination is? I've been sorta assuming it's simply effective Defense times remaining HP - ranking after which does not necessarily result in the same ordering as the chance of actually winning the battle, mind you - but haven't actually tested.
 
What I meant by the AI will defend the city with attackers is just what you said. When I get close to them, instead of attacking my units, they garrison all their attackers in the city. Note: it seems that the farther ahead technologically I am, the less likely they are to attack my units. Their bowman will openly assault my swordsman, but will flee for their life at the sight of my modern armors. Makes sense, but I think that has something to do with their descision.

Riflemen have attacker flagged? I stand corrected.
 
Last time I checked this thread was a while ago, indeed very interesting results here :)

Some things I thought I should share after playtesting my own mod....

"Build Often / Never" flags are problematic: Smoking Mirror suggests that flagging more than three “build often/never” choices will confuse the AI.

I can´t confirm that. I have seven checks in the "build often" list for one civ:

- off. land units
- def. land units
- air units
- naval units
- growth
- production
- culture

And it works really good. However, I should mention that this civ has a good start with most cities (and relatively well developed) in the mod, maybe this is a factor.

The AI will build cruise missiles, ships and bombers, but will tend to use them to attack infrastucture, rather than in support of ground attacks.

The same civ has lots of air units as a result of the "build often" flag. I´m just in the end game now, and at certain times they bombed really the crap out of me, targetting not only infrastructure but also my troops. Maybe it has to do with the fact that I gave them lethal land an lethal naval bombing abilities and a high rate of fire (4 - I´ll change it to 3). It took them usually 2 attacks to kill a veteran unit in the field, and they had dozens of air units.
 
Originally posted by BeBro
The same civ has lots of air units as a result of the "build often" flag. I´m just in the end game now, and at certain times they bombed really the crap out of me, targetting not only infrastructure but also my troops. Maybe it has to do with the fact that I gave them lethal land an lethal naval bombing abilities and a high rate of fire (4 - I´ll change it to 3). It took them usually 2 attacks to kill a veteran unit in the field, and they had dozens of air units. [/B]

One time I let a civ get to air power, and when I invaded them, they bombed the crap out of my troops. I had to retreat it was so brutal.
 
Top Bottom