Where does the AI go wrong with districts?

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.

I am just saying that the Ai really has the choice between +3 and +4 and it repeatedly chooses +3.
 
Plus there's so many more factors at play here too. For example, if you're next to Roraima, you can easily get a +4 holy site or even a +6 one. But for that +4 holy site you're giving up a tile that has +2 faith and +2 science. Do you build the campus in the best spot for the campus, even if that is where your ideal aqueduct spot happens to be?

Never mind the basic planning - do you slot in each district one by one? Do you plan what you will want assuming the city grows to size 4? 7? 10? 20? +4 campus spot is great, but what if that's my only mine tile? Or do I really want to build the campus next to the Volcano, maybe I would be better to get a lower yield elsewhere.

Also factoring in some other issues - if I put a district in a certain spot, will that prevent a farming triangle later in the game? How much do I re-evaluate in case if niter spawns and ruins my spot? If I'm piling in culture and not planning to run the double adjacency card, does it really matter if my theatre is +1 or +2?

I mean, all these things we can pick answers for, and in theory code an AI to handle them. But how many of them truly matter, or is that AI effort better spent in simply spending more time actually choosing which districts to build? I don't tend to find the AI district locations all that bad - yeah, for sure their harbor placement is pretty horrible, when that really should be the absolute easiest district to place (pick the highest adjacency tile that doesn't have a resource on it). But I'd bet that if we dug down into AI decision making, they'd get a lot better by revisiting other areas (policy card choice, unit choices, attack order, tile improvements, etc...) than spending a ton of time grabbing an extra +1 adjacency on their districts.
 
Perversely, making the AI better at placing districts would also make warmongering more valuable, as you'd capture more productive cities. :mischief:

I appreciate the intent of the discussion. I expect an understanding of the AI build tree logic would be needed first and foremost, as which district to build when is likely the most critical decision the AI makes. But there should be a feedback loop, as a high adjacency bonus district should rank as a higher priority than the same district with lower adjacency potential. Once the decision to build a district is made, I don't know if modders have access to the routine that handles the actual placement, or if that's buried in the DLL.

Trying to teach the AI to place districts more effectively is a noble cause, but if successful would make the game harder for new players who haven't learned how to balance district placement with improvements, etc. In this (and many other) ways I'd simplify the game for the AI and beginners. If effective district placement is a skill developed by players over time, it could be mimicked by giving the AI +1 adjacency bonus per district at Emperor, +2 at Immortal, and +3 at Deity. That would force the player to be more efficient in their own district placement to keep up when playing at higher difficult levels, without putting more pressure on those playing at lower difficulty levels.
 
We also know how to disagree well.
Well, perhaps we can have more agreement on something like, higher adjacency is better than low adjacency! In regards to machine learning I just meant that we know already how to place districts well, we don't need to datamine it.

Plus there's so many more factors at play here too. For example, if you're next to Roraima, you can easily get a +4 holy site or even a +6 one. But for that +4 holy site you're giving up a tile that has +2 faith and +2 science. Do you build the campus in the best spot for the campus, even if that is where your ideal aqueduct spot happens to be?

Never mind the basic planning - do you slot in each district one by one? Do you plan what you will want assuming the city grows to size 4? 7? 10? 20? +4 campus spot is great, but what if that's my only mine tile? Or do I really want to build the campus next to the Volcano, maybe I would be better to get a lower yield elsewhere.
But it is exactly working through these questions to find a "one size fits most" solution that would be such a benefit. I carefully did not say the AI should have an optimal placement strategy. Just a decent one.
Part of working out something better than what we have is exactly figuring out how to set planning portion to balance complexity vs yield.

But I'd bet that if we dug down into AI decision making, they'd get a lot better by revisiting other areas
I know, but we fanatics have infinite bandwidth for low priority discussion!


