Where does the AI go wrong with districts?

Sostratus

Deity
Joined
Jul 31, 2017
Messages
2,399
Location
Minnesota, USA
If you read almost any thread on this forum regarding deity play, it's always about catching up and then passing the AI. It is obvious that the human is qualitatively better at playing than the computer; but between deity AIs' extra settlers, huge growth bonuses, production advantages, etc., this human economic advantage seems to be coming from humans placing superior districts.

Anyone who has acquired AI cities probably knows that feeling when the districts are horribly laid out and you either stomach it or raze and do it yourself. Look around in your current game and you'll see a lot of +0 or +1 districts out there.

So I wonder: what fundamentally makes this problem hard? This is not an AI bashing thread. This is a thread about the possibility of working out a district placement solution that is:
-Not absolutely optimal, but "good enough"
-Can be feasibly implemented in Civ

At some point maybe those with working knowledge of the AI behavior trees will pop in, but
My personal take on the issue is that the AI probably follows the game's own city location scoring system (the one that suggests spots to settle.) AFAIK, this does not include at all district adjacency. Whereas any experienced human will look to settle explicitly for good district spots.
Potential solution: the game already can show you how much adjacency a district can get before you place it. Extend this to AI settler logic, and filter for good spots and put a strong weight to own and develop those tiles.
For example, if there's a double geothermal fissure providing +4 campus spot, the Ai would highly value that over an extra instance of bananas. I'm assuming the AI already places down districts where they will be highest adjacency, but maybe they don't realize they need to get good sites in the first place. This at least can cover Campus, Holy site, CH, and harbors. Theaters and IZs are much more infrastructure dependent and require some planning.

Side note: I have seen German AIs deliberately place hansas & CHs next to each other, so clearly there's something going on there under the hood. This same thing is why, IMO, AI Korea is such a monster: she places seowons which for at least the beginning of the game will be +3-4. IE, she spams high value campuses, aka unwittingly plays the meta.

Can you come up with a simple verbal "algorithm" that can look at terrain and place decent districts?
What's your human approach, and why would this same approach fail for an AI that's limited in computation power?
 
i still think that AI must learn from our games, using machine learning. That would be real intelligence ... And it would be able to learn from our games how to place districts in particular, because even a human player choose the places based on numbers given by the game, so it must be possible for the AI to reproduce it. Maybe they should allocate more computation power for the AI than for the graphics (even if i thinh both are possible with recent computers ; ) )
 
The AI probably only looks at "what is a good spot for this specific district I will build now". Not what future districts that could be built and create good "hubs" of districts or combinations of aqueducts etc.

And of course, not considering district planning in city settling.
 
i still think that AI must learn from our games, using machine learning. That would be real intelligence ... And it would be able to learn from our games how to place districts in particular, because even a human player choose the places based on numbers given by the game, so it must be possible for the AI to reproduce it. Maybe they should allocate more computation power for the AI than for the graphics (even if i thinh both are possible with recent computers ; ) )
I have definitely thought about machine learning to boost the AI before (mainly around conducting sieges actually) and while it's a technically possible answer, the dataset would have to be massive: the terrain is random and if you abstract to the level of where to place the cities too it's an absolute nightmare. Plus after that whole red shell fiasco i don't think firaxis would ever put in distributed game data collection so openly. *Even though IMO it's something that eventually needs to be available for the sake of improving the multiplayer experience.

And, it's not even necessarily the end all be all; Indeed, district placement has clearly defined rules that allow for a deterministic best solution(s). Whereas ML is most useful when you don't or cannot directly compute the answer and have to rely on a stochastic best solution, aka the well educated guess.

We can cut through the entire data collection / map reduce/your favorite variant here stages and just program simple rules or heuristics in ourselves. We already know how to play the game well.

And of course, not considering district planning in city settling.
See I feel like this has to be a huge part of it. But then how can we have an AI that has a straightforward, deterministic function that can look at terrain and decide the best/good enough spot to place district X is? Does the Ai keep a list for every city of what it wants to build there? That seems like something you wouldn't want to be too deep, because it will get interrupted and then you'll have to reevaluate. In principle i guess you could say "Prioritize this list of yield districts based on chosen win condition. Higher levels get increased weight to campus+theater."
The AI probably only looks at "what is a good spot for this specific district I will build now".
This isn't even that bad of a concept. How and Why it is delivering so poorly is what we need to solve. I wonder if it's restricted to just the tiles the city owns vs the ones it could buy or swap. Without that you'll never be able to get multi city combines.
 
There is a lot we consider in this decision making. It certainly could be done but it takes time and effort to do which was probably left out with a million other things to code.
The clue comes with the last patch when they enthusiastically told us they had got the AI to make better decisions about where to settle (thank god). I imagine they have not spent the time on this.
So imagine you are a programmer trying to tackle this, it’s not a 5 minute job by any means.
Then there is the point about how intelligent you want the game considering optimal placements will be better than the average player.
And of course the other implication is that if you make it, you have to maintain it which with any district change would mean longer patch and testing times.

