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

Originally posted by Arathorn
Contemporary defensive units? Hardly ever.

Contemporary offensive units?
Early ancient age: Warriors and archers (and chariots)
Middle/late ancient age: Swords, horsemen, and archers
Early Medieval age: Medieval infantry (PTW, not vanilla, but...), longbow, knights
Then it narrows much more....

{insert icon for extreme pain here }

Offensive units:

Early ancient age:

warrior AF=1 / DF=1 / MF=1 cost=10
archer AF=2 / DF=1 / MF=1 cost=20
chariot AF=1 / DF=1 / MF=2 cost=20 resource=horses

Middle/late ancient age:

swordsman AF=3 / DF=2 / MF=1 cost=30 resource=iron
archer AF=2 / DF=1 / MF=1 cost=20
horseman AF=2 / DF=1 / MF=2 cost=20 resource=horses

Early Medieval age:

medieval inf AF=4 / DF=2 / MF=1 cost=40 resource=iron
longbow AF=4 / DF=1 / MF=1 cost=40
knights AF=4 / DF=3 / MF=2 cost=70 resource=horses+iron

Cause Of Extreme Pain #1

Lack of cost correlation - offensive units w/MF=1:

Breakdown 1:

warrior AF=1 / DF=1 / MF=1 cost=10
archer AF=2 / DF=1 / MF=1 cost=20
swordsman AF=3 / DF=2 / MF=1 cost=30 resource=iron
longbow AF=4 / DF=1 / MF=1 cost=40
medieval inf AF=4 / DF=2 / MF=1 cost=40 resource=iron

Breakdown 2:

warrior AF+DF=2 cost=10
archer AF+DF=3 cost=20
swordsman AF+DF=5 cost=30 (+ resource=iron)
longbow AF+DF=5 cost=40
medieval inf AF+DF=6 cost=40 (+ resource=iron)

Conclusion: even if (as seemingly demonstrated early on) the AI build preference, with all else being equal, values 1AF = 1DF, the game is not structured to follow any such correlation vis-a-vis cost!!

Also compare the following:

1. the jump in A+D from archer to swordsman = +2 (= +67%) for an increased cost of +50% with iron also being required.
2. the jump in A+D from archer to longbow = +2 (= +67%) for an increased cost of +100% (no special resource required)
3. the jump in A+D from swordsman to medieval infantry = +1 (= +20%) for an increased cost of +33% with iron also being required.
4. the jump in A+D from longbow to medieval infantry = +1 (= +20%) for an increased cost of +0% with iron also being required.

... Can anyone find ANY consistant correlation here???


Cause Of Extreme Pain #2

Consider again the breakdown of units by approximate era:

Early Ancient age: warrior; archer; chariot
Middle/late Ancient age: swordsman; archer; horseman
Early Medieval age: medieval inf; longbow; knights

Each "era" contains one "inferior" infantry, one "superior" infantry, and one "fast" unit Also, except for the first "era", the "superior" infantry requires a strategic resource.

I suspect we will see a similar pattern recapitulated throughout ... and we all know how intelligently the AI builds and uses artillery, aircraft, and ships ...

TENTATIVE CONCLUSION: THE AI BUILD ALGORITHM REQUIRES AN EXTREMELY LIMITED NUMBER OF CHOICES DELINEATED ONLY BY SPEED AND STRATEGIC RESOURCE REQUIREMENT

If true, this means that -- as mod-makers, to give the AI any chance of a predictable (planned) build result -- we must adhere to this sort of "clustering" of build options.

*sigh* ... No "Holy Grail" build algorithm ... but at least it seems the truth was indeed out there ...

-- Oh, and I'd be REALLY happy if someone found some flaw in these conclusions ...

Disappointed But Hardly Surprised,

Oz
 
ozymandias,

AI will never have more than 2 units in production at a given
time. One offensive and one defensive.

