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

There are those out there trying to get Take2 to release source code (or improved editor), or at least get a statement from them (which they will not do). Apparently it goes something like this, Take2 owns the game, but not the rights to release the source code (which firaxsis still has somehow).. and since this will not likely change ever, chances of getting source code is nill. Hopefully one day, then we can all improve the AI! View attachment 209393

Tom

Sorry to disappont you, but Steph and I were each heavily involved in those efforts (and my contact sits on the Board of Take2) and we'll see Civ5 before we see the Civ3 code. :(

As Ever,

Oz
 
Sorry to disappont you, but Steph and I were each heavily involved in those efforts (and my contact sits on the Board of Take2) and we'll see Civ5 before we see the Civ3 code. :(

As Ever,

Oz

True, since it's entangled up in some legal mumbo-jumbo, and neither Take2 nor Firaxsis benefits from releasing it in any profitable way, it likely will never happen. Unfortunate!

Tom
 
Did anyone test how the flags the AI heavily favours can be used to motivate it to produce inferior units?

I know your tests Tom2050 showed that the AI loves stealth attack and enslave. They were the top two in your test. 95% and 85% over an equivilent unit without a flag.

So I was hoping to use these two flags to motivate the AI to build inferior units (lower attack/defence but cheaper). My very short, and perhaps not scientific, test showed the AI did as it always does and produced almost entirely the strongest unit available and ignored the two infeior units with Stealth Attack and Enslave. Very disapointing.

Here's what I did (roughly).

scenario with only four units.

Spear unit A2/D3/M1 (Stealth Attack) cost 8 shields
Archer unit A2/D2/M1 range 1, bombard 4 (Enslave) cost 12 shields
Sword unit A4/D3/M1 +2 HP, ZOC cost 18 shields
Cavalry Unit A5/D3/M2 cost 22 shields

All were set as Offence units only, as I wanted the AI to attack with all of them.

I was hoping that the AI would build mostly spear and archer units, some sword and only a small number of cavalry. Unfortunately the AI build large numbers of Cavalry and not much of the other units.

Am I doing something wrong? Or does the AI only favour the flags when Attack and Defence are equal among units it chooses from? Or was it the different shield costs?

Will try and test it more. Control more variables etc and see what happens.

Cheers

Nick
 
I'm very glad to see you doing this :)

First off: +1HP = AF x 2 AND DF x 2 in the AI's calculation. Also, irrespective of Strategy flag, the AI will almost always assume that the highest DF unit is the best defender, and it will ALWAYS build (and allocate for defensive purposes (you are aware that, given multiple startegies, the AI will always assign each and every unit only one strategy, forever, yes?) Defenders:Attackers in about a 55-60/45-40 % ratio.

Second off, apologies for not getting more deeply into the flags, although we were working with some anecdotal evidence, e.g., the AI really likes Hidden units.

It was also assumed (well, by me anyway) that there's a Jabberwock - hardcoded ;) - preference ratio for paradrop and amphibious units.

I'd be very curious to see what results ZOC / Blitz / et. al. will produce.

My Best Regards,

Oz
 
Hi Oz,

I'll admit I only skim read most of this thread so have probably missed some important work. I think I will have to read the whole thing more carefully. I was aware that more than one strategy results in the AI picking one, thus I made them all, even the spear unit, Offensive only, in an attempt to get them to attack with a variety of units.

I wasn't aware of, "First off: +1HP = AF x 2 AND DF x 2 in the AI's calculation." Am I right in understanding that you are saying the AI would value a AF 2 / DF 2 +1HP unit as much as a AF 4 / DF 4 unit?

It was not a very controlled test. I will endeavour to undertake a much more scientific round of test perhaps if I find some time.

Just quickly did you every manage to use any info in this thread to motivate the AI to produce a unit it would not otherwise produce. Like cheap but inferior infantry units?

Was there a difinitive outcome on whether or not sheild cost plays a part in AI descions? If so how does it effect them?

Cheers

Nick
 
I wasn't aware of, "First off: +1HP = AF x 2 AND DF x 2 in the AI's calculation." Am I right in understanding that you are saying the AI would value a AF 2 / DF 2 +1HP unit as much as a AF 4 / DF 4 unit?

Exactly. Also note that MF is also NOT a consideration.

It was not a very controlled test. I will endeavour to undertake a much more scientific round of test perhaps if I find some time.

