Solutions to the AI neglect of certain buildings

Alzara

Emperor
Joined
Jan 2, 2008
Messages
1,214
Location
Florida
Hey guys

Just thought I'd post some of my ideas to solve the problem of the AI neglecting buildings like stables and training yards etc...

For stables:
Add +1 :health: with horses.

This would ensure that the AI built this building once they actually had access to horses. As a greater incentive this health bonus could be raised to +2 :health: (or just +1 :health: and an additional +1 :health: from stirrups to give more of an incentive as the AI progresses down the mounted line). From a logic perspective, the health would be due to increased mobility of people and goods... just like the BtS public transportation building.


For training yards:
Add +2 XP for all new melee units.

I know this is quite a large XP bonus, but it would allow for 1-promotion melee units without civics like apprenticeship. Also, despite the incentive for the AI, the bonus would only be given to melee units so wouldn't be too broken.


For archery ranges:
Add +1 XP for all new archery units

The reason I didn't make this as large as the training yard bonus is because the archery range also slaps on a small defensive bonus and, because Bowyers give an even large bonus later. Hopefully the small XP boost would give the AI the incentive to build this building.

Any other thoughts?

Al
 
Well, Ice stage is coming in not too long, so the AI issues will be fixed eventually.

I don't know much about how things are balanced at this point so I can't really give my opinion, although it seems like those are workable ideas.
 
While I don't see any problems with what you've suggested, there may be a solutiion already extant in the XML.

<iAIWeight>0</iAIWeight>

Toggling that value to 1 in the BuildingInfos.xml under the buildings in question should force the AI to prioritize those buildings without needing to give the bonuses. This would also allow one to customize each civ to build the right path for its UUs.
 
Actually it's an integer not a boolean, so it'll want to be higher than 1 to actually pay attention I'd think :)
 
Where can this value be found? In which XML?

Btw I assume boolean values for civ are 0 an 1 (for true/false conditions)?

Al
 
Where can this value be found? In which XML?

Btw I assume boolean values for civ are 0 an 1 (for true/false conditions)?

Al
BuildingInfos.xml. You'll find it in the Assets/XML/Buildings folder.

As for boolean values, yes, that's right. However, BeefontheBone is correct in that it is a integer, and not a boolean value. I took a look at the Training Yard entry and Team FfH has already set the value to 80%.
Spoiler :
<iAIWeight>80</iAIWeight>

The Grove, however, only has a 40% weight. If certain buildings are already weighted and the AI is still neglecting them, the values may need raising and/or your proposed system of bonuses will need to be added to "sweeten the deal" for the AI.
 
So can the weight be set higher than 100%... how does weight function... I assume it's more than just a ranking system for building importance to the AI?

Al
 
So can the weight be set higher than 100%... how does weight function... I assume it's more than just a ranking system for building importance to the AI?

Al
Sorry, I don't know if it can be higher than 100%. Nor do I know exactly how it functions: I'm only a cut & paste modder, and the tutorials I found only covered adding civs and adding new units. Could not find an explanation of the BuildingInfos, which is why I thought the AI weight value was a boolean value like many of the UnitInfo toggles. (At least based on the similar value in UnitInfos, the AI should give build priority to buildings with a higher weight.)
 
Apparently it is just a number, not a percentage so I've found out (and it can go as high as you like)... :)

Al
 
Apparently it is just a number, not a percentage so I've found out (and it can go as high as you like)... :)
Good to know. Guess one could set it really high (say 200) for the Bannor since the melee line is important to them and that might fix things.
 
I don't really want to change weighting atm, just give real incentives to build these neglected buildings.

Ive been changing my XML to see how it works. Implemented the horse health thing (+1 :health: with horses) for the stable, +2XP melee units from all training yards, although I can't really decide what to give the archery ranges.

+2XP would make it a copy of the Bowyer, so I was thinking about adding 1 XP for the archery range, and upping the bowyer XP bonus to +3. Hopefully this wouldn't unbalance the archery route so much.

Also, is it much of a problem if the Sheaim miss out on the XP bonus from training yards? Maybe I should make the planar gate provide XP?

Any other thoughts? :)

Al
 
Careful with adjusting the weighting of the buildings, as well as tossing on modifiers. You really have to look at the formula which the computer uses to decide what to build in these cases. The AIWeight value is where you are supposed to place a number to reflect the relative importance of special features you implement via Python, or complex integration of multiple factors.

The AI will parse out what is in the XML, and each field (if placed by a responsible/aware modder) will be assigned a certain numeric value to the AI. Then whenever it has to build something it grabs all of those numbers, multiplies many of them by values from other XML fields (to account for their current status, such as war, close neighbors, personal agenda, current Civic/Religion...), and then whichever item comes out with the highest score is what they will build, with no new calculation being done until forced to re-evaluate, typically by finishing the current project, or a change in Civic/Religion.