Exception: An invisible Guerilla unit produced at 1 town
(out of 50). There is one more exception: We have tried
for a long time to force AI to produce Army-type units.
Now it does (indirect) by "cheating"! For 6-7 turns AI
will produce Leaders at one city (one Leader each turn).

Leaders are then converted to Army-type units.
These are the only exceptions to the rule.
Note also: AI have never produced Guerilla and Leaders
at the same time.

I wish to point out that this (the above mentioned rule)
is no "prestige-thing" for me. In fact I wish I were wrong on
this matter, since it would make AI production strategy
much more interesting.
Edit: As have been mentioned earlier: ACW is a one-continent
world, which means that AI will never produce naval units.
Its possible that if ACW was a 2 or more continent world,
AI would produce one type of naval units in addition to the
2 types of land units.

Still I doubt (with some odd exceptions) that I will see AI
produce more than 2 types of land units at a given time.

I hope you will continue with experiments and this thread.

Rocoteh
 
Originally posted by Rocoteh

I hope you will continue with experiments and this thread.

Rocoteh

Much thanks, again, for all the info and encouragement :)

I don't plan to abandon this -- where I'm taken aback is the apparent discovery that the algorithm-set responsible for AI builds simply does not seem designed to make "intelligent" decisions except when and where a very narrow force pool is concerned.

I plan to spend a few days mulling over whatever "rules" can be extracted from all the work we've collectively done (actually, I'm somewhat disappointed and surprised that more mod makers haven't been actively involved in this thread -- for example, I'd love to know what the SOE guys with their 135 UUs -- or whatever the precise number is -- are experiencing re: this issue ... Or perhaps the collective silence speaks volumes itself. I know I began this because I wanted to know why the AI ignored certain units in the ubiquitous personal mods I was playing around with.)

Tentatively, I'd say the "rules" and further points to be tested are as follows (limiting myself, for the moment, to land units):

1. The AI probably won't know what to do with more than (I'm guessing) 4-6 units at a time -- I'm assuming (i) that strategic resources aren't taken into account (ii) that the AI might be able to handle two different defensive unit types at once (although I'd like to test static -- MF=0 -- as well as MF=1 and MF=2) (iii) that the AI can probably handle ~4 offensive units, given that it's programmed to work with a force pool with special pupose units like paratroopers and marines.

2. That the AI will not build more than two unit types at a time, with extremely rare exception.

3. That the AI will "cheat" -- although the logic behind even these decisions seem opaque at best.

4. The "trick" to successfully modding with multiple units will entail:
(i) Having "meaningful" (i.e., contemporary) units available in lieu of both those which require strategic resources and their predecessors
(ii) Having different unit types used for drafts
(iii) develop DIFFERENT upgrade paths for both (i) and (ii) above
(iv) wait until Conquests comes out and assume that the engine which randomly generates Knights Templar will indeed be mod-able for any unit, and that minor wonders and/or improvements can be used to generate guerillas, assassins, etc.

Re: this last point (4) -- assuming, for argument's sake, that the AI can handle 2 defensive, 2 offensive, and 2 special purpose units, AND that the "state-of-the-art" 2 defensive units and 2 offensive will require two strategic resources each AND that alternative units are available for lacking either or both requisite resources AND that a different unit entirely is used for drafts -- that's a force pool of ELEVEN (11) different O/D land units in the force pool at once ... It'll just take even more work placing / "balancing" strategic resources to see more than about half of them in play at a time ...

I think another "trick" will be to work the tech tree so that combat advantage alternates between offensive and defensive units -- this would not only more truly simulate the evolutionary nature of warfare, I suspect it would make the entire game less predictable in its play (e.g., Civ 1 has Offensive units which can crack Civ2's Defensive units; yet Civ 2's Defensive units can't be cracked by Civ 3 ... properly and perversely developed :D I imagine something along the lines of rock / paper / scissors can be coaxed into being.)

Anyway, my real disappointment is that we've moved from science to art -- A true build algorithm would have been sweet ...
Although, having just jotted down the various points above, I'm pleased to think we can achieve our goals, even though it will involve a different design approach than one might hope for re: a 21st Century game engine :rolleyes: .

Anyway, onward & upward ;)

-Oz
 
Excellent research oz. :goodjob:
We all do appreciate it.
But I do have one or two questions....

If the AI has a choice in each period of three units (i.e. each "era" contains one "inferior" infantry, one "superior" infantry, and one "fast" unit), but as others have noted the AI will only build TWO diferent unit types in a single turn, then which would they be?

Also, do the results that you obtained show that the AI makes it's choices by the combination of attack + defence? (let's call it the 'value' of the unit, so a 3-2-1 has a 'value' of 5, while 2-1-2 has a 'value' of 3?).

