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

@Everyone -- Many thanks for all insights, help, encouragement, etc. :)

Re: "methodology" questions in general: I think trying to reverse engineer whatever algorithm(s) the AI use(s) is effectively impossible -- there are simply too many possible variables. For example, Arathorn correctly points out that war conditions will ... probably? ;) ... change what's built.

So I suggest we focus our collective efforts on whichever situations vex or enlighten us re: our own modding efforts. This will of course require some subjective calls -- and from my POV doesn't necessarily rule ANYTHING out, especially after Test #4!

Example -- Re: Test #4 & mrtn's suggestion re: the random seed -- randomness in the AI's builds have been "proven"; from my POV; I'm not certain what can be gained by re-running the test :confused:

-- BTW re: Arathorn's kind request, here's the .bix! It's simplicity itself; stats are still set for Test #4. Note that there are a handful of techs labelled 1-9 which are simply placeholders.

Also note that in my testing I wasn't "playing" per se -- I neither conquered nor allowed the AI to conquer cities or resource tiles.

My own next test is going to be based on "Conclusion #1" -- or perhaps "Rule #1" sounds better, or is at least shorter to type:

AI Build Rule #1

Everything else being equal, the AI 90+% of the time weighs Attack and Defense factors equally.


... Agreed? -- I know it hardly sounds earth-shattering, but it's definitely a firm foundation upon which to start. Note that, for tests 1-3, the combined A + D = 10. I'm hoping to wind up with a +/- 10% value for everything we deem worth testing and thereby a "Combat Equivalence Factor" for each attribute, with (A=1) or (D=1) equaling one CEF. So -- keeping our critical 5/5/1 O/D unit as the benchmark -- the answer to the question "What's an extra MF worth to the AI?" can be answered in CEFs.

... Comments / critiques?

BTW my use of 20 turns has been geared toward what "feels" like a reasonable sampling -- enough time for the AI to poke around, get prodded into war, etc. -- as well as simple sanity: it's a BORING test :crazyeye: ... mais c'est la guerre ...

My own next test is going to be trying to see what combinations of (A + D < 10) the AI will build for MF=2 vis-a-vis the benchmark 5/5/1 -- and therefore how many CEFs MF=2 is worth.

If anyone else runs any tests (hint, hint!) PLEASE post both the criteria and results!

All The Best,

Oz
 
Oz,

maybe I missed it but were the agression levels the same for all three of your civs? Has anyone tested to see if this has any effect on offensive v.s. defensive unit production. Also interested to hear if mobility effects production choices.
 
Originally posted by davbenbak
Oz,

maybe I missed it but were the agression levels the same for all three of your civs? Has anyone tested to see if this has any effect on offensive v.s. defensive unit production. Also interested to hear if mobility effects production choices.

Yep -- varying Civ aggression level is slated for later on; mobility is my next test.

The point so far has been to establish a baseline from which to test -- so far I think "Rule #1" above qualifies: simply put, from the AI's POV, with all other things being equal, 1 AF = 1 DF as a matter of "preference".

Utilizing the 5/5/1 marked both "Offensive" and "Defensive" as the benchmark, I suspect the general evolution of the tests will be as follows -- all with an eye towards seeing what the AI will view as equivalent, and at the same cost as, the 5/5/1:

1. Mobility (my next test)
2. Artillery (may I suggest that anyone having particular difficulty with the AI building artillery give this a go?)
3. Unit flags
[note that these three should/shall also work with O/D flags as required]

THEN we test preferences vis-a-vis AI aggressiveness and build preferences ...

... Or so I think -- it's a "work in progress" ;) Nothing's set in either stone or electrons ....

Welcome Aboard,

Oz
 
i love this thread. on my old mod i had drastically increased a/d and costs. Motorized units became substantially more expensive than the foot units and the AI never built them. I just this week started from scratch and am slowly incrementing stats to see when the AI stops building fast units. I'm really interested in the multiple resource theories. All my modern units require 2 or 3 resources and the unit the AI always builds requires none.
 
In ACW, AI (with one exception) will never build more
than 2 type of units at a given time.

The exception is that AI have started "cheating" and now
produce Leaders at one city. The Leaders are then converted
to Army-type units.
One can notice that AI is very slow in filling these Army-type
units with combat units and sending them to the front.


Rocoteh
 
Originally posted by Rocoteh
In ACW, AI (with one exception) will never build more
than 2 type of units at a given time.

