AI Development: What is a forward settled city?

Thank you for all the input, everyone, lots of good stuff here.

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)

"Forward settling" and "settling too near the AI" are distinct from each other. The latter triggers the expansion warning, the former will trigger additional aggression for your bold move.

If an expansionist AI were to pop up and complain about the player being in the way of their forward settling, that should be its own message (the AI being an aggressive jerk, not "you're settling too near me").

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.

Current logic (as of 1.2.1, which fixed the AI counting conquered cities and considering the whole world theirs):
- City is within 5-7 tiles (depending on AI's Boldness/UA) of one of the AI's cities, and was founded after that city was most recently acquired by the AI
- City is not conquered or the player's original capital
- City was founded less than 30 turns ago
- City is closer to the AI's city than to the owner's original capital

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

Too simple, unfortunately - it doesn't distinguish between "player is naturally expanding into my territorial sphere" and "player is settling outside of their normal settling range just to claim my lands", the latter of which is what I'm looking to define; in addition if any city closer to the AI's capital than your own is a forward settle that would result in a lot of AI aggression. It also doesn't account for more complex cases like looorg has mentioned.

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.

I like this idea in principle, although I don't see why the range should differ based on difficulty level. The flag would be redundant codewise since the distance is being checked every turn anyway.

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.

Cities that don't trigger the expansion warning can still count for territorial disputes, which is a major source of AI aggression.

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

What if your second city is next to their capital and 20 tiles away from yours? I do like the simplicity of this solution otherwise. It doesn't account for multiple forwarded settled cities, though.

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.

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)

It's easy for a human to look at the map and intuit natural growth boundaries based on defensible territory. It's much harder to train the AI to do this; not a feasible solution unless you can come up with a precise definition that works in every geography. It would also be a performance hit.

AI's desire to expand can fluctuate so I don't want the AI to be fine one turn and pissy the next, thus it won't be considered. It is considered in the territorial dispute modifier, though.

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.

Not a bad idea, but it misses the part about needing to be close to the AI. :)

Also by settling cities far away in other directions you could increase D and thus make R lower, so this is exploitable. At a cost, but it's not logical for the AI to ignore a city near them just because you're playing poorly (or are Polynesia).

Number of hexes is simpler and more consistent than religious pressure or trade route paths.

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.

This is the most detailed proposal and I like how comprehensive it is, although it's very complicated logic to implement just to handle forward settling. Perhaps. :)

However, it doesn't account for settling multiple forward settled cities at the same time.
 
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.

A forward settle is a settlement you place because you're looking for conflict. If the AI forward settles you, then its saying "don't settle near us" is a manipulation of words (a dishonesty), pure bullfeathers that allows no form of actual reconciliation with who it's talking to.

You, the player, forward settled the AI in order to guarantee you get the better of a hopelessly belligerent situation between you two (such as.... the map spawning your two capitals 8 tiles from each other). The AI's determination of the city being a problem is based on none of the factors you say it can calculate by, but by the question it asks itself of: What is the maximum prosperity I can get of legal city settlements I can do now, given placement restrictions - and, if no possible settlement routine can get the A.I. over a threshold of what it knows to be absolutely desperate, for-sure-losing position, then it knows it must capture or raze someone else's cities.

Making it object to a city position for any other reason is what would be artificial.

Giving the A.I. reasons to discount turning to war to solve this problem would bestow the computer player a glimmer of Humanity.
 
A forward settle is a settlement you place because you're looking for conflict. If the AI forward settles you, then its saying "don't settle near us" is a manipulation of words (a dishonesty), pure bullfeathers that allows no form of actual reconciliation with who it's talking to.

You, the player, forward settled the AI in order to guarantee you get the better of a hopelessly belligerent situation between you two (such as.... the map spawning your two capitals 8 tiles from each other). The AI's determination of the city being a problem is based on none of the factors you say it can calculate by, but by the question it asks itself of: What is the maximum prosperity I can get of legal city settlements I can do now, given placement restrictions - and, if no possible settlement routine can get the A.I. over a threshold of what it knows to be absolutely desperate, for-sure-losing position, then it knows it must capture or raze someone else's cities.

Making it object to a city position for any other reason is what would be artificial.

Giving the A.I. reasons to discount turning to war to solve this problem would bestow the computer player a glimmer of Humanity.

I don't follow. Forward settling almost always denies the AI access to land, thus there's reason for them to get upset regardless of where it can place its other cities. It's lost access to options, and the city placement means war/aggression is probably intended.

The AI is still an AI. Ascension to humanity is beyond the scope of my work for VP. :)
 
I can remember a game in which I used a colonist to settle in the middle of my territory, the only possible place, 4 tiles away from 5 or 6 of my own cities and I got a warning from 2 different AI after that. The entire workable territory of that city was already under my control and yet the AI still perceived it as a problem. I think it has to do with the number of cities too.
 
A forward settle is a settlement you place because you're looking for conflict. If the AI forward settles you, then its saying "don't settle near us" is a manipulation of words (a dishonesty), pure bullfeathers that allows no form of actual reconciliation with who it's talking to.