Last of all, although not about the building of units, but more about which unit the AI uses to defend with in a mixed stack, have a look at this post..... :)
http://forums.civfanatics.com/showthread.php?postid=1243543#post1243543
 
I managed to reconstruct my old mod (The reason I started
to work with this was that yesterday my new computer
bought less than 3 weeks ago become stonedead. They
say I will get it back maybe 3 weeks from now....)
Anyway I intend to investigate what AI-civs are producing.

I started with America (14 cities left). 7 produced M1A2,
6 B1 Bomber and 1 F22Raptor. With regard to "Build Often",
America have Naval units, Air units, Growth, Production and
Culture flagged.
Before America-AI declared war on me it had many coastal-cities
but never produced a single naval unit.


Edit: I continue to investigate and have a real absurd
report on Iroquois producing:

2xT90
9xF16
4xB52
1xMiG31

Build often flagged: Naval units, Air units, Growht, Production and
Happiness. If you wonder why the Iroquois can produce both
NATO and Russian units, the answer is that I see no problem
in that with CIV:s that not existed as states into Modern period.


Rocoteh
 
A final report from my reconstructed pesonal mod.

Aztecs: (Units in production)

8xT90
10xB52
3xBMP

Build often flagged: Naval units, Air Units, Production and
Happiness.

China:

19xT90
7xStrategic Bomber
4xBMP

Build often: Naval units, Air Units, Producion and Culture.

Spain:
10xLeopard 2
1xMarder

1xMarketplace

Build often: Naval units, Air units, Production, Happiness and
Trade.

Russia

6xT34/85
1xMotorized Infantry


1xSewer System
1xHospital
1xBarracks

Build often: Naval units, Air units, Growth, Production and Science.

Vikings:

5xImperial Guard
5xRifleman

1xForbidden Palace
1xWinter Palace
1xBarracks

Build often: Naval units,Air Units, Production, Trade and
Culture.

I agree with ozymandias: Its strange that so few mod-makers
and scenario-creators have responded to this thread.

If you add 200 units and AI only use 25% of them its
a problem!!!!!