It’s a nice to have but would say it has not been done nor will it be soon. But I guess we can play.
We already know how to play the game well.
We also know how to disagree well. Not sure we could come up with a simple set.... would the AI use CH with harbours?
Also it changes its VC a lot more fluidly than us.
 
Last edited:
Lets say the AI is going to build a Commercial Hub and a Harbour. But it is building the CH first. "Where is a good spot?", calculating... "This spot". However, given the harbour that shows up later, another spot would have been better.
 
So imagine you are a programmer trying to tackle this, it’s not a 5 minute job by any means.

Maybe not a 5 minute job, but not much longer if they have proper tools in place.

I have very limited programming experience, but we're talking about a few simple functions for every district and then a few more to tie them all together. A city has 19 tiles to think about and a plan for building projects could be generated immediately upon the founding of a city. A war or other extenuating circumstances would change the priorities of said build plan. Heck when the game is generated the game could lay out it's plan for empire and if the human player interferes then the computer has a reason to be upset just like a human player would. It's not like the fog of war really affects the Ai much anyways.

Oh and Ai Korea is a beast with seowons because they must be build on hills and therefor they can't screw them up badly, BUT most of them the Ai builds are adjacent to the city center so they are only +3 which is pretty much screwing things up.
 
I would like to know if the AI considers all possible tiles in the three rings around a city, or only tiles the city owns already. If there is a great spot for a district in the third ring, will the AI buy that tile? For us, the interface shows adjacencies even outside our territory (although only one tile far). But can/does the AI make use of the same information?
 
I have very limited programming experience, but we're talking about a few simple functions for every district and then a few more to tie them all together
Which wonders do I need and can build in this city, where do I place them and which districts and improvements will benefit most both in this city and the city next door without damaging the aqueduct/dam placement for the IZ. Good luck with coding that.

From what I have designed and implemented in the past the best approach is to start simple and get simple running before leaping toward predicting power plants.
So it is the level you go to @Sostratus ,a simple best adjacency placement is going to be harder than 500 minutes in my view. It is quite likely that a modular approach is needed and this alone would take a few takes to get right.

One of the killers off the bat I can think of is... I do not have that tile, will I expand to that tile soon, shall I buy that tile, how much gold do I have to spend, what else do I need to spend gold on and should I slot the 20% card. You do not have to account for all those decisions in the first edition but you know it is questions we answer without thinking once we have played a bit and require and understanding of the terrain around for a variety of reasons. One really good example of this is an early encampment is an option and the aggressive AI does build them early. You first expansion into 2nd ring tiles are onto resources and we do not really want to place them there. Do you expand to an empty tile that is a potential 3 farm triangle? Do I build it on a hill? Do I place it where a threat is coming from? What are my priorities, especially as I have already built 2 in pother cities.

Oh and Ai Korea is a beast with seowons because they must be build on hills and therefor they can't screw them up badly, BUT most of them the Ai builds are adjacent to the city center so they are only +3 which is pretty much screwing things up.
Is it ? is not +3 enough? 2 people can have quite different views on what is right and wrong in their eyes.
I am not having a go at you, just saying humans have a terribly habit of massively underestimating things.and I am playing devils advocate quite a bit.
 
@Victoria Exactly.

I do think the AI would often do well having a few different recipes for what combination of Districts to build, and then basically just building those in a triangle with the city centre eg CC-CH-H, CC-C-TD, CC-A-IZ.

But that's a very limited strategy and would result in a lot of mediocre (although not terrible) and quite samey cities. It also obviously miss all the nuance you've pointed out.
 
It also obviously miss all the nuance you've pointed out.
But it is the right approach, something simple that can be built on and would garner an understanding of what actually is required even for a simple decision.
anyone volunteering a verbal algorithm for a starter? What terrain is required?
Mountains, rivers, coastline, hills, resource tiles, developed land?
 
Triangles often produce less output than correctly placed single districts. A triangle gives +1 output which is lousy, specially since you get the +1 after building the second district.
 
Triangles often produce less output than correctly placed single districts. A triangle gives +1 output which is lousy, specially since you get the +1 after building the second district.

Depends really. The big advantage of a triangle is you just get the districts down while they're cheap and can crack on with buildings and projects. You also get +2 not +1, because you boost two districts in your triangle. If there's a river you get your CH to +3. If there's a single mountain, that gets you another +1 for a campus, or you might get +1 from some jungles. A resource etc buffs your IZ and better yet with an Aqueduct. TDs don't get better adjacecies other than wonders. And a Government Plaza is another +1.
 
