Version 0.50 Discussion Thread

Thanks for the explanation about stack attack values.
 
Something that I'm noticing is that the AI is very bad at "panic" defense. The AI doesn't seem to grasp the concept that unless this attack is blunted or stopped, it's game-over for that AI.

Yep that is true and a good point. It is a complex problem. I have got a complete 0.5 autosave game of this type of situation if it is needed. The AI is not clueless about the importance of defense, just that it is too slow in some cases. The correct behaviour is there but it is not efficient either in time or space.

To chip away at the problem more simply, there does seem some obvious cases of AI weakness. In my reference save of this situation, the AI could at least underdefend coastal cities and bring those defenders into the area of acuteness. However it does not seem to do this. Even this behaviour is probably sufficient in 60% of cases.

The algorithm could be one where the AI builds up a repository of cities that can be underdefended if needed, and then at the first sign of major threat, expel those defenders and allocate them actively. This algorithm would not be a far digression from what is currently happening, but merely an efficiency improvement that might be good enough.

The difficulty is determining what cities can afford to be underdefended if needed...Coastal cities are the easiest candidates because a lot of the time, there is simply no threat path to the city. The point is to leave defenders in the cities as it is now, but to have them allocated as potential active defenders in the case of high threat.

Perhaps this is already happening in the AI. I use this type of algorithm in my own head as a human player all the time. All humans have to do this against the AI because usually we don't have as big a military capacity as the AI. I don't think it is an impossible algorithm to conceive and code.

Cheers.
 
I agree with all of that glider1!

Once paratroopers are around, the threatened cities could go a bit more in from the border, but those cities only threatened from paratroops on the current turn could use machine guns as efficient defense, while other defenders rushed to the threatened cities that are nearer the border.
 
On a side track:
Something that has always bothered me is AI land units "patrolling" (or just moving about), either within their borders or not, and not doing it on roads where available. Ending a turn on a road would GREATLY enhance flexibility should that unit actually have to get somewhere on the next turn.

I wouldn't mind if the same were to apply to the movement alg. for my own units, also. End the turn off a comm. route, have a change of need and it takes an extra movement just to get back on the road, toad.
 
It is, if I remember, a matter of paralysis. The extra defenders built during peacetime tend to get 'locked down' where they are relatively easily, rather than being routed to where they are actually needed.

Some thoughts.

1> A 'panic' defense level. Dropping troops below this level is never considered.

2> A 'standard' defense level. You can only breach this in the event of serious panic.

3> A 'comfort' defense level. Stock troops up to this level during peacetime in order to generate reserves. Coastal cities, boarder cities, etc have extra 'comfort' defense levels. Interior cities generate 'comfort' defense boosts in adjacent cities instead of locally (representing distributed reserves).

4> A 'threat' defense level. Boarders with not-so-friendly neighbors with lots of power. Boarders with civilizations you are at war with. Cities that see nearby units that are not 'peace bonded' by a treaty or the like. Cities that see hostile units that they are at war with.

Troops are taken from cities at "Panic" levels in the event of a serious panic -- a 'do or die' situation. A low-population, low-investment (few buildings), easy-to-retake, relatively unthreatened city can have a "Panic" level of 0(!).

In the event of a 'threat', troops are requisitioned from nearby 'comfort' garrisons -- threat trumps comfort. High-threat steals from lower-threat in proportion to the threat gap.

Comfort troops also 'flow downhill' -- a city that is at 50% of comfort buffer will steal a unit from a city at 100% of comfort level. Some bias towards not moving troops to preserve fortification bonuses should exist.

Now this is sort of similar to how the AI allocates troops as is. However, they only have 1 value -- the number of units that they want in a city, which pays no attention to how powerful the troops are. Below that value, troops refuse to move.

There isn't, as far as I can tell, a fuzzy 'move downhill' response to increased threat. Instead, the stack causes increased threat in all adjacent cities, which quickly causes paralysis as each city thinks that it needs to horde almost all of it's troops.

Cities further away from the front with spare troops don't see a need to route troops nearby: the cities near them aren't under threat, and are fully garrisoned. So you don't get a large-scale troop movement towards the war zone.

I think with something like the above, you'd have:
1> In the event of war, comfort troops would flow towards the border with the hostile enemy.

2> In the event of invasion, troops would flow towards the threatened cities.

