How to teach AI to build new buildings?

The AI seems to build everything it's able to, at least at higher difficulty levels. Never had to "teach" them to build new buildings. Not sure there really is a way to do so.
 
No wonder it's considered stupid (AI) if the only algorithm is 'build whatever you can'.

Jokes aside, there has to be some logic. Granted that due to districts, building construction was greatly simplified - there's one path per district basically. But what happens if there will be more choices?
 
Maybe it follows the Advisor tags? They do seem to have some sort of priority list when it comes to buildings, but I didn't see anything except Wonders in the AI priority stuff.

With that said, if you add new buildings it does seem like the AI will build them as long as it has the appropriate district. At lower difficulty levels though it might not have the production to keep up and prefer to build units.
 
Does your building have a direct yield in <Building_YieldChanges> ?

I haven't checked yet whether all standard buildings have an actual yield assigned within the table, but the ones that don't (so far as I have checked) seem to have a housing or entertainment effect, or are wonders. The reason I'm asking is this found in the Leaders.xml:
Spoiler :
Code:
<AiFavoredItems>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_FOOD"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_PRODUCTION"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_GOLD"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_SCIENCE"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_CULTURE"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_FAITH"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_CITY_DEFENSES" Value="-1"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_MILITARY_UNITS" Value="1"/>
	<Row ListType="DefaultCitySpecialization" Item="BUILD_TRADE_UNITS" Value="2"/>

	<Row ListType="DefaultCityBuilds" Item="CITY_EVENT_DEFAULT" StringVal="Simple City Tree"/>
	<Row ListType="DefaultCityBuilds" Item="CITY_EVENT_UNIT_OR_BUILDING" StringVal="Build City Building"/>
	<Row ListType="DefaultCityBuilds" Item="CITY_EVENT_DISTRICT" StringVal="Build City District"/>
	<Row ListType="DefaultCityBuilds" Item="CITY_EVENT_IMPROVEMENT" StringVal="Build City Improvement"/>
	<Row ListType="DefaultCityBuilds" Item="CITY_EVENT_WONDER" StringVal="Seek Target Wonder"/>
	<Row ListType="DefaultCityBuilds" Item="CITY_UNDER_THREAT" StringVal="City Defense"/>
</AiFavoredItems>
<AiBuildSpecializations>
	<Row SpecializationType="BUILD_FOR_FOOD" BuildingYield="YIELD_FOOD" IncludePopulation="true" PrioritizationYield="YIELD_FOOD"/>
	<Row SpecializationType="BUILD_FOR_PRODUCTION" BuildingYield="YIELD_PRODUCTION" PrioritizationYield="YIELD_PRODUCTION"/>
	<Row SpecializationType="BUILD_FOR_GOLD" BuildingYield="YIELD_GOLD" PrioritizationYield="YIELD_GOLD"/>
	<Row SpecializationType="BUILD_FOR_SCIENCE" BuildingYield="YIELD_SCIENCE" PrioritizationYield="YIELD_SCIENCE"/>
	<Row SpecializationType="BUILD_FOR_CULTURE" BuildingYield="YIELD_CULTURE" PrioritizationYield="YIELD_CULTURE"/>
	<Row SpecializationType="BUILD_FOR_FAITH" BuildingYield="YIELD_FAITH" PrioritizationYield="YIELD_FAITH"/>
	<Row SpecializationType="BUILD_CITY_DEFENSES" IncludeDefense="true" PrioritizationYield="YIELD_PRODUCTION"/>
	<Row SpecializationType="BUILD_MILITARY_UNITS" IncludeMilitaryUnits="true" PrioritizationYield="YIELD_PRODUCTION"/>
	<Row SpecializationType="BUILD_TRADE_UNITS" IncludeTradeUnits="true" PrioritizationYield="YIELD_GOLD"/>
</AiBuildSpecializations>
The default Value for <AiFavoredItems> is "0", so military and trade units would appear to be favored higher than just about anything else in the "DefaultCitySpecialization" when that is being applied (and not over-ridden by something like "Build for Defense" or whatever).

Just spitballing here and I could be full of beans, but I am guessing the item's "Yield" is being looked for in the <Building_YieldChanges> table in order to determine whether the building is good for food, for example, when the AI decides to go for food in a city.
 
Interesting. I wonder if assigning a YieldChange of 0 would influence the AI to build the building, since it seems the default values for that table are all null.
 
Running this listener through lua tells me that at least one AI city is constructing my new building called BUILDING_LRS_HOUSING0, which gives +1 Housing and +1 Food and is buildable in the city center at the start of the game. This is running at Prince difficulty in the test game because I am more interested in making sure the various effects and conditions are working correctly than in whether or not the AI wants the new buildings I am adding to the game at high difficulty level.