I didn't write +2 cause that was obvious. And then it should be compared to the yield of two correctly placed districts. I dont find it a winning strat to do random triangles like Campus-CC-Theatre.

There are some variants of triangles that are good but they are special cases and not useful for a generic district strategy which was the OP.

Unless AI is hopeless. +1 is better than +0
 
+3 is so much better than +1 and only a little less value than +4 due do the 50% cards later

I guess we need to have some idea how big the city will grow, or at least assume 7 pop?
We need an assessment of mountain adjacency for Holy sites and Campuses
We need an assessment of forest and jungle for for Holy Site and campuses including if we intend to keep the forests.
We need to assess if we are going to overlay a resource do we chop the resource first
We need to exclude impassible tiles, luxury and strategic resource tiles and tiles better suite to other districts, hills and flat land we want/need to work.
yeah... I am starting to think this is a rod for our own back, I'm out, too much like real work.
 
AI should simply put tacks on a 10 pop ideal city. Pre-allocate space, computing best adjacencies to be and revise its assertion with each actual build. That's it. Someone suggested ML, it feels overkill to learn placement rules as they are limited enough to build an heuristic based constraints engine.
 
Taking district adjacency bonuses into account while settling sounds like a good first step, but which adjacencies should it prioritize? Ignoring theater squares and IZs which require forethought, should the AI prioritize sites with adjacency for campus? CH? Harbour? Holy Sites?

If you wanted the AI to play the meta it should just try and take all the best campus spots first. But that doesn't seem very satisfying, you at least want the AI to role play it's leader adgenda... And if the AI is just looking to maximize adjacency bonuses it's probably going to prioritize coastal river cities because on most starts CH and Harbour are the easiest buildings to get adjacencies for... Maybe as a compromise have it look for a campus/holy site location and a CH/Harbour location at a potential city and just take the highest of each class into account? With bonuses for a theater square and/or IZ location that it may have accidentally created before.
 
i still think that AI must learn from our games, using machine learning. That would be real intelligence ... And it would be able to learn from our games how to place districts in particular, because even a human player choose the places based on numbers given by the game, so it must be possible for the AI to reproduce it. Maybe they should allocate more computation power for the AI than for the graphics (even if i thinh both are possible with recent computers ; ) )

That's how you end up with WOPR, or even SKYNET
if you haven't seen the classic.
 
@ezzlar I think you're overvaluing adjacecy a little. To get that "sweet sweet spot" you're often spending gold to buy tiles and or delaying getting your district down. Are the extra yields actually worth it?

It's really only Campuses that underperform with triangles because mountains (more so since GS because the way continents spawn) and because you want the +3 for Rationalism. Even then, it's really only +3 that you need. Get a single mountain / two jungle and a triangle gets you to +2. You only need another +1, eg another mountain or more jungle or a Government Plaza.

Theatre Squares usually do better with triangles than anything else. Get a wonder in your second ring, build out your triangle to the wonder and that's +3.

Holy Sites use mountains but I'm not sure the extra faith is that valuable. IZs in a triangle with CC isn't optimal but it's not bad if the triangle includes an Aqueduct and you can find a resource (and you don't need Pop to build the aqueduct). Habours and CH love triangles.

And what do you even want from your districts? To me is usually buildings, projects and great people (particularly for Theatre Squares). The adjacecies are just a perk, with again the exception of Campuaes where you might want a +3. The sooner I can get my districts down and running projects the better.[1]

Anyway. It does of course depend on the map and your strategy. I'm not saying triangles are always the most optimal strategy in all situations. My main point was that throwing down triangles is not a bad default strategy for the AI. If it can be programmed to do better than great, but triangles arent a bad place to start.

[1] On that note, I know everyone complains about how weak Specialists are, but honestly I think the bit people miss is that projects are basically the new specialists anyway. Pumping projects and just buying or chopping in buildings gives some really terrific yields and Great Poeple Points.
 
IMO preplanning the city before settling and ( for me putting the map tacks ) deciding what tiles will become what district etc. should be possible.
If the computer player decides what victory condition it wants to pursue , then it can also adjust its district placement order easy enough.
The question becomes how much foresight or preplanning should the computer do? all 3 rings around the city ? potantially swapping tiles with a nearby city ( that would mean recalculating the other city also ) , considering +3 as good enough since it is all the policy card needs? or always go in favour of max adjacency? do we consider one distrcit adjancy or all districts together ( with as many as possible +3 ).
As players that can win at deity we answer those things all the time even if we are not doing it at a conscious level. Programming that would take a lot of manpower and hour. Now for the bad news ,if you cannot use this programming for other games our future projects then it is wasted talent/time for the company.
Also Machine learning as a standart response is really funny. do we want a game that is bigger than 10 harddiscs? or does anyone here want to play only when connected to a central server in firaxis where the machine learns from all games worldwide?
 
Back
Top Bottom