AI changing strategy Flag?

Predator145

Prince
Joined
May 22, 2020
Messages
459
Recently Ozy made a claim about the AI changing a unit's strategy flag based on its combat values. I would like to dispute that. His point was:

"The AI will change a Unit's strategy as it sees fit (and I'll get the shorthand version of AI build choices together, one of these decades.) Example: the AI will re-flag a 1-9-1 Unit, flagged Offensive, to Defensive, almost certainly. (If you're impatient for my summary of AI Flag Preferences and Combat Values, you can start Here, at the very beginning.)"

The AI will use Offense flagged units to garrison cities if they don't have enough Defense flagged units available. But once they do, your 1/9/1 units will be sent to the front where they may even be thrown into very bad odds. However, most of the time they will just enter your territory, be a nuisance, disrupt workers and even pillage. They can also serve the AI's line of sight enabling stealth bombard, esp with the unit ability radar flagged.

But I doubt the AI has reflagged anything. These are still offensive units no matter what their stats are.

If air units if you give an Air Defense flag unit 0 atk stats they would still suicide itself trying to intercept. For sea units if you give a Sea Power flagged unit 0 atk stat you will ensure that it will never attack and only bombard or float around providing LOS (both very useful). For land units they would not suicide attack and thus never do so. They'd still move into your territory and I believe if they have the Capture special order they could still pop your workers. But by having zero atk you make sure they will pillage.



The Nip Inf has been modded into paratroopers with 0 atk and every city improvement has been given the vet air units flag. The AI promptly paradropped some of them into enemy territory and pillaged since they would never attack at 0 atk value. This also shows that the AI can use paradroopers well with their low atk value and Offense flag. Unfort., in stock game, due to that low offense value, the AI would almost never make them. Perfume/auto production can change that. Also, Offense flagged explorers with 0 atk would be very potent in AI hands. It's very much worth 20 shields to pillage a border roaded tile.

Screenshot (1018).png




Screenshot (1015).png


But most of them still stayed garrisoned in the cities. But so were the light tanks who were flagged as Offense.

Screenshot (1016).png


In conclusion, the AI will use Offense flagged units for pillaging and garrisoning. But this is not them changing the unit's strat flag. I don't think they're capable of that.
 
Extensive testing suggested otherwise:
Spoiler [URL='https://forums.civfanatics.com/threads/the-big-question-how-does-the-ai-choose-which-units-to-build.62138/page-3']The Test[/URL] :

PLEASE have a look at this an offer any comments in the next day or two – this first step is the cornerstone from which I'm hoping / planning all future experiments to proceed ...

Game Conditions & Settings Test Round 1

The purpose of this round is to evaluate the AI selection among 3 types of units, each roughly equivalent: each unit has an Attack and Defense = 4, 5, or 6. Combined Attack + Defense for each unit = 10. All units move 1. Conditions (read below) have been set to make this test as absolutely "vanilla" as possible.


1. There are three Civs. Each Civ has three cities and begins with no units.
2. Each city begins at size 1.
3. Cities are limited to a maximum size of 4.
4. Each Civ is limited to one Gov type, Despotism modified to Communal corruption and no tile penalties. All units are free, no units may be rushed, and war weariness is none.
5. No Civs have been given any bonus traits (Commercial, Expansionist, etc.)
6. Aggression for all Civs has been set to 3".
7. All Civs have been made members of different cultural groups.
8. All terrain is plains which produce 1 food and nothing else.
9. There is one bonus resource which provides 20 gold; one of these is available for each city.
10. Standard victory conditions are in use.
11. For this round, three unit types exist Warrior (A/D/M = 6/4/1) Archer (5/5/1) and Swordsman(4/6/1)
12. All units cost 20 and do not require support.
13. EDIT: No Civ AI strategies have been checked (e.g., "Build Often"; etc.); unit strategy flags for all three unit types have been set to both "offensive and "defensive".
14. Victory Locations have been added: 1 in each capitol, and three in the center of the landmass
15. Number of citizens born content = 3; number of citizens quelled by military = 1.
16. Level of play = Regent.
[...]
"4. Units flagged as "defensive" by the AI were at times used aggressively for offensive purposes -- i.e., marched a long way from home to attack my cities (sorry, I didn't tally the breakdown of offensive vs. defensive assignments by unit type – but it hardly seems necessary given the identical proportion of 4/6/1s built by the two AI Civs; of course I'll also be the first to admit that determining a meaningful statistical threshold
I ran the "experiment" described above for 20 turns. The only change was that I upped production so each city would produce 1 unit per turn.