Spoiler lua code :
Code:
function PrintAllCityProductionItems(iPlayer, bIsFirstTime)
	local pPlayer = Players[iPlayer]
	if pPlayer:IsHuman() then
		local iNumMajorCivs = PlayerManager.GetAliveMajorsCount();
		for iLoopPlayer = 0, iNumMajorCivs - 1 do
			local pLoopPlayer = Players[iLoopPlayer]
			if pLoopPlayer:IsAlive() then
				local sPlayerCivName = PlayerConfigurations[iLoopPlayer]:GetCivilizationTypeName()
				local sPlayerLeaderName = PlayerConfigurations[iLoopPlayer]:GetLeaderTypeName()
				print("[PrintAllCityProductionItems] Player # " .. iLoopPlayer .. " is being used as " .. sPlayerCivName .. " with leader of " .. sPlayerLeaderName)
				local pCities = pLoopPlayer:GetCities();
				if pCities:GetCount() > 0 then
					for i, pCity in pCities:Members() do
						print("[PrintAllCityProductionItems] " ..  Locale.Lookup(pCity:GetName()) .. " is producing " .. tostring(pCity:GetBuildQueue():CurrentlyBuilding()))
					end
				else
					print("[PrintAllCityProductionItems] " .. sPlayerLeaderName .. " has no cities")
				end
			end
		end
	end
end
Events.PlayerTurnActivated.Add(PrintAllCityProductionItems)
Spoiler lua log result :
Code:
Player # 0 is being used as CIVILIZATION_ROME with leader of LEADER_TRAJAN
Rome is producing BUILDING_HANGING_GARDENS
Arpinum is producing BUILDING_GRANARY
Antium is producing BUILDING_GRANARY
Player # 1 is being used as CIVILIZATION_NORWAY with leader of LEADER_HARDRADA
Nidaros is producing BUILDING_LRS_HOUSING0
Player # 2 is being used as CIVILIZATION_KONGO with leader of LEADER_MVEMBA
Mbanza Kongo is producing UNIT_SLINGER
Player # 3 is being used as CIVILIZATION_GREECE with leader of LEADER_PERICLES
Athens is producing BUILDING_MONUMENT
Player # 4 is being used as CIVILIZATION_ENGLAND with leader of LEADER_VICTORIA
London is producing UNIT_SLINGER
Player # 5 is being used as CIVILIZATION_ARABIA with leader of LEADER_SALADIN
Cairo is producing UNIT_SLINGER
Player # 6 is being used as CIVILIZATION_JAPAN with leader of LEADER_HOJO
Kyoto is producing UNIT_SLINGER
Player # 7 is being used as CIVILIZATION_INDIA with leader of LEADER_GANDHI
Delhi is producing BUILDING_MONUMENT
Player # 8 is being used as CIVILIZATION_RUSSIA with leader of LEADER_PETER_GREAT
St. Petersburg is producing UNIT_SLINGER
Player # 9 is being used as CIVILIZATION_AMERICA with leader of LEADER_T_ROOSEVELT
Washington is producing UNIT_SLINGER
*note that I took the header stuff out of the front of each of these printed lines
I am playing as Rome, btw. But you can see that the AI is still heavily favored toward units.
 
@LeeS Interesting idea. Doesn't solve the problem but seems like a right direction.
All my new buildings have Yields in the yields table. Many have also various combinations of Housing, Amenities, Regional Range, etc. I've created a mod with 47 upgrades to existing buildings. So basically all combinations are there.
And AI builds only: an upgrade to Palace and all Defensive buildings (walls). Yes. It builds wall upgrades which means that Value parameter for DefaultCitySpecialization could mean something else since it's -1 for city defenses.
 
so far the AI only seem to be going for the buildings that my mod adds which give extra amenity and housing. There are other choices available that I've added and are available at game-start, but they seem as yet not interested in them. Perhaps because the other buildings I am adding that can be constructed at the start of a game (ie, at the encient era turn 0) only add +1 of a yield along with a % city total yield increase and the AI aren't actually programmed to be able to understand a % yield increase.

Spoiler :
:cry:

at least in Civ5 we could always just crank up the flavor settings to get an AI to at least sort-of value a building when their code determined for example they should go for food in a given city
 
That's odd. I know in my Wondrous Wonders mod, the AI does build the National Wonders, even when they don't give amenities or housing. Heck, the Library of National History and National Epic are very frequent builds and have no flat yields at all.

Maybe it's Great Person points? All of them do give Great People points, which could help the AI out.
 
It might be that wonders in general are treated differently. From AI perspective they all should be worth building.

@LeeS I have buildings with housing and amenities in later eras, will try to check if they are built.
 
It might be that wonders in general are treated differently. From AI perspective they all should be worth building.

@LeeS I have buildings with housing and amenities in later eras, will try to check if they are built.

