AI Development: What is a forward settled city?

Recursive

Already Looping
Moderator
Supporter
Joined
Dec 19, 2017
Messages
4,782
Location
Antarctica
As far as I know there is no function in the DLL for the AI to know what counts as a "forward settled city", and I'm having trouble coming up with one.

Relevant information the DLL can provide:
- The current owner of a city
- The original owner of a city
- The previous owner of a city (before its most recent trade/conquest/buyout)
- The turn a city was founded
- The turn a city was most recently acquired by the current owner
- The list of a player's cities
- The distance between two cities, or between any other two tiles (in tiles)
- Whether a city is an original/current capital

Ideas are requested on how to define this, because my brain is drawing a blank! I want to use this to finetune the "don't settle near us" logic to exclude AI forward settled cities, and to trigger the AI to get more aggressive when forward settled.
 
Just for a quick brainstorm, it could be a city that's not inside the capital's "cluster" of cities aka if a city isn't within, let's say 7 tiles from another one (within the capital's "cluster"), it's a forward city. This considers coastal civs like Carthage or Venice as it's only about the distance. I'm not sure if I'm missing any variables here though. It would be interesting to define how puppet cities would be considered though hehe
 
Just for a quick brainstorm, it could be a city that's not inside the capital's "cluster" of cities aka if a city isn't within, let's say 7 tiles from another one (within the capital's "cluster"), it's a forward city. This considers coastal civs like Carthage or Venice as it's only about the distance. I'm not sure if I'm missing any variables here though. It would be interesting to define how puppet cities would be considered though hehe

That doesn't differentiate between a forward settled city (near another civ's borders) and an isolated city, although I plan to exclude isolated cities from the expansion warnings as well.

To be specific, the issue I'm trying to solve is:
1) Player settles some cities close to their capital
2) AI plops down a forward settled city in the middle of their lands
3) Player settles a new city in their own sphere
4) Because it's within 5-7 tiles of the AI's forward settled city, AI pops up complaining about the player settling too near them.

So I want to fix this - while still maintaining the warning if the player settles in the AI's direction (not in the opposite direction) if the city is actually close to the AI's main cluster.

I've been thinking about how to solve this issue without making it overcomplicated and hard to understand/debug, and I'm drawing a blank.
 
I think your plan of excluding isolated cities (I assume the ai's) is enough. Like, if an ai settles a city close to their own sphere then sees a player settling near them, it could consider that as a threat. This said, maybe more expantionist civs could be more likely to give a warning if their cities are far from their own (and near the player)
 
That said firstly what is it that really triggers it now? Cause it seems to be wonky sometimes where they start to complain where or when you settle some place and they are not even close to that place but they somehow seem to think that all the world is theirs and no matter where you settle you are in their sphere.

There is always going to be some kind of edge cases that can be constructed where more or less any idea will come of as bad or stupid. So perhaps do not try and make it work for every single or possible scenario or geography. A pangaea should or could be very different from a map that is just tiny islands or maps with enormous amounts of mountains etc. So it might not only be tile distance but also tile content.

Question might be some kind of definition of what is a forward settled city? In some regard I think it could be a few different things but mainly I would say it's a city that is placed by leaving your core and moving closer to the enemy then you are to your own land/border.

That said there has to be more cause eventually then things are just going to count as forward settling no matter what as borders keep pushing towards one and another.

Perhaps one could also check for foundation turn and then keep track of how it looked at foundation. But it might be or become to complex, or not even possible.

After all there are just a couple of different ways to settle. Either you have some kind of natural growth where you sort of settle close and the grow out OR you go for some kind idea where you strike out far away from the capital and then you backfill later. Usually to claim some strat resources, luxuries or a natural wonder. When you go long you sort of want to signal that everything behind this city, or between this city and my capital, is mine.



Judging from the things that can be pulled from the DLL not all of them are very interesting or useful in that regard.

Current owner could be interesting, in some scenarios more then others.

Original owner not so much in relation to the current owner, it should triggers other grievances if anything.

Previous owner could be a long list or is it just the more recent one in which case it's often going to be the same as either the first or second option. So that isn't all that interesting either.

Founding turn could be crucial if you can also recall what the border situation looked like at the time. Otherwise perhaps not so much.

Recent change, not that interesting. After all if you are in a war and conquer a city it's not really forward settling. It's taking city as part of a war. It shouldn't really count as forward settling. It might lead to border disputes, warmongering penalties etc and that could anger them but it's not really forward settling. Or? I personally don't think so. It should be naturally placed cities (by settler, you have to be both the current and original owner and it can't be a city-state etc). If it counts as both forward settling and warmongering and/or taking their capital or whatever then you are sort of double dipping into the grievances. Which may or may not make sense. But it's weird for them to be angry about both the war and that it also somehow counts as you settling a city near them.