Recall that the three types of units were:

"Warrior" A/D/M = 6/4/1
"Archer" A/D/M = 5/5/1
"Swordsman" A/D/M = 4/6/1

All units were flagged both "offense" and "defense".

I was Roman (north center of map) with Greeks to my southwest and Egyptians to my southeast.

I let the Governor make all "my" build decisions. I also let peace reign for 8 turns before starting simultaneous wars which I waged more aggressively against the Egyptians.
[...]
Results:

I. Peacetime builds = first 8 turns (each Civ = 24 units total):


Ia. Romans = 24 Warriors

Ib. Greeks = 6 Warriors, 5 Archers, 13 Swordsmen

Ic. Egyptians = 12 Warriors, 1 Archer, 11 Swordsmen

II. Wartime builds = next 12 turns (each Civ = 36 units total):

Ia. Romans = 36 Warriors

Ib. Greeks = 14 Warriors, 8 Archers, 14 Swordsmen

Ic. Egyptians = 13 Warriors, 7 Archers, 16 Swordsmen

III. Total builds = 20 turns (each Civ = 60 units total):

Ia. Romans = 60 Warriors
( 100% Warriors )

Ib. Greeks = 20 Warriors, 13 Archers, 27 Swordsmen
( ~33% Warriors; ~22% Archers; ~45% Swordsmen )

Ic. Egyptians = 25 Warriors, 8 Archers, 27 Swordsmen
( ~42% Warrirors; ~13% Archers; ~45% Swordsmen )

Lessons, Observations, & Best Guesses

1. Never let your governors do all your building for you :)
2. Fully "balanced" units (the 5/5/1s) were a minority choice, although the spread narrowed ... significantly? ... in wartime.
3. Romans aside, there was a slight-to-slightly significant preference of 4/6/1s over 6/4/1s.
4. The identical Civ and unit settings for the Greeks and Egyptians, as well as their essentially identical strategic starting positions, indicates (i) that there is some randomness in the choice the AI makes to build units (i.e., the Greeks building nearly twice as many archers as the Egyptians overall – and 5 times as many during "peacetime") and (ii) there is a slight preference given to defensive over offensive capabilities ...
4. Units flagged as "defensive" by the AI were at times used aggressively for offensive purposes -- i.e., marched a long way from home to attack my cities (sorry, I didn't tally the breakdown of offensive vs. defensive assignments by unit type – but it hardly seems necessary given the identical proportion of 4/6/1s built by the two AI Civs; of course I'll also be the first to admit that determining a meaningful statistical threshold is most definitely open to question!)

... And there more "verification" tests after that ...
 
"Recall that the three types of units were:

"Warrior" A/D/M = 6/4/1
"Archer" A/D/M = 5/5/1
"Swordsman" A/D/M = 4/6/1

All units were flagged both "offense" and "defense".

You flagged them as both in the editor? This makes it even murkier.

The AI is known to move Defense flag units out and attack if the odds are good enough. We've all seen waves of hoplites marching into our territory when fighting the Greeks. But that doesn't disprove that they've changed the flag themselves. Those 0/10/1 Nip Infs I tested went on the offensive and as more MG Btln were built, they all moved out. It's the same for warriors. At first, the AI garrisons them to not have empty cities. But as they make more spears the warriors leave the city to barb hunt.

I think the swordsmen you see attacking you were simply flagged as Offense. When you have more than 1 flag in the editor the AI would choose 1 to build the unit and then stay with that flag till the end. That's why you have multiple versions of them in the building queue when playing on debug. I doubt the AI plucked one it built with the Defense flag and reassigned a new flag based on stats. If it could do that then it wouldn't go on the offensive with 1/10/1 or even 0/10/1 units or suicide 0/10/1 air units when having the Air Defense flag.
 
Last edited:
Does AI strategy change after upgrade?
Let's say we got unit A and it have only offensive strategy, and it upgrades to unit B which have defensive strategy. How it would work? Would unit retain initial strategy or it would be re-defined?
 
Does AI strategy change after upgrade?
Let's say we got unit A and it have only offensive strategy, and it upgrades to unit B which have defensive strategy. How it would work? Would unit retain initial strategy or it would be re-defined?
The AI will change its strategy as flagged.