My National Wonders don't use the Wonder tag, they're just considered buildings with MaxPlayerInstnaces=1

I don't imagine that tag could cause the AI to prioritize them, but I do suppose it's possible.
 
Further monitoring is showing me they're building pretty much everything from the new 'regular' buildings I've added to the game. However I'm going to have to start my test-game over after I figure out where I goofed on my modifer requirements/requirement sets for one building.
 
I've got good news! :goodjob: It seems that I hurried a little bit this topic and some patience was needed. I can confirm that AI builds all my upgrades. Only not immediately (except for walls) - just, well... some time after.. like an Era or two :) But that makes sense and confirms a theory that there's some logic that weights building's value (yields, properties, etc.) vs. its cost and most importantly maintenance cost. My buildings are designed to be rather expensive in terms of maintenance, I specifically wanted them to be built by a player after careful consideration if they are worth it. That's probably why it took AI so long to evaluate them as 'worthy'. This is the first time that I'm kind of impressed by Civ6's AI...
 
Does your building have a direct yield in <Building_YieldChanges> ?

I haven't checked yet whether all standard buildings have an actual yield assigned within the table, but the ones that don't (so far as I have checked) seem to have a housing or entertainment effect, or are wonders. The reason I'm asking is this found in the Leaders.xml:
Spoiler :
Code:
<AiFavoredItems>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_FOOD"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_PRODUCTION"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_GOLD"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_SCIENCE"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_CULTURE"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_FOR_FAITH"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_CITY_DEFENSES" Value="-1"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_MILITARY_UNITS" Value="1"/>
    <Row ListType="DefaultCitySpecialization" Item="BUILD_TRADE_UNITS" Value="2"/>

    <Row ListType="DefaultCityBuilds" Item="CITY_EVENT_DEFAULT" StringVal="Simple City Tree"/>
    <Row ListType="DefaultCityBuilds" Item="CITY_EVENT_UNIT_OR_BUILDING" StringVal="Build City Building"/>
    <Row ListType="DefaultCityBuilds" Item="CITY_EVENT_DISTRICT" StringVal="Build City District"/>
    <Row ListType="DefaultCityBuilds" Item="CITY_EVENT_IMPROVEMENT" StringVal="Build City Improvement"/>
    <Row ListType="DefaultCityBuilds" Item="CITY_EVENT_WONDER" StringVal="Seek Target Wonder"/>
    <Row ListType="DefaultCityBuilds" Item="CITY_UNDER_THREAT" StringVal="City Defense"/>
</AiFavoredItems>
<AiBuildSpecializations>
    <Row SpecializationType="BUILD_FOR_FOOD" BuildingYield="YIELD_FOOD" IncludePopulation="true" PrioritizationYield="YIELD_FOOD"/>
    <Row SpecializationType="BUILD_FOR_PRODUCTION" BuildingYield="YIELD_PRODUCTION" PrioritizationYield="YIELD_PRODUCTION"/>
    <Row SpecializationType="BUILD_FOR_GOLD" BuildingYield="YIELD_GOLD" PrioritizationYield="YIELD_GOLD"/>
    <Row SpecializationType="BUILD_FOR_SCIENCE" BuildingYield="YIELD_SCIENCE" PrioritizationYield="YIELD_SCIENCE"/>
    <Row SpecializationType="BUILD_FOR_CULTURE" BuildingYield="YIELD_CULTURE" PrioritizationYield="YIELD_CULTURE"/>
    <Row SpecializationType="BUILD_FOR_FAITH" BuildingYield="YIELD_FAITH" PrioritizationYield="YIELD_FAITH"/>
    <Row SpecializationType="BUILD_CITY_DEFENSES" IncludeDefense="true" PrioritizationYield="YIELD_PRODUCTION"/>
    <Row SpecializationType="BUILD_MILITARY_UNITS" IncludeMilitaryUnits="true" PrioritizationYield="YIELD_PRODUCTION"/>
    <Row SpecializationType="BUILD_TRADE_UNITS" IncludeTradeUnits="true" PrioritizationYield="YIELD_GOLD"/>
</AiBuildSpecializations>
The default Value for <AiFavoredItems> is "0", so military and trade units would appear to be favored higher than just about anything else in the "DefaultCitySpecialization" when that is being applied (and not over-ridden by something like "Build for Defense" or whatever).

Just spitballing here and I could be full of beans, but I am guessing the item's "Yield" is being looked for in the <Building_YieldChanges> table in order to determine whether the building is good for food, for example, when the AI decides to go for food in a city.
Sorry to necro this thread but you seem to be the only person who knows how "Value" works. Is a ranking number? As in, a Value 1's get built before Value 2's? I'm trying to add some AI behavior to my first Civ.
 
Top Bottom