3> Cities further away would notice the gaps in the comfort levels of nearer cities, and a flow of troops from the 'back woods' would start. It would peter out relatively quickly, sadly... but the flow would exist.

As an additional bonus, invasion forces can strip 'comfort' troops to generate an attack force.
 
Some good ideas here. Two loose thoughts and a different view on defence from me to make things more complicated. ;)

1) At the moment commando troops aren't too useful because the AI always keeps several units in a city and sacrificing lots of commando troops to a surprise attack is just not a good tactic as these troops are too hard to get. If cities would get 0 or 1 defenders because they are considered 'safe' by the AI, then this might change. So if you consider commando troops during the era of railroads in your definition of safe cities, then not a lot of cities will be considered safe.

2) The human might turn a city into a killing zone. It bombs city defences, kills the major fully fortified defenders and waits for the AI reinforcements from other cities and slaughters them with its city raider III troops as they slowly trickle into the threatened city.



My view is that you can't defeat a serious (human controlled) city attack stack by defending the city. You need to create a stack that can defeat the city attack stack. The combination of collateral damage plus the strong city raider promotions makes stubbornly defending a city an inefficient use of troops. A city with its inherent defence bonus is great in slowing down an invasion force, but it's awful in stopping it once this defence bonus has been bombed away. The only way to defeat a serious city attack stack is by using collateral damage as the defender combined with a serious force in well promoted units that are good vs troops in the field.

So in my view, the AI should garrison its directly threatened cities with a decent city defence force (4-10 units) just to make a direct attack without bombardment on the city extremely costly. Next to that it should have a reaction force spread over several cities which should group together in case of an invasion. Hopefully, the city defence is good enough to stall the city attack stack until the reaction force is assembled and can destroy the city attack stack.



So the AI needs several categories of units
- city defenders
- reaction force
- city attack force

Units should be able to switch back and forth from the city attack force and the reaction force depending on the momentum of the war.

The hardest part (I think) in this type of defence would be to let the AI define a tile where it should assemble the reaction force so that this force can counterattack the city attack force but not be attacked by the city attack force. As reaction force, you want to be the one who uses collateral damage, not the one who suffers collateral damage. This probably means that you have to define an area around the city attack stack which is threatened by this stack (mainly its collateral damage attackers) and pick a spot outside this area that still allows you to attack the stack in one turn (the defender should have the advantage of roads). If such a spot is not available, then assemble outside the threatened area and then move into the threatened area in force. The AI of course should have a way to determine which stack will win, so this would benefit a lot from simulated combat discussed in another thread.


As promised, I have made things more complicated. However, if the AI would be able to do this, then it would finally be somewhat capable to counter a human attack. And that would be the greatest achievement ever in all the AI improvements which have been made since Blake started improving the AI years ago.
 
The thing about Roland's suggestion is that it really does make war more a heap more interesting as well as improving the AI, if the AI would employ reaction stacks. Any algorithm has to be near perfect because it is really risky to underdefend cities somewhat and then make them vunerable to simultaneous attacks, just so that a reaction stack can be formed and deployed.

Maybe a merge of Yakk's systematic approach to moving defenders around from city to city, combined with Roland ideas of allocating some troops as a *potential* reaction stack is possible. It depends on an assessment of the attackers power again. Yakk's algorithm always comes first in AI defense. If it is continually improved, the efficiency of basic AI defense goes up. Then the "reaction stack" algorithm begins to be able to pull in more troops so that it becomes viable at some point in the development cycle. We could get to a situation where Yakk's algorithm is so good, that indeed there is enough capacity for a reaction stack to be formed and deployed, and even if it looses at 50% odds, the AI does not go down.

I don't know about other players, but the algorithm in my head when I play IS basically Yakk's algorithm continually honed through experience. At the same time I also am mentally employing Roland's algorithm, always making a mental note of suitable field attack units (characterised by promotion and type) that could be combined into a reaction stack. Those potential field units are mostly sitting inside a city and the routine in my head is to pull them out of cities in the region of threat. If the AI hits me hard enough, I have to resort to the Yakk algorithm in my head without exception, and indeed I too never form a "reaction stack".

We could do the same with the AI. The sad news is that the "reaction stack" algorithm is complicated, very risky, has to be one of the best algorithms ever written for civ, and would only ever get executed in situations where the AI has clear excess capacity for active defense.
Cheers.
 