Edit: The most important thing: Not a single naval unit
in production. That`s hard if you (like me) want to play
on Earth-maps. Maybe after all I should consider to
make a 24 continent fantasy-map with 24 Civs.....


Rocoteh
 
Originally posted by Rocoteh
I agree with ozymandias: Its strange that so few mod-makers
and scenario-creators have responded to this thread.

If you add 200 units and AI only use 25% of them its
a problem!!!!!

We are watching :D
It is really useful and I hope it helps me plan my scenarios carefully (more than what happened with first version of Reconquista).
But, apart from the joke, and Kryten who posts here, I am sure there are other scenario-makers that just read it with interest wihout posting.
 
Originally posted by LouLong
But, apart from the joke, and Kryten who posts here, I am sure there are other scenario-makers that just read it with interest wihout posting.
Im reading the thread too.

good job guys:goodjob:
 
here's something that will make your head spin

i turned on my govenors, and when they had the option of three units warriors 2.1.1 20 offensive, spearmen 2.2.1 20 offensive and defensive (bronze working), and archers 3.1.1 20 offensive (warrior code) they would pick warriors at times
 
Originally posted by Rocoteh
Maybe its better to work with Build Never than
Build Often?

Rocoteh

Again, the only "evidence" we have re: Governor Flags is anecdotal, that selecting more than 3 "confuses" the AI (i.e., the algorithm winds up with unforeseeable / unforeseen and/or unpredicatable results by being overwhelmed with more than 3 variables).

Perhaps someone can help me think of a decent way to to test this?

Best,

Oz

P.S. EDIT -- Rocoteh, would you be willing to re-run your mod, but with no more than 3 Governor flags checked per Civ? -- I don't think that an exact count of units is required (although I certainly wouldn't mind seeing precisely how it turns out :) ) but more a "sense" if the AI is behaving more rationally in its builds.

-Oz
 
Originally posted by korn469
here's something that will make your head spin

i turned on my govenors, and when they had the option of three units warriors 2.1.1 20 offensive, spearmen 2.2.1 20 offensive and defensive (bronze working), and archers 3.1.1 20 offensive (warrior code) they would pick warriors at times

Yeah, I'm increadingly convinced that my theory that the algorithm(s) to choose units is an "eenie-meenie-minie-mo" among what is intended to be a preset "force pool" is on the money ... :(
 
Originally posted by Kryten
If the AI has a choice in each period of three units (i.e. each "era" contains one "inferior" infantry, one "superior" infantry, and one "fast" unit), but as others have noted the AI will only build TWO diferent unit types in a single turn, then which would they be?

Also, do the results that you obtained show that the AI makes it's choices by the combination of attack + defence? (let's call it the 'value' of the unit, so a 3-2-1 has a 'value' of 5, while 2-1-2 has a 'value' of 3?).

Sorry for the delay in response -- Real World & All That.

I guess it's time for a recap :)

My very first tests did indeed seem to establish an equivalency of AF = DF (check page three or so of the thread). If all possible units were flagged both O/D, a slight (but statistically significant) preference was given to a higher DF than AF.

Also, in the three unit test (all both O/D) of 5/5/1, 4/6/1, and 6/4/1, the 5/5/1 was built least of the three, as though the AI was possibly making an "intelligent" decision that the higher DF was a defensive unit -- and it seems to jive with most feedback I've had re: the AI slightly prefering D to O units ("Safety first" and all that ;) ); this was born out in the test where the 6/4/1 was flagged O, the 5/5/1 O/D, and the 4/6/1/ D. Increasing the value of the D unit to 3/7/1 had little effect on the non-Player Civs.

At Arathorn's suggestion, the three available units (all flagged O/D) were 7/7/1, 5/5/1, and 3/3/1 -- and one AI Civ built 1/3rd inferior troops while the other built 1/5th inferior.

Next was MF -- keeping the 5/5/1 as a benchmark unit and offering only one other unit -- in 3 tests, in order, 3/3/2, 4/4/2, 5/5/2, again all flagged both O/D.

  • In the first test, the AI built ~25% 3/3/2s and ~75% 5/5/1s
  • In the 2nd test, it was ~35% 4/4/2s and ~65% 5/5/1s.
  • In the agonizing 3rd test, one AI Civ built the units 50% - 50%, whereas the other 65% 5/5/2s and 35% 5/5/1s.

To quote my earlier reaction to this, ":confused:", although it jives with "Oystein's Formula" of the AI calculating strength: (3*A+2*D)*HP+Bombard [NB: MF IS NOT in this equation!]

O/D flags are, however, critical in deciding what the AI builds within a limited force pool -- flash back to this post for a quick refresher ...

The final test I ran showed that HP made a significant but confusing difference -- given a choice between a 6/4/1 1HP and a 3/2/1 2HP, 2 Civs (including the Player with Governor in charge) built a whopping 70% of the weaker AF/DF-2HP units and the 3rd built 40%.

-- So the lack of consistency in production seems to indicate that any sort of metric for build decisions is impossible THEREFORE IT DOES NOT EXIST unless, of course, the "limited choice" force pool I suggest (or some other explanation) is correct!

... Now, ALL YOU MODDERS following this thread -- who haven't done so, and you know who you are! ;) -- please (SERIOUSLY!!) comment on all this -- numbers ain't required, just your gut sense based upon:

1. Is the AI build anything like you expect WHEN THE STRUCTURE OF THE FORCE POOL VARIES SIGNIFICANTLY FROM THE CIV3 "NORM"?

2. Are some LAND units never being built, to your surprise (again, all my "tests" were on non-bombard land units -- thank Heavens -- as the results Rocoteh et. al. are getting for ships and planes are whacked); of course, please feel free to comment on other types as well as the "anecdotal" evidence along those fronts is consistent -- if consistently troubling ...

3. MEM? SOE? GLC? Anybody else ... ?


Abraxas,

Oz


PS @Kryten -- thx for the tip on the "which defender" thread.

-O.
 
Re: AI build choices --

I. EQUIVALENCES

All other things being equal, the AI weighs the following:

1. AF = DF.

2. (AF + DF) ~= 1HP (i.e.: a 3AF / 2DF / 2HP ~= a 5AF / 5DF / 1HP)


II. DEDUCED LOGIC (from observation; shared anecdote; Firaxian silence; etc.)

1. All things being equal, given a choice of units where, in each case, AF + DF = N, the AI will "decide" that the higher DF unit = "D" strategy.

2. All things being equal, the AI will give some slight-yet-significant preference to "D" units.

3. O/D flags DO make a difference, although (probably) not in violation of all reason ...

4. FROM THE TESTING PERFORMED, the relative value of fast-moving units is indeterminate (which correlates to Oystein's formula as to how the AI determines relative military strength between Civs).

5. The AI will generally only build 2 unit types at a time.

6. The AI build algorithm(s) overall do not actually judge (i) well; (ii) wisely; and/or (iii) at all when presented with a "large" gamut of units, with "large" evidently being some yet-to-be-determined number in the range of 3-5 mixed O/D units; effects of flags such as "amphibious" etc. are yet to be determined --

-- THEREFORE:

7. The AI build algorithm(s) only function "well" when confronted with the force pool types / choices already built into the game.

... Did I omit anything? ...

-Oz
 
ozymandias,

Yes I intend to rerun the mod with 3 flags per civ.
I will start when I get my new computer back since its
much faster than the old.
1 536 MB RAM, Pentium 4 2,6 GHz, compared to 512 MB RAM
and 1 200 MHz Celeron.

Rocoteh
 
Rocotech mentioned some problems with the way the AI used artillery in his ACW scenario. I have noticed the the AI does do a good job of utilizing bombers to bombard cities. Has anyone tried to flag artillery units as air units in a preflight scenario? Am I way off Base here?
 
Some observations from my mod:

1) I experimented a lot with invisible land units (assassins, partisans, commandos, ...), with lower A/D stats than the normal visible units.
The AI liked that ones so much, that it nearly exclusively built that units. The most annoying thing was my experiment with a (2/1/3, invisible, all-terrain-as-road)-spy, available at the early industrial age. It was meant to be used for capturing workers, pillaging terrain improvements, which the AI used it very good for. But it also used the spy as its MAIN OFFENSIVE UNIT instead of cavalry and tanks! It was terrible and not much fun to watch hordes of AI-spies being killed by my infantry.
Now my spy is only an (0/0/3)-explorer-upgrade with only the explore-flag checked and as expected the AI builds none any more. :(

2) At the late medieval era I included a (6/4/1)-grenadier (upgrade of longbowman and medieval infantry). It is a little bit cheaper than cavalry and the AI loves that unit so much that it hardly ever builds cavalry any more, once it has the grenadier available.
Sometimes a single cav appears, but this is maybe only an occasional knight-upgrade and no new-built-unit.
I'd like to have the AI build more cav, but at least the grenadier is a quite good attacker and doesn't unbalance the game, as the spy did, so I'll leave this in the game.

3) One of my latest experiments was the introduction of a dive bomber. It has lower bombardment than the normal bomber, but is a little bit cheaper and can land on carriers (which I inhibited for the normal bomber).
First test: No dive bomber built at all.
Next test: I gave the dive-bomber the precision-bombing-ability. Result: AI builds bombers and dive bombers! :)

Conclusion:
1,3) Additional flags and abilities like invisible, all-terrain-as-roads, precision-bombing, ... are very highly appreciated by the AI.

2) AI doesn't seem to value higher movement very much.
 
Originally posted by davbenbak
Rocotech mentioned some problems with the way the AI used artillery in his ACW scenario. I have noticed the the AI does do a good job of utilizing bombers to bombard cities. Has anyone tried to flag artillery units as air units in a preflight scenario? Am I way off Base here?

The problem for me is that AI use Air-units at 95%
to attack infrastructure, seldom to attack cities or units.

Thus it right now builds B-52:s (which have a very high
price tag) and then uses them to destroy railroads!!!


Rocoteh
 
Originally posted by ozymandias


...given a choice between a 6/4/1 1HP and a 3/2/1 2HP, 2 Civs (including the Player with Governor in charge) built a whopping 70% of the weaker AF/DF-2HP units and the 3rd built 40%...

I haven't taken the time to read all your posts so forgive me if this has been covered, but I have noticed that statistically there is a large difference between the 6/4/1 1HP unit and the 3/2/1 2HP Unit that may not be readily obvious.

In a battle with a 0% defensive modifier, with the 6/4/1 unit attacking... The chance for victory is only 56.25% and this would go down signifigantly as the defender bonus increased from 0% (this is the greatest the victory chance will ever get)... I am assuming that your believe the 3/2/1 2hp unit is the weaker unit, but if it has a bonus of 25% (Forests) or greater, then the victory chance of the 6/4/1 1hp unit falls below 50%!

Assuming again the 0% multiplier for defense...
6/4/1 1hp attacks 3/2/1 2hp -- Victory Chance = 56.25%
6/4/1 1hp attacks 6/4/1 1hp -- Victory Chance = 60.00%

So statistically the 3/2/1 2hp unit is the better defender (over the 6/4/1 1hp unit)... Maybe the AI takes into account this statistical probability somehow... It seems to know that the 3/2/1 2hp unit is the better defender.

Also, for completeness sake, lets look at offense...
3/2/1 2hp attacks 6/4/1 1hp -- Victory Chance = 67.34%

The 3/2/1 2hp unit is also the statistically superior unit on offense... The AI seems to know this too...

Unit-for-unit I would personally take the 3/2/1 2hp unit over the 6/4/1 1hp unit any day... In an average encounter with the 3/2/1 2hp unit attacking he will win 33% to 67% (depending on bonuses) battles and while on defense he will win 45%-73% (depending on bonuses) of the battles... also assuming since it is believed the 3/2/1 2hp unit is inferior, it might cost less! Making it even more attractive...

Just some thoughts, maybe a new direction to analyze... I apologize if this has been covered in a previous post...
 
Originally posted by Der PH


...2) AI doesn't seem to value higher movement very much...

I wouldn't expect it to... the survivability of the unit has very little to do with movement. Movement gets your units to the battle faster and there is the retreat chance (insignifigant in comparison to other traits)... but other than those factors. Movement is practically useless, unless you are impatient for battle... I would think the AI would value a slow movement unit, 6/4/1 Grenadier to use a previous example, over the fast-moving cavalry. Since, in the long run, the grenadier will fare better than the cavalry...
 
Back
Top Bottom