Trying to teach the AI to place districts more effectively is a noble cause, but if successful would make the game harder for new players who haven't learned how to balance district placement with improvements, etc. In this (and many other) ways I'd simplify the game for the AI and beginners. If effective district placement is a skill developed by players over time, it could be mimicked by giving the AI +1 adjacency bonus per district at Emperor, +2 at Immortal, and +3 at Deity. That would force the player to be more efficient in their own district placement to keep up when playing at higher difficult levels, without putting more pressure on those playing at lower difficulty levels.
This was something I had thought about to make the AI properly capable of scaling into the midgame, and it's what inspired me to make this discussion. Since allocating citizens to tiles is the same routine for human and AI unless we manually intervene, it's really just districts producing the economic gap. The AI can certainly have more cities and improvements and units out than you can. The balance of course can be toning back the AI's other general bonuses to growth and production if ti's too overwhelming. Although on sub-prince I doubt it will really have the exponential effect that emperor+ bonuses would have. It's a great backup option that i think would introduce a lot more realistic challenge to the game than the current production boosts.

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.
I like these questions. You get it. I'll get to it later but in my head, the AI's strategic level goals should dictate districts more than the other way around, because if we keep them separate then they can be improved in a modular way. You never want to introduce a circular dependency when you can avoid it. [Strat defines districts defines strat defines...]

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.
You understand exactly what I am getting at. No one reading this should think that you can deploy a full, 'takes everything into account,' right away and expect it to work. Like most software the first thing is to have something you can describe clearly in "psuedocode." That is, the core functional steps that have to happen. I think there's so much room for potential improvement, that even getting something tweaked but partway to the goal would be a big improvement. Useful if they ever make a Vox Populi for civ6.

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.
See, theaters and IZs are really hard because they have such a dependency see on other things you have to build. But you cannot wait around forever to put them up. I do think having mini "plans" would be the abstract next step beyond anything that just says "place district in best currently available spot."

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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?

Here's a rough first start:

At the top level we have a District Unit Queue. Per city, this is a list of "district units" that the city will try to build. A district unit is something to allow this algorithm to handle both standalone districts and multiple of them. Most districts will be a single unit, but some cases will be more than one; for example, how to implement things like Harbor and CH, or IZ and AQ. Unique districts can have their own definitions under this scheme.
The order of this queue is inherited from the Civ's Strategic Focus. In my head this means any specific Victory Condition would have a predefined order of priority to build stuff in. For example, Science Victory would have Campus at the top of the list. How long is it? I think we can start our list at 3 District Units. That usually going to be 7 pop, so I think it's okay.

Now each city has a District Unit Queue informed by the civ's strategic focus. When a city is settled, it can evaluate the terrain around it for the District Placement Plan. This step is perhaps the meat, but the legwork needs to be done in order to make this practical.
We start by going to our District Unit Queue and defining all the individual districts that need to be constructed (because a District Unit may require more than one district.) Once we have that, we can place them on the map.
Valid locations on the map are any tile that city could normally place in that does not already have a district planned for it. So this would require a piece of data that it essentially an array representing each tile on the map, with the data entry either being blank or specifying what district is planned on it and by which city.
The order of planning is set by some preset ranking of the districts. Again, this could be informed by VC, or maybe there's just a general one. IDK. But the city goes through that list of all the districts it wants, and first it places the most prioritized district in the highest yield valid location for it, then the next, then the next, etc, until each district has a planned location on the map. If there is no way to place part of a larger District Unit, then the District Unit is cancelled.* Extra note: the district evaluation counts previously Planned Districts as if they exist already. I recognize this is a slight modification of the Best Location rule but it would be handy. If we don't have it we would need to change a lot of stuff.

Now, the city needs to build these things. I don't know how the AI manages its production queue but when it goes to build a district, now it will instead try to place the District Unit on the top of the District Unit Queue, in their planned locations according to the District Placement Plan.
This is where the complication is. What to do if the tile isn't owned needs to be determined. For a basic first cut, I would suggest if the tile isn't owned, defer and go to the next item in the District Unit Queue.