:goodjob:

Just quickly did you every manage to use any info in this thread to motivate the AI to produce a unit it would not otherwise produce. Like cheap but inferior infantry units?

Yes: IIRC, in an undefended city, the lowest DF value unit will be built. Also, during testing, there seemed to be a very low (~1%?) random unit production.

Was there a difinitive outcome on whether or not sheild cost plays a part in AI descions? If so how does it effect them?

Cost is NOT a factor. (When I first began these experiments, I was assuming - :shake: - that the AI used a simple cost/benefit analysis for choosing what to build :suicide: ) Neither is MF.

I'll repeat my working hypothosis (and the reason I didn't push these tests any further) that the AI is designed to make its selections based upon a very limited force pool.

Happy Explorations,

Oz
 
Did anyone test how the flags the AI heavily favours can be used to motivate it to produce inferior units?

The AI absolutely loves and adores extra hitpoints. In fact, as I mentioned above, the AI preferred a Destroyer with 11A and 8D, 8MP, 12 hitpoints (cost 360) almost exclusively over a (check this out) BATTLESHIP 70A and 62D, 6MP 6 hitpoints (cost 800).

Lowering the destroyers hitpoints from 12 to 9 or 10 made the AI build the Battleship more often.
And having the DD cost half as much is worse for AI, because AI likes to build units that are more expensive over cheaper units.

