Experimental DLL for 4/21

Status
Not open for further replies.

ilteroi

Prince
Joined
Mar 11, 2006
Messages
486
hi there,

here's a test DLL for the experimentally inclined. some tweaks to AI combat behavior:
  • more aggressive against citadels
  • ignores enemy civilians less often
  • should be a bit less reckless when attacking
just put it in the mods/community patch folder, replacing the DLL which is there. then, after you've played some games with it, please give feedback:

what is your impression, how is the tactical performance of the AI these days?


tactical here means unit-level target selection, positioning, concentrated fire, hit-and-run, etc. as opposed to empire-level strategical decisions like when to declare war.

are there any areas where it reliably falls into a trap? are there certain situations it is bad at handling? any typical mistakes you have observed?

if that's the case please post a description, ideally with screenshots.

issues i'm aware of:
  • AI is better at attacking than at defending. it's just easier to decide what to do based on what you see in front of you right now than based on what your opponent might do or not do next turn.
  • AI does not protect its elite units very well. it's hard to strike a balance between using them carefully and not using them at all.
  • AI tends to waste it's unit one at a time instead of setting up a coordinated attack. problem here is the visibility of enemy units, they don't remember much between turns.
if you have any ideas for improvements, i'm all ears. please keep in mind though that what seems easy to you isn't always easy for the AI, because their situational awareness is a bit spotty.
 

Attachments

  • ignores enemy civilians less often
That's actually a thing? I feel like the Ai repeatedly declares war just to grab my unprotected workers.