This is a great tool for king ability units. Let's say I want the AI to make more air defense units. But if you flag them as Offense or Defense they would almost never get made because of how low their stats are compared to regular offensive and def units. But if you flag the Flak/SAM units as Flag Unit/Explore/King and perfume in the C3X config sheet so that they will build them they shall do so. Then if you wish these units to be used as Offense/Defense/Artillery have them be upgraded into identical units but with the king ability. Remember to do this in the config sheet: ignore_king_ability_for_defense_priority = true. The AI will a barracks in the city will then upgrade these Flag Unit/Explore/King strat units into Offense/Defense/Artillery and use them outside of their cities.

Personally, I don't like anti air units to be used as defense by the AI. Because the AI is often content with just 2 units guarding a city it you could easily end up with just 2 flaks fortified. AA units intended for city defenses are best left unupgraded in Flag Unit/King form where they will stay fortified in the city forever. For field escort either offense or artillery will do. You can have your king ability unit flagged as both. Offense will be part of the attacking unit stack so if they're mobile SAMs they could keep up with 2 movers. Artillery will behave like the usual C3X style (I assume you have this enabled) and the AI will take a defense unit to escort the AA unit and be part of their artillery SOD. Personally, I have AA units modded into having bombard ability and have their defenses lowered. That way they can provide AA cover and still contribute to the ground war. And it's a bit more realistic too. An Flak/SAM battery can bombard from a far (even SAMs like the S-300 have been used for ground bombardment) but not hold ground like infantry.

The same "upgrade into identical king ability unit" trick can be used for many other things.
 
The AI will change its strategy as flagged.

This is a great tool for king ability units. Let's say I want the AI to make more air defense units. But if you flag them as Offense or Defense they would almost never get made because of how low their stats are compared to regular offensive and def units. But if you flag the Flak/SAM units as Flag Unit/Explore/King and perfume in the C3X config sheet so that they will build them they shall do so. Then if you wish these units to be used as Offense/Defense/Artillery have them be upgraded into identical units but with the king ability. Remember to do this in the config sheet: ignore_king_ability_for_defense_priority = true. The AI will a barracks in the city will then upgrade these Flag Unit/Explore/King strat units into Offense/Defense/Artillery and use them outside of their cities.

Personally, I don't like anti air units to be used as defense by the AI. Because the AI is often content with just 2 units guarding a city it you could easily end up with just 2 flaks fortified. AA units intended for city defenses are best left unupgraded in Flag Unit/King form where they will stay fortified in the city forever. For field escort either offense or artillery will do. You can have your king ability unit flagged as both. Offense will be part of the attacking unit stack so if they're mobile SAMs they could keep up with 2 movers. Artillery will behave like the usual C3X style (I assume you have this enabled) and the AI will take a defense unit to escort the AA unit and be part of their artillery SOD. Personally, I have AA units modded into having bombard ability and have their defenses lowered. That way they can provide AA cover and still contribute to the ground war. And it's a bit more realistic too. An Flak/SAM battery can bombard from a far (even SAMs like the S-300 have been used for ground bombardment) but not hold ground like infantry.

The same "upgrade into identical king ability unit" trick can be used for many other things.
That's interesting. AFAIK there's similar approach in CCM. Some building auto-produces some "basic unit", with offensive flag (to make AI upgrade it? Would AI ever upgrade units without offensive/defensive flags?) and immobile, which upgrades to other units that AI has to use more often.
But I don't understand, what King flag actually do?
 
But I don't understand, what King flag actually do?
It makes a unit available to a tribe via upgrades, but unbuildable using shields.

(Without the Flintlock patch "Ignore King-ability" function activated in the config file) It makes a unit(s) into the "last defender(s)" within a stack -- even if that unit(s) has the highest D-value(s) of all units in the stack.

And if you switch on the basic "Regicide" mode in the game rules when you start a game, losing any King-flagged unit will cause you to lose the game.
 
That's interesting. AFAIK there's similar approach in CCM. Some building auto-produces some "basic unit", with offensive flag (to make AI upgrade it? Would AI ever upgrade units without offensive/defensive flags?) and immobile, which upgrades to other units that AI has to use more often.
But I don't understand, what King flag actually do?
The AI will upgrade anything as long as they have enough cash and the needed city improvement.
 
Top Bottom