Best way to do this, is give your inferior unit extra hitpoints (try using the combat calculator to make sure the extra hitpoints doesn't make it too strong, you might need to lower it's attack/defense values to keep it's strength close to the same), and I can guarentee it will build them. If it doesn't, add another hp and try again, it will eventually especially if the 2 units aren't extremely far apart in strength.

So for example if you have a unit that has 8 attack and 6 defense 0 hitpoints (but AI won't build),
You could try the unit with 4 attack 3 defense 3 xtra hitpoints (believe it or not, the chance that these 2 units will win/or lose a battle is pretty close to the same in most circumstances). Great use of comb calc. to determine how to make a 'similar unit with different stats' in order to make AI build a certain unit more often.


You could try giving the Spear unit A1/D2/M1 with 2 extra hitpoints (this is a little weaker than below)
and Archer unit A1/D1/M1 with 3 extra hitpoints (this is actually a little stronger than below)

Of course, with all flagged as offense, it is very likely the AI weighs attack factor more heavily (don't think we've really tested this very much though to know to what extent).

In order to give yourself more flexibility in forcing AI to build more inferior units, you would probably need to 'UP' the attack/defense values of all these units a little. Or using the above examples, you would have to lower the sword/cav values a bit. If some type of build calculator could be developed that would be tremendously helpful!

Spear unit A2/D3/M1 (Stealth Attack) cost 8 shields
Archer unit A2/D2/M1 range 1, bombard 4 (Enslave) cost 12 shields
Sword unit A4/D3/M1 +2 HP, ZOC cost 18 shields
Cavalry Unit A5/D3/M2 cost 22 shields

Let me know if you have any luck.

Tom
 
Cost is NOT a factor. (When I first began these experiments, I was assuming - :shake: - that the AI used a simple cost/benefit analysis for choosing what to build :suicide: ) Neither is MF.

What? You are referring to shield cost of a unit? Someone did a test showing the AI will build more expensive units more often, as far as to what degree, I am not sure, I'd have to dig through the post and find it. (I thought you did that test, actually :lol: )..

Is MF move points you are talking about or something else? I forgot what the lingo stands for? How fast a unit moves will make the AI build that unit slightly more often, but it is not a huge factor (i think it was a 2move unit was built 10% more often than a 1 move unit, with all else the same).
 
Will try what you said Tom2050. Will use HP's to try and get the AI building inferior units. I realsied there was something seriously wrong with my test anyway, as even when I made the Cavalry unit the worst unit 1/1/1 it still was the only unit being produced. I have no idea why. All four units were definitely producable. I deleted every unit for the test and created 4 new units. Perhaps that stuffed it up. There was no worker, setller, scout, leader etc, so maybe that AI couldn't handle that. Or some other factor was stuffing it up.

Will need to construct a much better test along the lines of your tests and try and get the right balance to get the AI producing the variety of units I want. Hopefully possible as we are only talking about 4 unit types.

So Tom2050 have you used Stealth Attack and Enslave (outside of you tests) to promote production of weaker units?

Cheers

Nick
 
Well, if you think something else was up causing only the horseman to be built, maybe try it again, the swordsman should be built somewhat often. The thing is it is hard to tell how often they are built, unless a test scenario is set up and you go through 30+ turns or so (where each city can pump out a unit per turn).

I was messing around with Rocoteh's WW2 Global scenario, as I mentioned earlier with ship building, and found a way to get US to build ships using hitpoints, and ability to carrier a troop (or plane) <-- both big things AI seems to value for ships.

I'll do a quick test of your original units and post the results of the builds.
I'm curious myself now how it will turn out :)

Here was a re-cap of some of the stuff that has been found out:

1. Does difficulty have any bearing on how the AI chooses it's units? NO - http://forums.civfanatics.com/showpost.php?p=1269761&postcount=243

2. Does aggression have any influence on AI build? NO - http://forums.civfanatics.com/showpost.php?p=1269779&postcount=244

3. Does war affect the AI's build decison? LIKELY - http://forums.civfanatics.com/showpost.php?p=1269872&postcount=245

4. Does one civ's military affect the building decisions of other civs? NO - http://forums.civfanatics.com/showpost.php?p=1269897&postcount=246

5. Does a higher cost of a unit make the AI build that unit more often? YES - http://forums.civfanatics.com/showpost.php?p=6832643&postcount=476

6. Do units requiring strategic resources affect AI build decision? YES - http://forums.civfanatics.com/showpost.php?p=6832760&postcount=477

7. Does the ai seek equilibrium in it's offensive/defensive units? YES - http://forums.civfanatics.com/showpost.php?p=1269925&postcount=247

8. Do all available units to the AI have a 'chance' to be built? YES - http://forums.civfanatics.com/showpost.php?p=1276578&postcount=261

Tom
 
One more question in that list is:

Do the civ traits affect AI build decision?

My answer is: yes. I had a lot of looks in Debug Mode at CCM. In the early stages of the game the civs could build a transportship that is able to carry one unit but has no attack factor and a triereme that has an attack factor of one but no transport capability. All other factors of both ships are the same.

Civs with the seafaring trait built the transport unit very early in the game and in higher numbers. Other civs tended to build the triereme but later in the game and in small numbers. When in CCM in the mid of era 1 there was a ship available with a bombarding capability but no transport capability and an attack factor of one (and not very expensive) all civs did build that ship, what should I say - the AI loved that ship.
 
What? You are referring to shield cost of a unit? Someone did a test showing the AI will build more expensive units more often, as far as to what degree, I am not sure, I'd have to dig through the post and find it. (I thought you did that test, actually :lol: )..

Most likely, although a long time ago in a galaxy far, far away ... :)

What I meant was that the AI doesn't perorm any sort of cost/benefit analysis. Personally, I cannot think of any reason to set up a force pool which would have the AI choosing a unit simply because it's the costliest. Although (as is usually the case) I certainly don't mind being proved wrong :king:

Is MF move points you are talking about or something else? I forgot what the lingo stands for? How fast a unit moves will make the AI build that unit slightly more often, but it is not a huge factor (i think it was a 2move unit was built 10% more often than a 1 move unit, with all else the same).

"MF" = "Movement Factor" a.k.a. "Movement Points". And your test results sound about right.

Best,

Oz

EDIT / P.S. There's a handy online combat calculator HERE.

-O.

P.P.S. I'll have a closer look at the links in post 510 tomorrow (it's been awhile). All in all, fine work, gentlemen :thumbsup:

-O
 
Thanks Tom, both for testing my unit list and for the summary of what is known. I appreciate it greatly.

I put those units together quickly but what I want to create is:
1. a basic infantry unit (built most, cheap and not very strong)
2. an archer unit (built almost as often as infantry, similar to the infantry, a little more expensive, and slightly better for Def and Off becuase of bombard)
3. an elite infantry (built much less often, and more expensive)
3. cavalry (also elite, built the least often, most expensive)

I don't like the idea of defensive units. In modern times it makes more sense I guess. But Ancient and Medieval units were usually used to defend and attack. The same infantry and archers were attackers and defenders. Cavalry are slightly different in that they aren't much good defensively in most siuations.