As far as wasting units, that's probably always going to be the case, because of how the player can just pile on an exposed unit, only real thing the AI can do about it is predict which tile isn't safe better (guessing that's really hard) or do the exact same thing back towards a players unit (which I think they already do).
 
That's actually a thing? I feel like the Ai repeatedly declares war just to grab my unprotected workers.


As far as wasting units, that's probably always going to be the case, because of how the player can just pile on an exposed unit, only real thing the AI can do about it is predict which tile isn't safe better (guessing that's really hard) or do the exact same thing back towards a players unit (which I think they already do).

I have even used my civilians as bait during war. If the AI sees an unprotected worker it will do everything it can do capture it. Even if it means the unit will be killed right after and the worker recovered. It's a more logical thing to do with generals, or even any of the other killed on capture units. Not so much for the workers.

If anything, the AI probably should only bother to capture workers when there is no other targets to worry about.
 
is this 43 civ version? will be glad to test this alpha version in new games(me play one game per one day)(and i am warmonger, so can give a feedback on fights)
 
just replace file(CvGameCore_Expansion2.dll)
File are here on my PC:
C:\Users\User\Documents\My Games\Sid Meier's Civilization 5\MODS\(1) Community Patch
 
Uhm, instead of relying on visible enemy units, wouldn't making a reliable defense line be better for the AI? Like detecting the player/other civ's borders and how far it is from their own. If far with land connection, make outlook fort posts on terrain with best visibility and/or defensibility. If borders are close/touching other civ's border, make a defense line of citadels and forts with permanently stationed units. The Maginot line would have worked if the entire borderline was protected...

I'm not totally sure if the AI actually likes to park forts on their borders but it sure would be fun if the AI would start a pea shooting match against my citadel/fort/citadel/fort line instead of recklessly trying to kidnap my workers only to get killed by a mounted unit watching nearby.
 
Uhm, instead of relying on visible enemy units, wouldn't making a reliable defense line be better for the AI? Like detecting the player/other civ's borders and how far it is from their own. If far with land connection, make outlook fort posts on terrain with best visibility and/or defensibility. If borders are close/touching other civ's border, make a defense line of citadels and forts with permanently stationed units. The Maginot line would have worked if the entire borderline was protected...

I'm not totally sure if the AI actually likes to park forts on their borders but it sure would be fun if the AI would start a pea shooting match against my citadel/fort/citadel/fort line instead of recklessly trying to kidnap my workers only to get killed by a mounted unit watching nearby.

Maginot line failed even where it was protected, so that's not a good argument. Besides, if the AI simply lines up on its borders that makes it very difficult for the AI to mount a proper counterattack.

G
 
Maginot line failed even where it was protected, so that's not a good argument. Besides, if the AI simply lines up on its borders that makes it very difficult for the AI to mount a proper counterattack.

G
Well, I guess so... A defensive AI solution can't not be a mobile theater. Probably needs more fixed defense play though.

But the AI needs to stop using it's proper military units as scouts. On a ynaemp marathon game as China, I had warrior units from spain and austria staring down at my borders...

As for the AI aggressiveness, it's pretty much okay as it is. Genghis tried to steal my border worker with a warrior only to be ganked by my horsemen. They are a bit reckless though, only sending out warriors to DoW me when he knows I've killed barbs around him with my horsemen while I had a citadel on top of that ridge line near the south of gobi desert and the forest to the east has my border forts at the edges.
 
Ah finally a proper thread for this. Question: From my understanding, the AI mostly works with what it sees right? I have no idea how the actual math goes on the decisions, but for defense wouldn't it be easier to look at it from standard player strategies and have the AI work from that? As in, something similar to a flavor system where the AI is inclined to certain positions on the assumption of what a competent player would do. For defense have the AI work from the assumption of capability more than anything.
For example: Player A has a high enough military score that allows Player B to assume that A has more than shown. B pulls from predefined examples to fortify and grind against A.
This would remove some initiative that would be useful against an ignorant player, but if situational awareness becomes a problem on terms of what the AI can see, then different forms of processing for offense and defense would be the best outcome.
I'm only looking to stir this up a bit for a better understanding of how the tactical AI works.
 
Ah finally a proper thread for this. Question: From my understanding, the AI mostly works with what it sees right? I have no idea how the actual math goes on the decisions, but for defense wouldn't it be easier to look at it from standard player strategies and have the AI work from that? As in, something similar to a flavor system where the AI is inclined to certain positions on the assumption of what a competent player would do. For defense have the AI work from the assumption of capability more than anything.
For example: Player A has a high enough military score that allows Player B to assume that A has more than shown. B pulls from predefined examples to fortify and grind against A.
This would remove some initiative that would be useful against an ignorant player, but if situational awareness becomes a problem on terms of what the AI can see, then different forms of processing for offense and defense would be the best outcome.
I'm only looking to stir this up a bit for a better understanding of how the tactical AI works.

This reminded me of something I've often wished for: that the AI would respect my smaller-but-highly-successful military more. But I think it would require the mod to keep track of my batting average, so to speak, and that may be impossible.
 
Last edited:
In my last two games I noted that the Ai has become copletely recless with embarking.
Even agains total naval supremacy they will send waves after waves of units in the boats, only to have them completely slaughtered.
I don't remember this behavior in older versions.
 
if you have any ideas for improvements, i'm all ears
You are going to regret this! Hehe.

Use two tactical layers: Offense and Defense. The Offense layer works pretty much as now. The Defense layer will work on potential threats. Each layer will ask for some tasks to be fulfilled, with a priority level, and unit type/strength requirements. When a unit is set to a task, it will keep doing the same task until another task with higher priority demands the unit, or the task is completed. Being closer to the tile with a task increases the probability of that unit to be selected for the task (this means that if an extra tercio is needed for a task, it will take the nearest tercio that works on a lower priority task, or else the nearest idle tercio unit).

The Defense layer identifies good defensive points, weak points and sentry points within our territory boundaries, including nearby no-man's land. A good defensive point has rivers, a nearby hill in our side, open terrain in the other side, fast healing from owned territory, good road connection and fewer tiles that allow access to enemy units (with lakes and/or mountains, except if Incas/Songhai are neighbours). Cities can be defense points with extra defense, healing and attack, but having improved tiles ahead counts against it. For naval, defensive tiles are always coastal cities. A weak point is a tile located in the empire boundary, near enemy lands, with no defensive points nearer than four pathfinding steps. Weak points are a place for gathering idle units, place them in defensive formation and set workers to improve defense with higher priority. Sentry points are linked to boundary points, where there is fog of war in unclaimed territory.

Defense layer will label the tiles in the boundary as defensive or weak, spacing them each four pathfinding steps across the boundary, and will set a priority. Priority is decided upon the closeness to aggressive neighbours, the value of the city and resources it directly defends and the closeness of defensive resources (if a nearby defense point can send reinforcements in fewer than two turns, or a populated city is nearby). Sentry points are related to a defense or weak point, and its priority is inherited from the point it is watching for.

1. DEFENSE POINTS. A defensive task may change depending on the era and terrain, but it usually consists on a melee unit backed by a ranged unit. If there is no terrain bonuses in the defensive tile, it can be a mounted melee instead. And a siege unit can be called for if no ranged unit is available.

2. WEAK POINTS. A weak point needs more units to fulfill its defensive role. All units not assigned to a task will gather at weak points and stay in defensive formation.

3. SENTRY POINTS. Sentry tasks are fulfilled by scouts, or else mounted units. If there are two sentry points that the scout can visit in two turns, then the scout will receive the patrol task between those two points.


PREPARATION TASKS

After Defense, Weak and Sentry Points are identificated and priorized, units have to be assigned. If the empire is at peace, all units not working on an anti-barb squad or garrison can be used for defense. Each point will ask for units, starting by those with highest priority, and the closest matching units will go to the tile (or around it). After the unit has arrived to point, the priority of nearby points will be reevaluated, since there is now an extra nearby military unit. Garrisons per se have low priority and these units may be used for attacks or reinforcements. If possible, cities that are used as defense points will focus on defense buildings.

New cities or new territory around boundary points will also cause them to reevaluate boundary point locations.

A worker squad will take care of defense improvements for each boundary point (clearing forests ahead, connecting to road network, building forts), beginning by the weakest points with highest priority. If there weren't enough military units of the required type to fulfill all defensive tasks, then it will increase the will for that kind of units.

THREAT LEVEL

In case we spot other civs (neutral) military units moving, we raise the threat level. Just for caution, we increase the priority for tasks near the spotted units. This means any nearby boundary point is going to receive extra units and workers are prioritizing roads here. The priority raise will depend on the relative strength of the shown units. We don't want to mobilize tercios for a single foreign warrior, but we do want it for a couple of knights.

If war is declared, then it's not just for caution. An attack is expected, and we need to estimate how long the point is going to hold. Then compare it with the time it will take for reinforcements to arrive. If help cannot arrive in time, then a retreat task is in order. Retreating is a complex task of finding the next defensible position and moving all the units there while minimizing losts.

In both cases, only enough units to fulfill the tasks should be employed. Idle units without any task may join combat, though.


So, basically the Defense layer use a set of fixed tiles near the borders (which may include cities), says which kind of tasks are suitable there (minimal defense, units gathering or scouting) and decides a priority level depending on tactical factors (strenght of nearby friendly, neutral and enemy military units, proximity to foreign/enemy territory). Meanwhile the Offense layer keeps launching surprise attacks by several ways if possible.
When at war, the Offense layer may control up to 50% of the units. A warmonger may allow the Offense layer to control up to 80% of the army, while a peacemonger may limit that to a 30%, for example.
 
You are going to regret this! Hehe.

well i didn't promise to implement anything, so the joke's on you :)

anyway, the idea is good on an abstract level and the AI already does a number of things in this vein, like identifying strong points, having a mobile reserve, having a prioritzed list of tasks and a (rudimentary) threat level monitoring.

however, as always the devil is in the details. could you write down the unit allocation logic for strong points and weak points, depending on threat level etc? if there aren't enough units to go around, how do you divide your forces? what data is needed in order to "estimate how long the point is going to hold"? what is the condition for a strategic retreat and what is the condition for a counterattack? what is defensive play anyway, does it mean no melee attacks?

you see, there are some tricky questions here. especially since right now the AI doesn't even try to keep track of currently-invisible enemy units, so a proper threat monitoring is a pipe dream. by the way that is also the reason why the AI's unit danger assessment is so bad. invisible units are ignored, zones of control are ignored too (never know if your first line unit might be killed, leaving you exposed) and of course it's unclear which target the enemy is going to pick. it's hard to use that as a basis for planning.

but the concept of "sticky" unit tasks is interesting. currently each unit gets a new task every turn (with some exceptions). i wonder if the potential for improvement would justify changes here, or if it's simply too much work to test it. right now we have the "always new task" model. the other extreme "always keep task" obviously isn't good, so where's the optimum and what would be the condition for "overwriting" a task? or would it make sense for a unit to have multiple tasks, if they are "compatible" in some sense? so many questions!
 
Alright so visibility being such a debilitating issue for the AI, then how about increasing the relevance of scouts? Scouting is currently a small part of the game even though the promotions necessary to their relevance are there. Ignoring ZOC, using enemy roads, and extra visibility are all available to be used, yet are almost never on the field. Maybe some altered promos and a decreased gap between scouts and explorers would help with visibility? I can imagine it would also help their flanking attempts a fair bit.
 
well i didn't promise to implement anything, so the joke's on you :)