A relevant question: Do AIs ever delay promotions?

For example, a unit that would normally take city raider should never do it until the turn it intends to attack its first city. I think this could create some funny surprises for the human player. :)

In other situations, city garrison troops in unthreatened citys should not be promoted either, until they are threatened. Remember that promoting troops does not take away the fortification bonus. When your enemy can see in advance what promotions you have they can prepare better (bad for you), so delaying your promotions makes it easier to react more effectively, and harder for your enemy to know what to expect. A human player can use these facts very effectively. Could an AI use them?

In own territory, perhaps AIs could even consider not promoting units before attacking if odds are high enough (like 98% or so), so it can use the promotion heal the immediately after battle instead. The reason I say this for home territory is that the enemy naturally has less mobility and it is easier to keep unpromoted units out of range of the enemy, and use them when required.
 
If you check a save w3ith cheating on and start checking the AIs units with CTRL on, you will see that the AI actually has a few units that are called as "Counter-Attack" units. I guess this is their function. But it always seem to be units on Horses, and I don't remember seeing any siege unit with this "title".
 
Wow, really great ideas!

There are shades of both the threat-level defense and counter-attack stacks in the AI now, though I haven't yet fully climbed through the routines used on defense. City defense units will guarantee a minimal level defense in all cities first, then shift excess units around to threatened cities ... the problem as has been mentioned is that when the AI is initially attacked the defense needed at all cities goes up, so there are often no longer extra troops to shift. The AI also uses a bunch of UNITAI types aside from city defender exclusively for defense, including reserve, city counter, and collateral. These are the "floating defenders" that I believe are intended to counter incoming stacks but certainly leave something to be desired ... getting all those pieces to work together to run a more active defense will be quite the undertaking, we'll see how it goes.
 
If you check a save w3ith cheating on and start checking the AIs units with CTRL on, you will see that the AI actually has a few units that are called as "Counter-Attack" units. I guess this is their function. But it always seem to be units on Horses, and I don't remember seeing any siege unit with this "title".

The UNTIAI_COUNTER units are used for a mixture of offense and defense, but they will generally join offensive stacks. There's a (very rare in the early game) unit ai type UNITAI_CITY_COUNTER that focuses on defense. I think the "counter" part is that they counter certain other types of units, so spears and axemen are the common early examples as they "counter" horses and melee respectively.
 
A relevant question: Do AIs ever delay promotions?

A very interesting question. I was thinking exactly the same thing. For sure us humans intuitively delay our promotions but not our fortification. It is natural for us and like you say, we even use promotions for healing. I honestly am clueless on the AI's tendancy to delay promotion. That is another really interesting algorithm problem if it is not implemented!

Further thoughts on this idea of improving the AI's behaviour on forming reaction stacks, would be to introduce an algorithm where the AI forms "virtual stacks" that could be deployed in threat areas that comprise a list of yet unpromoted field capable units that could be assembled in an area within a certain time from spare city reserves in the region.

These virtual stack's would not actually be assembled unless there is some trigger condition like an enemy invasion stack that shows weakness to this yet unformed "virtual stack" in the AI's consideration and that is not at the expense of basic structural defenses...

The idea would be that the AI develops a higher level consciousness about possible defensive deployments, not actual ones. I think that if I disassemble my own biological algorithms in my head, I am actually also doing this formation of "virtual stacks" as well based off unpromoted field units sitting in reserve. I do this because that "virtual stack" could also be used defensively as a counter attack stack!

The worst scenario would be if the AI does actually begin to form "real" reaction stacks ahead of time. This would be too much of a give away to any human player as we normally have built up sufficient espionage and scouting to know where such a "reaction stack" is currently deployed, and then hit the AI somewhere else...

Cheers.
 
Note that in my previous post, I suggested that the units that are part of a future reaction stack should be the same that are part of a future (city) attack stack. An AI shouldn't need two separate groups of units to fill these roles. Depending on the momentum of an actual or potential war, the AI should consider units to be part of a reaction group or a city attack group.

So for example when the AI is on the offensive, it will use 20% of it non-dedicated city defenders as reaction force and 80% for the city attack group. When the AI is on the defensive, it will use 100% of the group for the reaction force. If the AI doesn't promote these units until the moment it starts to use/deploy them, then this shifting can occur without loss in efficiency of promotions. If the momentum of the war shifts, then there will be some loss in efficiency of promotions as for instance city raider units will now be used to try to stop the enemy offensive. That's not ideal, but it's the best you can do when you're trying to stop the shift in momentum.

