Question: How to modify AI city placement algorithm?

Compromise

Emperor
Joined
Apr 17, 2006
Messages
1,601
I'd like to play around a little bit with the algorithms the AI uses to choose its city placement sites. I've poked around a little bit in the SDK source code and have a decent idea of where to start, but uncommented source code is such a pain to work with.

Since the SDK has been out for a while, I wondered if there is commented source code out there, or if anyone can point me to a thread someone's started about how to modify the AI's city placement logic.

Thanks for any advice/help, including: "no one's done that yet..."
 
I'm pretty sure nobody has (publicly) done that yet, and I'm also pretty sure there isn't a set of commented source code out there.

Sorry - and good luck!
 
Rhye has modded it for his mod, Rhye's and Fall of Civilization.

In it the AI is more likely to settle its cities closer together than in vanilla. He also has introduced a procedure which tells the AI what areas it is allowed to settle on (on the world map) to produce more historical results.
 
The Great Apple said:
I'm pretty sure nobody has (publicly) done that yet, and I'm also pretty sure there isn't a set of commented source code out there.

Sorry - and good luck!
Jorgen_CAB has also modified it for the AI to place more importance on rivers and coastal tiles, but he's gone MIA :(
 
I worked on these algorithms so as the AI founds some cities in the ocean (sea colonies).
Actually, every turn, the AI updates what it is called the "found values". Each plot of the map is given a value by the AI. The plots with the highest value will be the targetted plots for the next cities. The function which is called each turn is CvPlayerAI::updateFoundValues.

The value of each plot is determined through the function CvPlayerAI::AI_foundValue. Many parameters are taken into account to calculate the value of a plot: the AI looks if there is some owned tiles, some bonuses, fresh water, hills, coastal land, the AI calculate the potential yields of the plots which would be within the city radius, the distance between that plot and the settler, the number of friendly cities, and so on.
Consequently, if you want to modify the way the AI chooses the plot where it settles its new cities, it is, namely, by modifiying this function.

The AI also uses the found values to determine if new settlers are requiered: when the AI chooses the production of a city, it looks if there is some good plots where to build a city, and if so, there is a chance that the city chooses to produce the settler.

If you want a detailled explanation about how works the AI_foundValue, maybe I could try to do that tomorrow.
 
Back
Top Bottom