anyway, the idea is good on an abstract level and the AI already does a number of things in this vein, like identifying strong points, having a mobile reserve, having a prioritzed list of tasks and a (rudimentary) threat level monitoring.

however, as always the devil is in the details. could you write down the unit allocation logic for strong points and weak points, depending on threat level etc? if there aren't enough units to go around, how do you divide your forces? what data is needed in order to "estimate how long the point is going to hold"? what is the condition for a strategic retreat and what is the condition for a counterattack? what is defensive play anyway, does it mean no melee attacks?

you see, there are some tricky questions here. especially since right now the AI doesn't even try to keep track of currently-invisible enemy units, so a proper threat monitoring is a pipe dream. by the way that is also the reason why the AI's unit danger assessment is so bad. invisible units are ignored, zones of control are ignored too (never know if your first line unit might be killed, leaving you exposed) and of course it's unclear which target the enemy is going to pick. it's hard to use that as a basis for planning.

but the concept of "sticky" unit tasks is interesting. currently each unit gets a new task every turn (with some exceptions). i wonder if the potential for improvement would justify changes here, or if it's simply too much work to test it. right now we have the "always new task" model. the other extreme "always keep task" obviously isn't good, so where's the optimum and what would be the condition for "overwriting" a task? or would it make sense for a unit to have multiple tasks, if they are "compatible" in some sense? so many questions!