I would like to repeat my point about massive city defence. At some point, adding new defenders starts becoming inefficient. If you have 10 dedicated city defenders and the enemy has a stack of 15 siege units and 30 city attack units and 10 stack defenders approaching this city, then adding 20 more city defenders to the city won't help. The collateral damage attacks will reduce the defensive strength of 10 defence units as easy as the defensive strength of 30 defence units. It typically means that you trade 20 defenders against say 2 siege units. (I was once attacked in the industrial age by an AI stack of 150 units (Warlords BetterAI mod, huge map, aggressive AI, immortal level) and I didn't win by massive city defence.)

In my opinion, it is useful to have up to 10-12 defenders in a city to slow down or stop a city attack stack. These defenders will make sure that the enemy is forced to remove the defence bonus before it attacks or suffer horrendous losses. But if the enemy has enough bombardment power to obliterate this force, then it is typically more efficient to find a way to counterattack. One way is assembling an equally strong counterstack, another is to use flanking units with a high retreat chance to destroy the siege units and thereby protecting the defensive bonuses of your cities.

So in my opinion, moving defenders to threatened cities is extremely useful and can help stop or slow down a limited attack. But at some point, it won't help and will start to become inefficient.
 
It's a very good point Roland, at some point there should be a switch from adding defenders to building a stack to counterattack the enemy stack. With the benefit of roads/rails often they'll be able to surprise the enemy. I also agree that the AI should use its attack units which aren't already deployed in enemy territory to counter the threat.
 
Due to the game mechanics of seige units, against an attack stack defending is pointless (unless you just want to give your enemy XP). Counterattacking with your own stack of siege is the only viable way to defend. Getting the AI to use this behavior (By building a counterattacking defensive stack) would hugely improve the AIs defensive capabilities.
 
That is all true.

But it really means that 'threat' caps out around the 10-12 level.

Hmm. How about 5 levels:

1> Panic level
2> Standard level
3> Threat level
4> Reserve level
5> Comfort level

Panic: Never go under this. Note that Panic can spike in some cases (a holy city is about to be taken).

Standard: Only go under this in the case of a Panic.

Threat: Requesting troops in order to defend against an invading stack.

Reserve: Requesting troops to build up a stack to attack an invading stack.

Comfort: Requesting excess troops to be garrisoned here when there is nothing better to do with the troops.

Then use the "units flow downhill" rules:
Units first try to find a city that is missing Panic defenders.
Then units try to find a city that is missing Standard defenders.
Then units try to fill in Threat targets, based on relative threat. (danger: this could cause paralysis).

Then flow to Reserve waypoints.

Next, units see if they can do a counter-attack. Stack war simulation code might be useful here. Fly swat (kill a stack with conventional forces), Stack stomp (collateral then fly swat the remainder), and Siege stomp (use anti-siege units to kill the enemy siege train) all become options.

Finally, have units flow based on the relative comfort levels of cities and their current garrisons.

...

The difference here is the Reserve phase. It attempts to route units close enough to counter-attack the enemy stack. A city that is under threat would send out reserve requests to nearby cities. This does rely on the AI having a relatively dense collection of cities and a decent transportation network, but... it makes things easier. :)
 
I can largely agree with that. I do want to add that not all unit types are equal. So for instance, siege units and horse based units should typically just be reserved for stack use (attack stack or counter-attack stack) while archers and longbowmen should typically only be reserved for city defence. I hate it when I see the AI using catapults to defend its cities while it could use them a lot better to (counter)attack my stack.

So I think I would typically divide the units into 2 groups before using the algorithms described above.
 
*nod*, some units shouldn't be considered for some categories. In particular, units that are "does not gain defensive bonuses" should only be used for city defense when there isn't any point in them trying to attack.

On the other hand, axemen and spearmen often make perfectly fine defenders, and perfectly fine stack-stompers.

...

Another tricky problem is the "what if" game. If we stomp a stack, how many units will be free threat-wise? Because we can afford to contemplate attacking with units that we would otherwise hold back if the stack we are attacking is defeated...
 
Back
Top Bottom