Also as I may undertake some tests myself. What method do you use to know how many of each unit is built? Do you simply record each unit built, in each city, each turn then calculate the percentage?

Cheers

Nick
 
Also as I may undertake some tests myself. What method do you use to know how many of each unit is built? Do you simply record each unit built, in each city, each turn then calculate the percentage?

That was my original approach (some of the earliest posts in this thread).

-Oz
 
Also, irrespective of Strategy flag, the AI will almost always assume that the highest DF unit is the best defender, and it will ALWAYS build (and allocate for defensive purposes (you are aware that, given multiple startegies, the AI will always assign each and every unit only one strategy, forever, yes?)

Now that you mention that, I just thought...
You know , since tests show little diff between having/not having BUILD OFTEN selected for Offensive/Defensive Land Units... that

all it could do is assign a unit a offense or defense AI strategy more/less often than normal. So it makes units be FOREVER offense, defense instead of random (AI strategy most likely) more often than normal. It is possible, stranger things have happened with the editor!

Marine.jpg

So the build often may not effect AI builds for off/def land units??

Now for Naval Powers, transports, etc... these AI strategy's cannot be changed since they can only do 1 (most of them). So it should effect these, and appears to.

Tom
 
Tested approx. 45 turns:
Egypt - Build Often: Off land
Rome - Build Often: Off land and Def Land
everything else the same. mid aggressive, culture mediterranean

all flagged as offensive
Spear unit A2/D3/M1 cost 8 shields
Archer unit A2/D2/M1 range 0, bombard 4 cost 12 shields
Sword unit A4/D3/M1 +2 HP, ZOC cost 18 shields
Cavalry Unit A5/D3/M2 cost 22 shields

ROME:
Spear: 0
Archer: 0
Sword: 24
Cavalry: 386

EGYPT:
Spear: 3
Archer: 0
Sword: 31
Cavalry: 376

Here's a good Unit Test scenario I through together... you can mess around with unit values to try to get the builds you are looking for. Just change spearman, archer, swordsman, and horseman values and test, everything is already setup. Marines are placed in cities so it doesn't muck up results from AI building cheapest units first as defenders.

View attachment UnitTest2.zip

I don't like the idea of defensive units.

Try flagging all these units with both off and def, I believe the AI will force units to defense if no unit is flagged as defense.

Tom
 
My thoughts on the dreaded BUILD OFTEN flags: (no solid proof on these)

Off. Land Units - (may effect AI strategy decision, may effect AI to build Transports)
Def. Land Units - (may effect AI strategy decision, may effect AI to build Transports)
Artillery Land Units - (may effect any ground unit with off. bombard ability, may effect AI strategy decision) NOTE: ground units can have off, def, and arty flag all checked, which gives the AI strategy decisions of: offensive, defensive, artillery, or random (AI has to pick one of them, which it keeps forever for that unit for the rest of the game, says Oz :) )
Settlers - (should make AI build more units with AI strategy 'Settle' Flag checked)
Workers - (should make AI build more units with AI 'Terraform' strategy enabled)
Naval units - (seems to make AI build only 'NAVAL POWER' units more often, not 'transports/carriers') <- can be tested, I believe transports are affected by off/def land units, and carriers are affected by air units build often flags, not by naval units!
Air units - (seems to work as one would think, more air units of any type, also may effect AI building more carriers, since carriers don't seem to apply to naval units above)

NOTE: 'Other Characteristics' on 'Improvements and Wonders' tab SHOULD NOT apply to the below (which are the Civ Bonuses, and the help file says they are for peacetime golden ages)
Growth - (?? AI builds buildings more often that have doubles city growth rate, allows city size level 2, allows city size level 3, increases food in water, or city growth cause +2 citizens flags selected?)
Production - (AI builds buildings more often that have a value greater than 0 in the Production box, increases shields in water, reduces corruption ?)
Happiness - (any building with a value in the Happy/Unhappy Faces selection. +50% Luxury Output???Anyone know what this does?, Reduces war weariness?, Reduces war weariness in all cities?)
Science - (any building that gives +50% to research output, doubles research output)
Wealth - (capitalization)
Trade - (50% tax output, reduces corruption?, increase luxury trade, allows water trade, allows air trade, increases trade in water, +1 trade in each trade-producing tile, some others maybe)
Explore - (any unit with the Explore flag checked)
Culture - (any building with a value in the culture box?)
 
@Tom:

(1) "So the build often may not effect AI builds for off/def land units??"
(1a) "Try flagging all these units with both off and def, I believe the AI will force units to defense if no unit is flagged as defense."

-Those are my beliefs.

(2) I'm not certain I'd even bother to test artillery builds, given how inept the AI is with them (the best workaround I know of is to have "organic" artillery in units, where AF = Bmbrd Strength).

(3) "Naval units - (seems to make AI build only 'NAVAL POWER' units more often, not 'transports/carriers') <- can be tested, I believe transports are affected by off/def land units, and carriers are affected by air units build often flags, not by naval units!"

(4) "Air units - (seems to work as one would think, more air units of any type, also may effect AI building more carriers, since carriers don't seem to apply to naval units above)"

(3) & (4) should make for some interesting tests.

Tom, I'm very happy to see you pick these lines of inquiry :thumbsup:

Best,

Oz
 
(1) "So the build often may not effect AI builds for off/def land units??"
(1a) "Try flagging all these units with both off and def, I believe the AI will force units to defense if no unit is flagged as defense."

Well, in my quest to get the US to build warships in Rocoteh's WW2-Global (which I could not achieve last year, but got US to build them like mad crazy recently), initially the US had BUILD OFTEN for off/def land, naval, and air: and US rarely EVER built any warships except for maybe 3 or 4 in the first 2-3 years of the game. I was just testing different settings, and when I took BUILD OFTEN naval OFF, and left the other 3 on, the US would build about 6-7 transports in the first year and an occasional carrier (still rare).
When I tested with Japan, and set them only to off/def and air (took off naval), they would pump out transports and carriers like crazy, with fewer Yamamoto's (although they still built many battleships also) which usually doesn't happen EVER.
Same with Britian, and they still made lots of battleships, but made 3x as many carriers (which was always very rare to ever see them make one, and made hordes of transports).
When I tested all with Naval Power on, Britain and Japan would go back to almost only making Battleships all the time. So there isn't really much else of an explanation ??

Transports do in a way directly relate to ground units, same as carriers with air, so I guess it could make sense (in a strange arcane Firaxsis only kind of way).

(2) I'm not certain I'd even bother to test artillery builds, given how inept the AI is with them (the best workaround I know of is to have "organic" artillery in units, where AF = Bmbrd Strength).

I agree, I was testing some units (to give Tank Destroyers a difference from Assault Guns), but when I gave Assault Guns Off/Def/and Artillery capabilities, AI would often keep many of them bunched up in cities and do nothing with them (like they usually do with artillery) and very very very very very rarely would one launch a shot. Organic artillery is really the only way to go, as you stated, for consistency.

(3) "Naval units - (seems to make AI build only 'NAVAL POWER' units more often, not 'transports/carriers') <- can be tested, I believe transports are affected by off/def land units, and carriers are affected by air units build often flags, not by naval units!"

Now as far as a Naval Power ship with transport capability, not sure how AI views this. But I will say one thing, doing that will make AI build ships like a mad crazy maniac, that is how I got US AI to build ships in WW2-Global. So having a Naval Power ship also with ability to transport an aircraft, will make them build more (although it doesn't work as well as transport ground units it seems). One way to coerce AI to build ships in scenarios that don't use aircraft.

Tom
 
Did anyone test how the flags the AI heavily favours can be used to motivate it to produce inferior units?

It has been a while since I read all the way thru this thread, so I can't remember if anyone mentioned 'detect invisibility' as a way to get the AI to build inferior units.

I did a test with 3 AI civs and they had access to the warrior, spearman and the swordsman and nothing else. Took away the iron requirement and the warrior upgrading to the sword and all 3 had their normal stats and shields, except the warrior had detect invisibilty. The sword had offense flage, spear had defense flag and the warrior had both offense and defense flags.

Ran the test to 1000 BC and the AI built these numbers(averaged out)-
Sword- 13
Spear- 9
Warrior- 10


Ran a second test with the sword and spear with both att and def numbers doubled and both got +1 hp.
Sword- 8
Spear- 19
Warrior- 4

So, the AI had a unit with an attack of 6, a unit with a defense of 4, both with +1 hp and they still built several 1-1-1 warriors!! Maybe 'detect inviso' can be used to motivate the AI?
 
Back
Top Bottom