List of players city, a total number can be gathered. At least in theory the more cities you have the more distance there should be from your capital and core cluster. That said new clusters of production and yields can usually form around conquered capitals as they tend to have fairly good land. Not sure that by itself constitutes as forward settling.

Distance should probably be the primary maker.

Current or previous Capital probably doesn't matter as far as forward settling either. As noted previously other grievances might matter more then such as you are controlling their previous capital or you have conquered a city-state or whatnot.


Perhaps some kind of ration of your total number of cities and the distance to your capital (from the city in question)? Compared that ratio then to the distance to the AI capital and their number of cities, or their ratio. Some number will be considered to be ok and others will not, possibly depending on leader type and their relation to you in general. Perhaps discount various outliers if there are just one or another city that is totally screwing with the ratio. As in what would the ratio be if that point (or city) wasn't part of the equation.

That is if you think all nations should be clumped around the capital. They sort of usually are in some way, even tho it might not be the exact geographical center of the domain. But there are not a lot of nations that have piece of land here and another there but they are somehow really connected by land in between. There is no unclaimed land in reality, eventually there won't be in civ either but it could be at the time cities are founding in the early to mid game.

At worst then you could just slowly creep up on each other. Eventually you will. It might promote a certain playstyle or settling strategy.

The longshot foundation at the start, or in the early game, if you leave your close proximity to the capital will almost always probably then be a grievance or count as a forward settle.
 
What about if you got the average distance each city from the capital and used it to flag whether a city was generic expansion or a "colony". You could set a hard minimum for the initial settling phase so you don't get wonky results and assign modifiers based on difficulty. For purposes of settling disagreements, colonies would be ignored by the owner of the colony cities.

I'm thinking something like....

Code runs a calculation for each civ when a city is settled and determines their "fair settlement sphere (FSS)" that is based on the average distance each city is from the capital plus the modifier. Cities that are settled outside this value are flagged as colonies and ignored for purposes of calculation of averages. After each city placement, the FSS is recalculated, and cities are checked to see if they need to have the "colony" flag removed for purposes of future calculation.

Let's run a scenario and assume for Immortal difficulty, the modifier is 7 tiles. Austria's average distance from the capital is 7 tiles, so they have a FSS of 14, meaning any city within 14 tiles is considered normal growth. Now Austria has settled a new city, NewCity. A check shows that it is located 12 tiles from the capital so it is considered normal..

Let's assume Austria settles a second city, NewColony, on the frontier that is located 20 tiles away and towards Germany's borders. Because NewColony is outside the FSS, NewColony gets a flag so the code knows to ignore it when considering whether Austria gets upset at German growth. (Germany might, however, be peeved at Austria for the new city.) Now over time, Austria grows towards NewColony with additional cities. Each time a city is settled, a check is ran to see if NewColony still deserves the "colony" flag. As some point in history, Austria's FSS expands to include NewColony at which point the "colony flag" would get dropped, and Austria would treat it like any other city.

***
I think this idea would work and is pretty straightforward. My hesitation is in those cases where your capital is on the edge of your borders, and you are growing in the opposite direction, but I think the ever increasing average distance would automatically adjust for it. I'm also wondering how it would do for the more maritime civs that might generally have more widely spaced cities from island settlements.
 