We could, as part of the AI's handicap model, give the AI cheaty vision of FOW tiles x range outside of a unit's sight. Yeah it is technically cheating but it also gives the illusion that the AI is keeping up with unit movement better than it really is.

G
 
We could, as part of the AI's handicap model, give the AI cheaty vision of FOW tiles x range outside of a unit's sight. Yeah it is technically cheating but it also gives the illusion that the AI is keeping up with unit movement better than it really is.

G

Early ruin hunting will be a nightmare
 
The only really weird thing I see AI doing is smashing a lone scout into a full health barbarian camp, sometimes even passing up the opportunity to grab a ruin in order to do so. I'm not complaining though, I love goody huts and you already get so few on higher difficulties.
 
well i didn't promise to implement anything, so the joke's on you :)

anyway, the idea is good on an abstract level and the AI already does a number of things in this vein, like identifying strong points, having a mobile reserve, having a prioritzed list of tasks and a (rudimentary) threat level monitoring.

however, as always the devil is in the details. could you write down the unit allocation logic for strong points and weak points, depending on threat level etc? if there aren't enough units to go around, how do you divide your forces? what data is needed in order to "estimate how long the point is going to hold"? what is the condition for a strategic retreat and what is the condition for a counterattack? what is defensive play anyway, does it mean no melee attacks?

you see, there are some tricky questions here. especially since right now the AI doesn't even try to keep track of currently-invisible enemy units, so a proper threat monitoring is a pipe dream. by the way that is also the reason why the AI's unit danger assessment is so bad. invisible units are ignored, zones of control are ignored too (never know if your first line unit might be killed, leaving you exposed) and of course it's unclear which target the enemy is going to pick. it's hard to use that as a basis for planning.

but the concept of "sticky" unit tasks is interesting. currently each unit gets a new task every turn (with some exceptions). i wonder if the potential for improvement would justify changes here, or if it's simply too much work to test it. right now we have the "always new task" model. the other extreme "always keep task" obviously isn't good, so where's the optimum and what would be the condition for "overwriting" a task? or would it make sense for a unit to have multiple tasks, if they are "compatible" in some sense? so many questions!

Obviously I wasn't expecting all this to be implemented. But I love this kind of wondering.

To the details. The easiest to explain is how to change a task. Priorities. I set a level 2 priority to the defensive task of a border city (peacetime, no expected enemy army coming this way, no spotted units, easy to defend tile, already a melee unit as garrison). I set a level 5 priority to the defense of a weak point (no friendly unit in this spot, direct path from closest neighbor, important iron resource nearby). First they demand for idle units. The one with highest priority and closer to the unit gets to choose first among the idle units. If they can't find idle units, then there's a competition. High priority tasks will try to get units from lower priority tasks. It will compare the priority of the higher task against the priority the lower priority task may have if the unit is separated from its task. For example, garrisoning the city had a priority of 2, since there's already a unit there, but if I were to remove the unit, the priority for garding the city would raise to 4. Because the other task has a priority of 5, it takes precedence, so the unit stops its garrison and goes to protect the iron. If there are no higher tasks demanding units, the unit can keep doing the same task.

Units are distributed the same way. Say we have already the defense points identified, and there's no unit in any of them. We put all units near the capital, for example. Now we compute the priorities. Highest level and proximity to the units decide which tasks pick which idle units. As units fill the tasks their priority lowers, but those units will only abandon their task if there is another task with a higher priority that can't find any idle unit and if removing that unit doesn't raise priority over the other task.

The most difficult thing is how to find those points and how to set priorities. Finding highly defensible tiles is a hard task, but you know, better if you can stand behind a river, use features at your advantage, can heal and there are fewer tiles from where to shoot or replace units at the other side. Once you get the best defensible points along the borders, finding weak spots should be easier. Value of terrain, distance from safe positions, near routes... Preferably at a four steps distance. I don't know exactly how to find the best tiles without making an extensive search, but this sounds slow, so there should be something more holistic.

To set priorities is going to be a learning experience. Because this would ultimately decide where units will go, the factors for priorities may change. Starting things to account for would be
- Closeness to foreign territories
- Value of nearby resources
- Presence of neutral or enemy units
- Relative strength of friendly units committed to the task (already in place).
- Proper unit type for the task. (Sentry points prefer scouts, weak points prefer mobile units)
- As a rule, a defensive point without units should have more priority than a weak point without any unit. Sentry points inherite priority from the point it is watching for.

Sorry I can't be more specific.
 
Status
Not open for further replies.
Back
Top Bottom