Thanks! :) Now that I think about it, in the testing I've done so far, even though (i) each Civ had three cities (ii) most tests involved three unit types, the AI Civ never did build more than two types of unit per turn, even when the rough distribution of production of 20 turns was ~33% per unit type.

-Oz
 
This most recent test (#5 in a series) wound up being three parts -- so far ... :cringe:

Throughout Test #5, each part used two units, the 5/5/1 which I was hoping could be a "benchmark" unit, and a cavalry unit, with the intent being to try to ascertain how the AI weights an extra MF vs. A/D factors.

Test #5, Take 1

Instinct and reading others' tales led me to make the first Take use the benchmark 5/5/1 and a 3/3/2, both O/D, all stats identical. I expected this to be a little bit low for parity, but I thought I'd be in the ballpark ...

Recall that each "Test" or "Take" involves 3 cities, 20 turns, therefore a total production of 60 units per Civ.

Romans (Player with AI Governor) = 60 5/5/1s = 100%
Greeks = 44 5/5/1s (73%) and 16 3/3/2s (27%)
Egyptians = 47 5/5/1s (78%) and 13 3/3/2s (22%)

Test #5, Take 2

Take 2 utilized the benchmark 5/5/1 (of course) and a 4/4/2.

Results:

Romans (Player with AI Governor) = 60 5/5/1s = 100%
Greeks = 42 5/5/1s (70%) and 18 4/4/2s (30%)
Egyptians = 36 5/5/1s (60%) and 24 4/4/2s (40%)

Test #5, Take 3

Take 2 utilized the benchmark 5/5/1 (of course) and a 5/5/2!.

Results:

Romans (Player with AI Governor) = 8 5/5/1s (13%) and 52 5/5/2s (87%)
Greeks = 30 5/5/1s (50%) and 30 5/5/2s (50%)
Egyptians = 21 5/5/1s (35%) and 39 5/5/2s (65%)

:confused:

1. Re: Take 1: except for the usual monotonous Player AI Gov, I wasn't terruibly surprised ...

2. Re: Take 2: I was surprised that the % of AI builds for the 4/4/2s (i) was effectively the same as the % 3/3/2s for the Greeks and (ii) nearly double for the Egyptians.

3. Needless to say, my expectations for Take #3 were of course that the AI would build ~100% 5/5/2s ... again this was one I almost didn't run, except I guess the ex-programmer within me was insisting upon some sort of methodical, binary-search-type approach.

So frankly I'm confused and would like some advice --

Do I:

1. Bother continuing (that Take #3 ...)
2. Continue and try to "fine-tune" with the cavalry being 5/4/2 or 4/5/2.
3. Utilize a different "CEF" equivalent for the MF=1 unit (say, a 4/6/1) and label it "Defensive" only and the MF=2 unit "Offensive".

-- Of course, there is the (to us modders) the ghastly possibility that the AI build algorithm(s) are tightly bound to the rest of the game -- i.e., they only work within the context of the designers' expectation that only a very limited number and type of units will be available at any one tech level / point in time ... Which would also explain why (i) Nobody at Civ HQ has ever given us any clue as to how the AI engine works re: builds (ii) why reverse-engineering this to any degree is so ... "interesting" ...

If this is the case, this means that all mods will have to experiment with what might seem absurd relative cost values for, e.g., ships in the ACW mod.

Perplexedly Yours,

Oz
 
What made me almost fall of my chair was seeing that the only way you've managed to provoke the Governor to build more than one unit is by providing two units where one of them is simply superior. Why in seven kinds of CENSORED could be the reason for such CENSORED stupid behaviour?

Possible partial explanation: the AI first decides whether it wants an attacker or defender (or artillery piece or party girl or whatever), and then choses, among the units with the appropriate strategy flagged, using an special algorithm for each kind of unit. If the algorithm for defensive units ignores the movement allowance (which'd be stupid, but not CENSORED stupid), one could get results like what you've got - when building a defender, the AI'd chose randomly between the two units.

Suggestion: try fooling around with the strategy flags on those two units. You could also see what happens if you add the Explore flag to either.
 
Originally posted by The Last Conformist
Suggestion: try fooling around with the strategy flags on those two units. You could also see what happens if you add the Explore flag to either.

Your sugestion makes excellent sense. The challenge is (i) to keep the MF=1 unit at the AF + DF = 10 with that unit being flagged "Defense"; presumably (ii) this unit should have a higher DF than AF; and (iii) the MF=2 Attack unit has to be able to at least take on the Defend unit at even odds ...

If methodologically "true" this suggests that the MF=2 unit has to have an AF => 6 with (AF + DF < 10).

So I guess I'll first try a 4/6/1 Defender and a ... 6/2/2 Attacker??

-Oz
 
Originally posted by alpha wolf 64
are you planning on testing the 5/5/1 v 5/5/2 but with the 5/5/2 increasing in cost to see when the AI decides its not worth building?

If need be. Again, my hope was to discover some essential equivalence: keeping the cost the same, how much of a tradeoff the AI would make for each additional attribute: MF, special flags, etc.

Given the admittedly rudimentary discovery that AF and DF seem equivalent, it only seemed/seems rational that the AI would be willing to sacrifice some amount of A/D for additional abilities.

During the next test(s) -- whatever they precisely prove to be -- I'd like to keep costs equal and the "baseline" comparison a 1MF unit with A+D=10.

Given the immediate problems posed -- i.e., WTF would the AI produce any 5/5/1s instead of 5/5/2s with identical flags and cost -- this could be a limited exercise.

I do believe I'll try the 4/6/1 "Defensive" with the 6/2/2 "Offensive" next; theoretically, I would think / imagine / hope that the 6/2/2s ability to retreat would make it a worthwhile bargain, despite the "defensive" units' ability to attack at 4:2.

BTW, should the test I just describe prove unenlightening, I'll try tweaking the "Attack" unit; my concern would be to discover that -- under what seem to me to be reasonably controlled circumstances -- the AI would only value +1MF as = 1A or 1D ...

-- But, yes, I imagine that experimenting with cost will have to come sooner rather than later if some basic equivalence measuring the "worth" of +1 MF vs. some amount of A/D -- and assigning each unit in the test only one strategy -- fails to shed any further light on the matter.

Best,

Oz
 
With regard to what has been written in this thread and
what I have found out working with ACW,
one can only hope there will be a AI with a more "broad"
build-strategy in future CIV-expansions.

I had to reinstall, install 1.27f etc. and due to that my
personal mod. refuses to load. I guess I have start from
scratch again. One thing is clear: I will check AI build-
strategy very close, when I have started the new mod.!!!

I hope you will continue to work with this thread. Its one
of the most interesting.

Rocoteh
 
Originally posted by Rocoteh
I hope you will continue to work with this thread. Its one
of the most interesting.

Thanks! -- And, fear not, I'm not planning on giving up anytime soon :)

As I see it, the worst case is that we'll discover that there AREN'T "build rules" per se -- or, more precisely, as I fret in an earlier post, that they're tightly bound to conditions which we, as modders, would by definition like to change.

-- If so, then it nevertheless remains an algorithm set, and the task becomes to discern how to best fool it into getting it to behave as we wish ... And I already have some ideas along those lines ...:mischief:

More to follow --

Oz
 
It just hit me that someone ran a test of how military strength is computed.

Some searching turns out that this someone was Oysten in this thread, and that the result was that unit strength is considered to be proportional to (3*A+2*D)*HP+B. Arathorn suggested he take a look at this thread, but if he's done so he's not commented on this issue.'

Now, my idea is that a similar formula could be used for chosing among units - of course, some sort of allowance is then presumably made for cost and flags, as well as MF.

In the present form, the formula clearly doesn't square with Rocoteh's results with units with a defensive bombard, which makes me suspect that the bombard strength should be multiplied by the bombardment range, and quite possibly also the RoF. (Oystein apparently only tested with those at =1.)

An alternative to my suggestion in post #89 could be that the AI calculates a "usefulness score" for each unit it's able to build, and then assigns each unit a proportional probability of being built. This would allow the AI to do without any "strategic planning" for what kinds of units it builds - even if a 3.1.3 attacker would have the highest "usefulness score" it would get some 1.2.1 defenders built.
 
In the test 5 you did, I just wondered whether military strategy choices would be hidden civ traits.
This choice could be linked to the type of UU each civ has.

For instance : Egyptian have a chariot (fast unit) while Greeks have hoplite (slow unit). It might explain why Egyptians have higher numbers of fast units than the Greeks. Of course if it works well for take 2 and 3 it does not work with take 1. Maybe because it goes below a certain level of interest.

My explanation might be stupid but it could be one of the elements.

So far if I am not wrong we know already there is :

- a formula to calculate the value of each type of units including cost, attack, defense and probably movement "edit : usefullness of Last Conformist"
- a residual build of most units (even if underpowered by comparison to the other ones).
- a preference for fast units over slow ones (atta/def factors being equal)
- (maybe ) a military trait giving them a special strategy.
 
Lou, I don't think the AI cares about it's UU in that way, as that would be really stupid programming. I reason that they probably started with the AI before deciding such small stuff as UU's. Besides, what if you want to change the American UU from Minuteman to F15? Do you reprogram the AI then?
 
Originally posted by The Last Conformist
Some searching turns out that this someone was Oysten in this thread, and that the result was that unit strength is considered to be proportional to (3*A+2*D)*HP+B.

Nice find! -- If nothing else, it gives us some insight into how the design team was working.

Oystein's post in the thread The Last Conformist cites reads:

Originally posted by Oystein
I have done some more testing.

I have mostly tested how many catapults I need to have a strong/average army compred to a single regular attack/defence unit.

The unit stregth is (3A+2D)HP+B
A - attack strength
D - defence strength
HP - helth point
B - bombard

Then, the total armystrength is sum of unitstrengt + 4
The +4 is probably an easy way to get rid of divison by 0 for civs without any units.

My superspeed chariot 1.1.100 was no better than a warrior.
I have just test HP a few times, needs more.
I have not tested bombard rate/range, combination of bombardstregth and attack/defence.
4 catapults is just sligtly better than 1 regular warrior.

... So, if there is any correlation between strength computation & the build algorithm(s):

1. Speed of the unit is meaningless (!)
2. HP is meaningful
3. Arriving at a relative value for bombard units is problematic -- which would be in keeping with how haphazardly the AI seems to use these --

@Kryten (you there? :) ) Have you experimented any with A/D factors with bombardment units? -- Just curious. Should you do so:

(1) Beware the Jabberwock; and
(2) Recall The Last Conformist's admonition:

Originally posted by The Last Conformist

In the present form, the formula clearly doesn't square with Rocoteh's results with units with a defensive bombard, which makes me suspect that the bombard strength should be multiplied by the bombardment range, and quite possibly also the RoF. (Oystein apparently only tested with those at =1.)

@The Last Conformist --
Originally posted by The Last Conformist
An alternative to my suggestion in post #89 could be that the AI calculates a "usefulness score" for each unit it's able to build, and then assigns each unit a proportional probability of being built. This would allow the AI to do without any "strategic planning" for what kinds of units it builds - even if a 3.1.3 attacker would have the highest "usefulness score" it would get some 1.2.1 defenders built.

This makes intuitive sense (note that intuition based upon our collective gaming experience has generally proven correct :crazyeye: ) and I'll start pondering along those lines.

Thanks again to all!

-Oz
 
Originally posted by LouLong
In the test 5 you did, I just wondered whether military strategy choices would be hidden civ traits.
This choice could be linked to the type of UU each civ has.

For instance : Egyptian have a chariot (fast unit) while Greeks have hoplite (slow unit). It might explain why Egyptians have higher numbers of fast units than the Greeks. Of course if it works well for take 2 and 3 it does not work with take 1. Maybe because it goes below a certain level of interest.

My explanation might be stupid but it could be one of the elements.

Hi LouLong,

I've not witnessed you being stupid yet -- why would you start now? :D -- Indeed, the idea of "hidden" Civ traits is troubling, yet, before reading your post -- while reviewing the test results -- I had internalized it as "Why are the Greeks consistently building more 'conservatively' than the Egyptians?" I think it's the same question from a different angle.

*sigh* I see this might take a LOT longer than I had originally thought ...

Thanks YET AGAIN to all,

Oz
 
Originally posted by mrtn
Lou, I don't think the AI cares about it's UU in that way, as that would be really stupid programming. I reason that they probably started with the AI before deciding such small stuff as UU's. Besides, what if you want to change the American UU from Minuteman to F15? Do you reprogram the AI then?

Hi mrtn!

-- As I mention in an earlier post, I beginning to fear that the AI build algorithm set isn't some wonderful, relatively standalone set of functions but is more tightly bound to the game -- and, sadly, it wouldn't be the worst questionable design/programming practice/implemenation we've seen, from our modder's POV.

Interestingly / perversely, if Lou is correct, then changing a Civ's UU probably wouldn't change the sort of build behavior it's witnessed -- which might indicate that a test of "rebuilding" a Civ or two from scratch and comparing the results of one of the build tests where the Egyptians and Greeks vary considerably might prove to be a sad but necessary exercise ... *sigh*.

Best,

Oz
 
Top Bottom