Milae on discord used the idea of “you settle closer to a foreign capital than your own”

thaf feels like a simple yet solid definition to me

This is what I'd have suggested too. It is simple enough that you can just look at the map and tell if you are forward settling or not.
 
Milae on discord used the idea of “you settle closer to a foreign capital than your own”

thaf feels like a simple yet solid definition to me

It might be to simple. The amount of what if scenarios are staggering. What if the land/map is to small there might only be room for say one city between you and the enemy capital so whomever settles the spot then triggers it. Would there be a difference between settling right up on their border or just closer then your capital? More grievance the closer you are? What if your border has grown out by some mean (say lots of goodie huts or you have the right pantheons etcwhatever) and you backfill the area with a city that is clearly within your borders but still closer to the AI capital? What if you conquer most of their lands. Then all conquered cities are now forward settling them? That is unless we discount conquered cities, which I think we should do. But it seems to be a thing currently. What if it is equal distance between your capital and theirs? What if their capital moves? So if I take all their lands and their capital and push them out to some far flung colony on an island in the middle of nowhere. They are now fine with the distance thing (even tho they'll be massively pissed that I took all their land and their original capital) but the distance criteria is now no longer an issue?

If distance is the only criteria you will not only have only one player vs another AI but there will be a matrix of cities and capitals then. In theory when you settle a city you could be forward settling a multitude of AI players (or they forward settling each other including you).

What if you settle a city that is say 50 tiles away from your capital but just 49 tiles away from a rival capital? Have you really forward settled them when you took that one tile island out in the middle of nowhere etc? There might need to be some limits on the whole distance thing then. Certainly so if the world wraps around to.
 
Last edited:
I mean you can already forward settle every AI once with no penalty. If land is super tight it probably should lead to conflict.

And while a more complicated system might be better if it works that is a big if. Humans often don't agree on what counts so expecting AI to work it out all the time seems very hard.
 
I would agree with the "closer to my capital than their capital".

But, another thing to consider is how easy it is to defend a city. For example if there is a mountain range between me and another civ I will often consider my territory to be up to the mountains because after that it's harder to defend. Does the AI have methods for evaluating how defensive a city is? If not then it's probably too much to implement but if it already exists it could be used as part of the evaluation.

And another thing is how many cities I'm planning on. If I'm progress then I'll want a lot more cities than tradition.
 
Maybe it should satisfy multiple criteria to count as forward settling someone:

1) Closer to their capital than your own
2) Within at most 7 tiles of their nearest city
3) Not your 2nd city
 
...But, another thing to consider is how easy it is to defend a city. For example if there is a mountain range between me and another civ I will often consider my territory to be up to the mountains because after that it's harder to defend. Does the AI have methods for evaluating how defensive a city is? If not then it's probably too much to implement but if it already exists it could be used as part of the evaluation.

I thought about this as well and thought trade route distance might work.
 
What about initial generic territorial borders be established upon founding the capital based upon the topography of the map surrounding the area?