To tie it all off with a bow, several cases need to be handled, like what happens when the queue is empty and the city can build another district. This is where I would add a "defacto" case where the city can just build non-queued districts in accordance to the "best place open right now rule" and whatever priority it already has. Longer term fix would be working out something extremely simply for buying tiles. (Like if it's the most important district type to you, buy the tile.)

*We could have a simple table that says If you cannot place part of this district unit, do this instead. IE if you cannot place an AQ, build the district unit that only contains the IZ. Single districts have no replacement, and so they get cancelled altogether.

As some simple example, imagine a science victory pursuing civ. They might have a District Unit Queue defined as:
  1. Science Unit
  2. Production Unit
  3. Culture Unit
The science and Culture units are both just single districts. The production in this case would be Aq+IZ. For these scenarios, it would be helpful to establish an unconditional order to them. The AQ is more restricted, so should be built first. So the ordered list for the "district placement plan" might look like this:
Plan the placements in order...
  1. Campus
  2. Aqueduct
  3. Industrial Zone
  4. Theater Square
Suppose the Aqueduct could not be placed. Then the Production Unit would be checked in some kind of table to see if the entire thing should be dropped, or replaced with something simpler. Perhaps in this case it comes back as "place IZ unit" which only contains the IZ. Then the District Placement Plan would only have 3 districts in it instead of 4. This entire routine is to prevent failures when the city is on an island or if the city has little usable terrain.

When it gets to checking land availability, it's possible another civ may have taken the tile, or the tile has popped a strategic resource, or something. In this case it will just be deferred forever and effectively removed from the DU queue.
The defacto case is something that is how cities could build beyond their DU queue, and is probably currently informed by what the civ needs. In fact, one could assign Defacto case decisions to be their own item in the city production decision tree, in order to fill in when the empire needs something in particular, like an EC or a spaceport.

Here's a quick graphic showing some of the basic logic:

upload_2019-8-7_0-5-43.png

The computational overheard is analyzing the city's terrain on founding, once per city; storing the District Placement Plan array, and maintaining the District Unit Queue for each city. The downside is it requires some kind of set of strategic plans to exist. It's entirely allowable for the plan to change over time, since the computation of the placement is when the city is founded. But the DU queue can't be changed if the VC goal changes. And AIs may not have a VC goal to pursue. So I suppose one could always have a Default strategic plan too to cover that.
Land Availability is something that could be greatly extended on, but oh well.
 

Attachments

  • upload_2019-8-7_0-4-22.png
    upload_2019-8-7_0-4-22.png
    25.3 KB · Views: 118
Actually, the AI's district placement isn't really that bad. They pick out decent adjacency bonuses and while they can't plan for future adjacency, nor can most people. :lol: Also just because they place low adjacency districts doesn't mean they made a mistake. C-hub adjacency is often very weak anyways and sacrificing great tiles for 2 gold is a bad idea. Sometimes spending early game gold to place the best district isn't a good idea either and that's something that not even humans can easily evaluate. Sometimes you need a district right now regardless of position and I imagine that must be hard to tell an AI to do.

Their city placement is still pretty poor though, avoiding fresh water. Actual district choice is also pretty questionable-- they love those encampments way too much. I'm also more troubled by them refusing to build walls over all else.

If you want the AI to really be ruthless and get ahead of the player, that's easy actually. Just make them chop or at least use their tiles. Usually the AI just leaves forests and stones as is.
 
Last edited:
Imo. the issue comes down to a mix of some AI shortcomings combined with some game features being designed so that they can be abused by the human player.

In terms of AI shortcomings, I think the most important are:
  • Underprioritizing building districts and buildings in general - AI will tend to build a lot of unecessary units and (the worst culprit by far) put all their production into help projects, which is directly harming themselves.
  • Prioritizing wrong districts - AI has a huge love for Holy Sites and Encampments, and while both can be useful, they are currently underpowered in terms of optimizing your strategy.
  • Failing to capture Campus adjacency - and perhaps IZ adjacency as well. While most of the district adjacencies are dispensable, these two make a pretty significant impact and are - imo. - way too powerfull and easy to get high in the current game.
In terms of game design flaws going against the AI, the most important is:
  • Flat yields of Campus buildings. This is a pretty serious core design failure in the game imo. The fact that you can just spam Campuses for linear growth in output is neither realistic nor good for balance. It prompts the human player to always default to Campus in every city, something the AI fails to understand. The natural solution would be that a Campus works on a per-pop basis (i.e. increases science per population) and that each Campus can only serve a certain number of citizens (basically working with a capped AOE like the EC and IZ).
  • Great people that add additional flat yields to Campus buildings. It is fairly easy for the human player to specifically target these great people, particularly Isaac Newton providing +2 Science (which is +50 % on the overall quite significant +4 University) is quite devastating for balance.
  • Too high and available Campus adjacency bonus. Like mentioned above, AI has a hard time using it, and it's not good for game scaling either. Why does Campus get +1 science from mountains before Astronomy is invented anyway? And what's with the +2(!) science for each Geothermal fissure - again, working from Ancient era?
  • Too high and cryptical IZ adjacency bonus. It's fairly easy for the human player to plan IZ/Aqueduct/Dam triangles for massive IZ adjacency. It's not easy for the AI to do the same (at least it's not programmed to do it). Getting a +5/+6/+7 IZ is entirely possible in many cities if on a river, and running the +100 % IZ adjacency card will make you run miles ahead of the AI suddenly.
 
Something in line with what @Trav'ling Canuck was saying: would we want the AI to prioritize better district placements, specifically campuses and holy sites? On any given map, there’s a finite number of >=+3 spots. If the AI were to start prioritizing settlement locations based on adjacency potential, how far do you take it? Do they go 3 tiles out of their way for a +4 campus? How about 6 tiles? 20? What’s too far? (Understandably, this could be part of an optimization code with a cost function)
There is a line of too far, where suddenly everyone is prioritizing mountains, and now humans have to compete for those spaces through war. That’s probably undesirable for peaceful players.

This all comes down to the balance of victory conditions. Ideally, you want one that cannot be too easily achieved by stepping hard on the gas in one direction (else, it’s frustrating when you realize you can’t do enough to catch up). You also don’t want to pigeonhole everyone into one path (though warmongering is currently kinda in this zone), but you also want to make the player feel rewarded for having strategy, not just good tactics.

Reworking the AI balance would probably need to rebalance the game itself as well.

However, I think this is a fantastic idea, and should be looked into. What about prioritizing district locations based on a hierarchy of priority of preferred victory types for each leader?
 
Last edited:
On any given map, there’s a finite number of >=+3 spots. If the AI were to start prioritizing settlement locations based on adjacency potential, how far do you take it? Do they go 3 tiles out of their way for a +4 campus? How about 6 tiles? 20? What’s too far? (Understandably, this could be part of an optimization code with a cost function)
There is a line of too far, where suddenly everyone is prioritizing mountains, and now humans have to compete for those spaces through war. That’s probably undesirable for peaceful players.
While forward settling is a thing AI will do, it's been greatly pared back. They seem to mostly blob out.
But in my OP or a post after it I mentioned that one thing they could do is add district adjacency for some focus district or two to the scoring of settle spots.
This would result in the AI still settling in a similar pattern but, maybe they pick the river geothermal fissure spot instead of one downriver because it has an extra banana.
Doesn't really add much than extending whatever function already can compute district adjacency to their little city settle recommendation.

Part of the district placement motivation is that if we can simply tell the AI to focus on building campus/theater early, it will perform much better than it does now. But that's a very deity tuned plan of action; it would be better if they could somehow place districts better. But, in order to place districts well, they need to settle those tiles in the first place. So it's sort of a necessary requisite to ultimately better play, but the problem placing districts well for a given set of terrain is independent of actually having good spots to place on.
 
I mean, the AI doesn't build commercial hubs on rivers sometimes...Blowing some pretty logistics there.
 
I just want to throw in, that while my AI might just have been blindly finding golden corn here, in my current game, the AI had some pretty good district placements. And this was without any AI mods in action:

While it may be overprioritizing holy sites here, those are not badly placed, and that Campus is pretty sweet!

Spoiler :
upload_2019-8-7_23-39-52.png


Again in this one, we see some great Campus placements, and those Industrial Zones in the background has potential to grow excellent with proper Aqueduct and Dam placement.
Spoiler :
upload_2019-8-7_23-43-34.png
 
I don't think I've ever seen an AI get over say 300 science per turn at any stage in the game. The AI tech leader is usually around 150 in the 1700s at least on immortal difficulty.

Adjacency might be the problem, but they also don't build enough campuses, they use terrible cards, and they very very rarely can even take other AI cities to get a runaway going. Walls are awesome to slow a player down a tad, but the AI cannot handle them. Same thing with barbs.

It would be great to teach them adjacency strats, but that is beyond wishful thinking at this point. Sid Meier can't program catapults to shoot at the moment. Weighting the AI to favor campuses over encampments and better cards would be a start. Auto give the AI(on high levels at least) a +3 adjacency on all districts. Maybe then the AI with 10 cities could get ahead in tech and take out the guy with 3. Do you guys ever see AI snowballs?
 
Adjacency might be the problem, but they also don't build enough campuses, they use terrible cards, and they very very rarely can even take other AI cities to get a runaway going. Walls are awesome to slow a player down a tad, but the AI cannot handle them. Same thing with barbs.
As recognized elsewhere, obviously to make the AI more potent those are by far the easiest things to do. But there is still the central issue of: if district placement is relatively formulaic and the coding already has them trying to place in the highest currently available spot, why do they seem to make generally poor choices?
Since districts will very likely be carried in whole or part to civ7, and they may continue making district adjacency more complex (like with IZs) the core question I was trying to pose is if there are simple changes that could help them execute just this part better. I'm not bashing the AI or devs here; this isn't something they should have a crack team on.
 
I don't think I've ever seen an AI get over say 300 science per turn at any stage in the game. The AI tech leader is usually around 150 in the 1700s at least on immortal difficulty.
goSY4a9.jpg


Just an Emperor game. Though to be fair it's not typical; he took out Gilgamesh and my start wasn't too hot-- Egypt with almost no rivers...
 
Last edited:
The Ai is exceptionally weak once the year 1000 comes around. Even playing a peaceful game on Emp or immortal level I will find myself having 4 or more times Science, culture and faith than my closest 3 or 4 opponents even if I don't have a strong game going. I saw Ai Indonesia with only 69 science around the year 1100 the other day and they were untouched by war.
 
I don't think I've ever seen an AI get over say 300 science per turn at any stage in the game. The AI tech leader is usually around 150 in the 1700s at least on immortal difficulty.

Adjacency might be the problem, but they also don't build enough campuses, they use terrible cards, and they very very rarely can even take other AI cities to get a runaway going. Walls are awesome to slow a player down a tad, but the AI cannot handle them. Same thing with barbs.

It would be great to teach them adjacency strats, but that is beyond wishful thinking at this point. Sid Meier can't program catapults to shoot at the moment. Weighting the AI to favor campuses over encampments and better cards would be a start. Auto give the AI(on high levels at least) a +3 adjacency on all districts. Maybe then the AI with 10 cities could get ahead in tech and take out the guy with 3. Do you guys ever see AI snowballs?
Sid Meier don't have to program catapults to shoot, because..
  1. He's not been doing that since the very first game in the Civilization series.
  2. It's not like "AI never use their catapults" - I've seen it happen.
That being said.. Yes, AI do fail a lot, but so do humans; though we are so much better in adapting, so I kind of agree in this.
 
I was being too negative. I do like the game and all the new additions since Civ V. I just wish it was better is all.

Barbarian catapults work just fine. They attack your land units, cities, boats, anything. I've seen AI civ catapults shoot at a boat and attack my cities, but usually they just sit there not doing anything. Archers don't do this. So an easy fix would be to tell siege units to think they are archers. It's just that that is such a simple fix that why hasn't it been done yet? To get the AI to put districts in better spots would be fantastic and it's a good discussion to have. I just don't think Fireaxis or Sid Meier will ever fix the AI.
 
..
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
..
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?
As recognized elsewhere, obviously to make the AI more potent those are by far the easiest things to do. But there is still the central issue of: if district placement is relatively formulaic and the coding already has them trying to place in the highest currently available spot, why do they seem to make generally poor choices?
Since districts will very likely be carried in whole or part to civ7, and they may continue making district adjacency more complex (like with IZs) the core question I was trying to pose is if there are simple changes that could help them execute just this part better. I'm not bashing the AI or devs here; this isn't something they should have a crack team on.
I think the core problem here is "tiles are not there just for districts" - a District Placement Plan will (be) interfere(d) with and by any other priority about Wonders and improvements. Actually, it may already be that way (eg idle builders).

Don't get me wrong, I do enjoy this new District concept, but it's so backward and it cripple humans planning though mostly AI - there need to be a better system where all numbers are in place when crunching.
A district should be generic at first and later earn a specified status, when it's making sense - when there's infrastructure for it (@Boris Gudenuf in Industrial Era?).
Until then adjacency should be about buildings in a district - buildings would be (re)movable somehow, in a project (when there's technology/civic for it).
 
Last edited:
It's not like "AI never use their catapults" - I've seen it happen.
Was that by chance because there was a Great General present, giving them an extra movement point? It seems to me that AI siege weapons still seems to suffer from the "unit must move" syndrome.
 
Was that by chance because there was a Great General present, giving them an extra movement point? It seems to me that AI siege weapons still seems to suffer from the "unit must move" syndrome.
Not really. They were built at an encampment and didn't need to move..
I've seen Inca catapults counter-attack my war-carts when I was trying to siege their Capital city. That happened recently on King difficulty.
 
Back
Top Bottom