You, the player, forward settled the AI in order to guarantee you get the better of a hopelessly belligerent situation between you two (such as.... the map spawning your two capitals 8 tiles from each other).
A player forward settles another in order to take land that they might not otherwise be able to have if they settled in a standard order. That is, the land is desirable and closer to the other player, so the other player is more likely to be able settle it first if both players settle their closest locations first. Therefore, the settler needs to skip other, closer, desirable locations in order to get the land before the other player.

Current logic (as of 1.2.1, which fixed the AI counting conquered cities and considering the whole world theirs):
- City is within 5-7 tiles (depending on AI's Boldness/UA) of one of the AI's cities, and was founded after that city was most recently acquired by the AI
- City is not conquered or the player's original capital
- City was founded less than 30 turns ago
- City is closer to the AI's city than to the owner's original capital
With that in mind, I think you only need to change the final point to "city is closer to AI city than the nearest settler's city", then find a way of discounting isolated cities. Perhaps also add a "settled city is more than 5-7 tiles from settler's nearest city".
 
Current logic (as of 1.2.1, which fixed the AI counting conquered cities and considering the whole world theirs):
- City is within 5-7 tiles (depending on AI's Boldness/UA) of one of the AI's cities, and was founded after that city was most recently acquired by the AI
- City is not conquered or the player's original capital
- City was founded less than 30 turns ago
- City is closer to the AI's city than to the owner's original capital

With that in mind, I think you only need to change the final point to "city is closer to AI city than the nearest settler's city", then find a way of discounting isolated cities. Perhaps also add a "settled city is more than 5-7 tiles from settler's nearest city".

I think that might actually do it, or be on the right track. I am not sure why we would have to compare to the distance of the capital. It might just be better to compare to closest cities. As long as there is somehow like a line of cities back to your capital. This is a normal growth pattern. As long as you have a (or another) city that is in "normal" range (whatever that is but apparently 5-7 tiles) then this would be normal growth. If you don't and you are close the to the AI or AI capital then that might constitute a forward settle.

Perhaps quantify it somehow by checking if there are ANY cities with X tiles (and it's not early in the game).

Also are the tiles and timers game speed and map size dependent or scaling? As in are those numbers for standard maps on standard speed? As in then is it 150 turns on marathon speed? If the map is huge then 5-7 tiles is not very much either. But that said if it's a tiny map then 5-7 tiles might be quite a lot by comparison.

Can you somehow quantify where the borders are in game? Like how many tiles out it is? I guess you could just check each tile out for ownership. Or how close the city is to a current border? If you can you might want to check vs borders to (or instead of). This might solve the issue of if you settle a city that is clearly within your borders on your land but might also be somewhat close to the AI. Say if a city is within a certain amount of tiles (2-3?) before city settling inside your border. Still I guess a city close to the AI within your borders or not might still be perceived as a threat. After all you forward settle for one a very few reasons -- claiming resources or claiming a geographically strategic point. If that point is close to the AI capital that is naturally going to be even scarier for them.

After all if I forward an enemy AI that close to the capital it probably isn't to grab resources. It's to have a good point for an attack as I can swiftly move around with some roads and increase my healing per turn. But for other cities it might be about the resources (or natural wonders or whatnot).
 
Last edited:
upload_2021-11-29_15-39-55.png

Should red be counted as forward settling blue in this case? Assuming the rightmost red city was just founded.
Darker colour = capital
Lighter colour = founded cities
 
Sure! It's 5 hexes to nearest red's city, 3 hexes to nearest blue's city and 4 hexes to blue's capital.
 
View attachment 615292
Should red be counted as forward settling blue in this case? Assuming the rightmost red city was just founded.
Darker colour = capital
Lighter colour = founded cities
I would say no. First, because Red is following a natural settling progression, and second, B has had ample opportunity not claim that spot for itself, but chose higher priority locations.

This is cause for border tension, not forward settling.
 
It seems a bit weird but I'm sort of with Rekk on this one. I think the red city in this case would/should be fine. That said I am less certain the scenario would be real. Blue border growth would or should probably by this time have made that tile invalid.

Other questions pop up sort of like why is red breaking the pattern of spacing? It's 3 between all their other cities. Why now jump to five? Is there a lake or mountains or something that made it so red have to go to five? Or was it a choice to go to five to get closer.

New red is 9 tiles from red capital, 4 tiles from blue capital, 3 tiles from nearest blue city, 5 tiles from nearest red city.

If one just looks at the current logic then this would be a forward settle as it's clearly within 5-7 tiles from from a rival city, it was a settled city not a conquered one, it was just founded (ie less then 30 turns ago) and it's closer to a rival city then to your own capital (it's even closer to a rival city then to your closest city even tho that isn't a rule).

If the last settle had been a blue city instead that would or should have been more ok as it's closer to blue capital then to nearest rival red city. It would have been a backfill blue city of sorts. That said it would break 3/4 of the rules as it is withing 5-7 tiles of a rival city, it's settled, just founded but it is closer to your capital (or a second city) compared to the rival (capital 4 away, other city 3 away, closest rival 5 away). But unless you break them all it doesn't qualify as a forward settle as I understand it.

It might also matter in which order red and blue has settled. We know where capitals are and we know that the most right red city was the last settle. But nothing more, did red go 3 left and then started going 2 right? It could matter. As I noted previously borders might matter and perhaps it just can't be a distance thing. Would the solution then be to look or compare to the previously founded city and compare distance to that? I don't think that would be a good fit either. After all you might not just grow in one direction but growing in different directions or have some sort of ping-pong growth as in one here and another one there on the other side and then back and forth a bit.

But even with that in mind I find it tricky as it clearly seems to fit with reds growth pattern. If that tile/area was so great one more wonders why blue have not settled it yet, it might be that blue have more cities beyond the image but otherwise it's still weird why it settled say that city at the bottom of the image before settling the new red spot (if that spot is any good and not just a garrison city put there for a future war). But I guess we can't start to teach the AI how to evaluate city locations properly. Still I would think blue messed up if that area is good and they have not settled it yet (even tho I believe that blue borders would probably have made that tile invalid in the time it has taken red to found five cities beyond it's capital).
 
It broke the pattern because that location had some combination of defensible terrain and high resource value. It's perfectly acceptable as an example.

It's also easily possible that blue's resources were in locations that their borders didn't grow towards red. Red is (necessarily) in blue's fourth ring. It's not unlikely that blue has not reached their third ring in their direction by the time red has expanded to their 6th city. Blue could have spent gold on tile purchases to make red's new city less desirable in the absence of settling there directly.
 
I would say no. First, because Red is following a natural settling progression, and second, B has had ample opportunity not claim that spot for itself, but chose higher priority locations.

This is cause for border tension, not forward settling.
Red had even more options for different settling positions and yet it chose this one, which more like Blue's territory. I'd absolutely expect Blue to be pissed about that. Even I'd be pissed about that :D
 
Red had even more options for different settling positions and yet it chose this one, which more like Blue's territory. I'd absolutely expect Blue to be pissed about that. Even I'd be pissed about that :D
You'd be annoyed at Red when it took its 6th city in a place that really should have been your 3rd if you were concerned about your borders? Not yourself?
 
You'd be annoyed at Red when it took its 6th city in a place that really should have been your 3rd if you were concerned about your borders? Not yourself?
Yeah, because it could be me my 5th. 3th city of Blue could very well also be in a spot that another enemy could take instead, so it's not necessarily a bad order of placing cities.
 
Yeah, because it could be me my 5th. 3th city of Blue could very well also be in a spot that another enemy could take instead, so it's not necessarily a bad order of placing cities.
With your proposition of events, I guess enemy C should be angry that Blue forward settled them with their 4th city.
 
Definitely passes the eye test to me and looks like a forward settle. It's very close to multiple of Blue's cities, close to Blue's capital, messes up the concavity of Blue's borders, etc.
 
The reason I am ok with this if I am red is that there have to be something wrong with the location otherwise blue would have claimed it already. Blue apparently values it quite low. It's following the red settling in some regard. But it does break the current rules. The easiest fix would just be for the AI to never allow a rival city withing 5-7 of the capital period. Those will always be deemed as scary, possibly there might be ok if they are on a different continent or some weird island setting.

That said if you just reverse the players here, red is now the AI and blue is the player. Then I would never allow that placement. I would more or less instantly declare on red at my earliest convenience.

(back to normal again) For the AI this is just so bad if it would allow player red to place a city there. If red gets any ring 2 or ring 3 tile in the direction of the blue capital that is just a citadel and you are just right on top of their capital. Blue messed up by allowing this.

It might also be a very bad location for red, after all you are in that position practically under bombardment from three AI cities with your army. It's not going to be fun if blue declares on you either.

But it's sort of besides the point I guess. The goal is to find some rules that work for most cases and is reasonable in general and not one that works for every single possible scenario, I'm sure others could be created that would just be equally bad in that regard.
 
got a proposal
1) Each city has a "zone of control" radius, which is equal to it's distance to it's closest city of the same player plus X tiles (to be defined, fixed value, dynamic, dependent on population? your pick)
2) if enemy city hits 2 zones of control from two different cities of the same player, that counts as forward settle.

Using azum4roll's example, if X was, like, 2, then both blue capital and third blue city (counting from top) would feel "invaded" from the east-most red city
 
A few questions for myself (And perhaps others) as I am not too familiar with the current implementation of logic and progression of said logic:

For initial defined logic,
Is the AI aware of the location and distance to their neighbours at the beginning of the game or is it based upon discovery for a more human-like element?
Is the AI aware of resources (Starting or tech based) at the beginning of the game or is it based upon discovery as it is for a human player?

For progression of said logic,
What is the defining AI logic upon settling their Capital in regards to expansion of territory? After settlement of their Capital, how is the logic defined for their 2nd, 3rd, 4th, etc settlements?
How does the AI perceive their respective terrain within their territory in comparison to other AI/player neighbours? Is this based upon assigned personality traits at the beginning of the game?
 
Top Bottom