I have a tendency (Am guessing most do as well) to use mountain ranges/hills/rivers/coastlines/desert edges/tundra to establish a natural defensive perimeter for overall territorial expansion/city foundation where the 2nd, 3rd, 4th (Sometimes I found towards 7 or 8) city establishments will be positioned strategically, based upon the discovered resources in the localized areas within the region from my capital (Whilst maintaining tile connection within city borders to 'close off' my land to those that are not friendly.

Very few times I will push past those natural borderlines due to having very close neighbours, in which case it is more likely than not I settle my first few cities farther then 'fill in the gaps' to establish control of the region.

With city cultural acquisition of new tiles, I have noticed it generally does not pick up those tiles that are poor in yield unless there are tiles beyond them that are high yield, even then those tiles will be sought after for natural expansion when there is little else closer or those tiles beyond are quite high in yield (Generally favouring food acquisition)

Edit: It took me over 2hrs to write this... Never saw rsc2a's post (Multi-tasking first thing in the morning is not the best idea)
 
Calculate a mean position of all your cities as the center of your civilization and call it C. Then Calculate mean distance of all your cities to C and call it D. Then calculate distance from the new city to C and call it N. Divide N/D to see how relatively far away the city is from the center of your civilization and call it R. Do the same for AI. If your R is higher than AI's R, then you are forward setting.

C = mean(your cities positions)
D = mean(distance from your cities to C)
N = distance from the new city to C
R = N / D
Player forward settling = Rplayer > Rai

I think that this simple formula would work in most scenarios. The distances could be calculated either by number of hexes or trade route distance (which is the same as religious pressure distance?)


OR

Calculate hypothetical passive (or active via TR?) religious pressure assuming the same number of believers in all your cities to the city. Do the same for AI. If AI's pressure is higher then you are forward settling.
 
Maybe it should satisfy multiple criteria to count as forward settling someone:

1) Closer to their capital than your own
2) Within at most 7 tiles of their nearest city
3) Not your 2nd city

I'm in favour of this. The rules allow for more intelligent appreciation while still being simple enough to know whether or not you're forward setting.
Sure it would be fantastic to take into account mountain ranges, lakes and even rivers as defining "sides" and borders beyond which you are trespassing, but I believe it's impossible for a mod.
 
Calculate a mean position of all your cities as the center of your civilization and call it C. Then Calculate mean distance of all your cities to C and call it D. Then calculate distance from the new city to C and call it N. Divide N/D to see how relatively far away the city is from the center of your civilization and call it R. Do the same for AI. If your R is higher than AI's R, then you are forward setting.

C = mean(your cities positions)
D = mean(distance from your cities to C)
N = distance from the new city to C
R = N / D
Player forward settling = Rplayer > Rai

I think that this simple formula would work in most scenarios. The distances could be calculated either by number of hexes or trade route distance (which is the same as religious pressure distance?)


OR

Calculate hypothetical passive (or active via TR?) religious pressure assuming the same number of believers in all your cities to the city. Do the same for AI. If AI's pressure is higher then you are forward settling.

This was pretty much my first thought. I think you would have to do a few things: discount colonies like I discussed in my earlier post from the "center of civilization" calculation, set some initial minimums perhaps until a certain number of cities are placed, and set a maximum distance from the borders the AI would care about. They shouldn't care if I land on a island in the middle of nowhere just because it's 1/2 a world away from me if it's still 1/3 of a world away from them (assuming you aren't using tiny maps).
 
For each civ, initiate its pissy territory as a circle centered at the capital with radius 7.

For each new city founded or captured:
If new city is within existing pissy territory, add the new city to the city cluster. Otherwise it's a colony with its own new cluster.
Include 4 tiles around the new city into the pissy territory.
If a cluster is updated (through city loss or gain), calculate the center of the cluster using the average of coordinates, then draw a new pissy territory circle with the diameter equal to the longest distance between all pairs of cities within the cluster.
If an old city is now included in the territory, add that to the cluster too and update the territory again until no more city can be added.

Pissy check:
If civ A founds a city within civ B's pissy territory but not their own, it's a forward settle.
 
Yep. How would you define a colony? A city placed at least X tiles from all cities?

...Code runs a calculation for each civ when a city is settled and determines their "fair settlement sphere (FSS)" that is based on the average distance each city is from the capital plus the modifier. Cities that are settled outside this value are flagged as colonies and ignored for purposes of calculation of averages. After each city placement, the FSS is recalculated, and cities are checked to see if they need to have the "colony" flag removed for purposes of future calculation.

Let's run a scenario and assume for Immortal difficulty, the modifier is 7 tiles. Austria's average distance from the capital is 7 tiles, so they have a FSS of 14, meaning any city within 14 tiles is considered normal growth. Now Austria has settled a new city, NewCity. A check shows that it is located 12 tiles from the capital so it is considered normal...

Basically the same pissy territory idea described in another post.
 
Top Bottom