It would be nice to also include a hefty random factor in the calculations at some point, but it can be as tricky deciding where to place that as it is deciding how large of a value to assign to each field in the XML.

To see the formulas, and preferably provide feedback on them, look in CvCityAI.cpp & CvPlayerAI.cpp (in the DLL download, first page of the Modders Thread)
 
Ahh cool thanks Xien :)

Yeah I thought that changing weights would be a bit extreme.

I'm still gonna test out my modifiers.... just to see if they work well...

Al
 
yes, the weighting can be set higher than 100, the Clans Warrens are set to 300, the Sheaim's Planar Gate is set to 300 and the Mercurian Gate is set to 300.
 
Yeah, adding bonuses to buildings to try to get the AI to build them isn't the right way to fix the problem. Some buildings may benifit from some bonuses from a balance perspective, but dont add them just to get the AI to build them.

The better way is to use AIWeight. Really thats all thats going on in the background to get the AI to build buildings (so instead of adding +100 weight because the building adds +1 health, just add the +100).

But really the best of the best options is to get the AI to knwo when to build each of them. It isnt always best to make nothing but buildings, a classical start allows a lot of training buildings right off but an ai that does nothing but build them all is going to be to weak for a long time.

We did make changes in 0.30 so that the ai is better about building training buildings. But some refinement in that algorithym is still needed.
 
There's also "AI_chooseProduction" in the Python that can be used if you're sure you absolutely want the AI to choose something instead of the normal builds. For instance, you may decide that the Bannor and Khazad civs should both build Training Yards as soon as the city reaches 5 population, provided that there are at least 3 units with a total strength of 10 or more in the city.

This is more like "expert system" AI than the weightings used elsewhere though - it's an "if this set of conditions is met, then this is the best thing to do everytime" approach. Hard to perfect - but then again, so are the weightings.
 
You should for instance create a new FLAVOR_MELEE, give a melee value of 10 to the Training Yard and give a melee flavour value of 50 to 100 to the leaders you want to focus on melee units.
 
Yeah, adding bonuses to buildings to try to get the AI to build them isn't the right way to fix the problem. Some buildings may benifit from some bonuses from a balance perspective, but dont add them just to get the AI to build them.

The better way is to use AIWeight. Really thats all thats going on in the background to get the AI to build buildings (so instead of adding +100 weight because the building adds +1 health, just add the +100).

But really the best of the best options is to get the AI to knwo when to build each of them. It isnt always best to make nothing but buildings, a classical start allows a lot of training buildings right off but an ai that does nothing but build them all is going to be to weak for a long time.

We did make changes in 0.30 so that the ai is better about building training buildings. But some refinement in that algorithym is still needed.

Hehe well until there is something to change the AI, I'm gonna use my bonuses... unless it breaks the game. Seems to be working OK so far...

Al
 
You should for instance create a new FLAVOR_MELEE, give a melee value of 10 to the Training Yard and give a melee flavour value of 50 to 100 to the leaders you want to focus on melee units.

I just tried this one out with Bannor/Clan - gave both leaders (Sabathiel/Jonas) a FLAVOR_MELEE of 100 and gave TrainingYard/BannorTrainingYard and Bronzeworking a FLAVOUR_MELEE of 30.

Jonas seems to get Bronzeworking around Turn 120 or so and then produces axemen fine. Sabathiel on the other hand is rushing Crafting/Mining, then completely ignores Bronze Working and starts to research Agriculture, Hunting, Masonry and Construction. It looks like his "FLAVOR_PRODUCTION" is being emphasized by the early game growth AI and dragging him off down that path.

EDIT: Just tried boosting the FLAVOR_PRODUCTION for Bronze Working to make it more appealing to Sabathiel. He researched absolutely anything except Bronze Working. Horseback Riding (no horses - didn't try to get trade), Archery, Mysticism, Ancient Chants - every line except Melee. He rushed to Mining at the start, then ignored what should have been the tech that matched all of his flavours. I'm beginning to think he's just a bit thick...

Jonas also crushed him utterly with an axeman stack in turn 254.
 
You should also give FLAVOR_MELEE to the Bronze Working and similar techs.

Check out the Rise of Mania mod if you're interested in this for your own modmod. It's outdated, so it won't start up, but you can look at the XML files for where I used what flavours (of course taking into account that was for v22 including my own modifications). In any case, the AI seemed to perform much better than it is doing even now in FfH.
 
Back
Top Bottom