Artificial Unintelligence

Question for you, is there a way to shut off AI plot buying

Just make

Code:
void CvEconomicAI::DoPlotPurchases()

to terminate in all situations (i.e. by default, AI will not buy plots during war-time).


You can also try toying around with AI_GOLD_PRIORITY_MINIMUM_PLOT_BUY_VALUE and AI_GOLD_BALANCE_TO_HALVE_PLOT_BUY_MINIMUM.
 
I am having the most glorious test game right now. I'm about to pinch myself.

I made everyone's boldness value 2... now almost every settler was escorted. Not 1 was taken.

I also set it so patrolling had a -1 value. Units are staying in cities, there's more military functions outside with barbs happening. This is just amazing.

I want to think this is just luck, because it would be far too easy if this can really solve this problem, but I'm in awe right now watching the AI have a sane start.
 
I am having the most glorious test game right now. I'm about to pinch myself.

I made everyone's boldness value 2... now almost every settler was escorted. Not 1 was taken.

I also set it so patrolling had a -1 value. Units are staying in cities, there's more military functions outside with barbs happening. This is just amazing.

I want to think this is just luck, because it would be far too easy if this can really solve this problem, but I'm in awe right now watching the AI have a sane start.

You need to be careful of screwing over the AI's behaviour patterns in other areas, such as number of military units desired, site evaluation for new cities, odds of giving in to diplomatic demands, among other things that uses boldness as a factor...
 
You need to be careful of screwing over the AI's behaviour patterns in other areas, such as number of military units desired, site evaluation for new cities, odds of giving in to diplomatic demands, among other things that uses boldness as a factor...

I understand your concern. I was worried that the AI would be less inclined to war with a low boldness number. That is not the case, there have been several wars.

This is ridiculously cool. I can upload the version, and you can run a test if you'd like to see it.

I will do a search for boldness in the DLL and see all the areas I've affecting it with a low number. My expectation is that perhaps AuI can remove the boldness impacting Settler escorting, and then I don't need a low boldness.

The major factor was shutting off the Patrolling. The AI is acting like a player now.

Maybe this is all a dream, and the next test is horrific, but this is mindboggling better than any test I've run.

Question for you - There are no religious flavors, and no aiweight for beliefs. Is there anyway to change the AI's belief choices that you know of?

I'd like to stop them from selecting horrible beliefs.
 
I did a quick search, the escort behaviour (with regards to boldness) you were observing was most likely this routine inside

void CvAIOperationFoundCity::Init

Code:
					// There was no escort immediately available.  Let's look for a "safe" city site instead

					if (eOwner == -1 || GET_PLAYER(eOwner).getNumCities() > 1 || GET_PLAYER(eOwner).GetDiplomacyAI()->GetBoldness() > 5) // unless we'd rather play it safe
					{
						pNewTarget = FindBestTarget(pOurCivilian, true);
					}
 
I did a quick search, the escort behaviour (with regards to boldness) you were observing was most likely this routine inside

void CvAIOperationFoundCity::Init

Code:
					// There was no escort immediately available.  Let's look for a "safe" city site instead

					if (eOwner == -1 || GET_PLAYER(eOwner).getNumCities() > 1 || GET_PLAYER(eOwner).GetDiplomacyAI()->GetBoldness() > 5) // unless we'd rather play it safe
					{
						pNewTarget = FindBestTarget(pOurCivilian, true);
					}

Yes, I am aware of that, which is why I did it. I made it lower than 5 because I believe I saw a rand in there as well to make it not be deterministic. But I want deterministic when testing, to prove something works.

This was a test. I'm on the second game now, on a massive map so I'd have a lot of test cases. It's working wonderfully.
 
Also, Lowering boldness across the board, I get the feeling is impacting the wars. Most of the time a war is declared in these tests, the warring AI succeeds. This is ideal behavior for me, I'd prefer the AI succeeds when they go to war.

It means they have enough units over their opponent to deal with their poor pathing issues.
 
AUI_MILITARY_DISBAND_OBSOLETE_TWEAKED - Is disbanding units when the Civ has a gold surplus, as it is creating units to go to war.

The player went to war soon after with one less useful troop, for no reason. The treasury was low because the player just bought a unit, but GPT was still positive (by a lot) and the unit was a Composite Bowman, when they are still useful. Yes, the player had a crossbowman too (they upgraded), and reached the tech, but that's no reason to disband the unit.
 
When the AI tries to remove barbarian camps, often they will get stuck in a loop of not attacking due to the expected result of damage (i.E. barb camp on rough terrain), and will then move to a free tile, and repeat this process over and over again in a loop.

I've corrected the problem by making a mandatory ranged unit in the group so they can deal with the issue. From there, it's a walk in the park.
 
AUI_MILITARY_DISBAND_OBSOLETE_TWEAKED - Is disbanding units when the Civ has a gold surplus, as it is creating units to go to war.

The player went to war soon after with one less useful troop, for no reason. The treasury was low because the player just bought a unit, but GPT was still positive (by a lot) and the unit was a Composite Bowman, when they are still useful. Yes, the player had a crossbowman too (they upgraded), and reached the tech, but that's no reason to disband the unit.

This happened again in my next test. This time the AI was negative GPT, but the AI was building to go to war, and then in consecutive turns disbanded archers, only to then request them to be built again.

They did have a positive treasury. At the rate of negative gpt, they had about 14 turns before running out of money. The units would have been dead in the war and not needed disbanded, or they would have taken the city, and thus had more gold.
 
This is how the AI selects all religious choices

Spoiler :
/// Select the belief most helpful to this pantheon
BeliefTypes CvReligionAI::ChoosePantheonBelief()
{
CvGameReligions* pGameReligions = GC.getGame().GetGameReligions();
CvWeightedVector<BeliefTypes, SAFE_ESTIMATE_NUM_BELIEFS, true> beliefChoices;
std::vector<BeliefTypes> availableBeliefs = pGameReligions->GetAvailablePantheonBeliefs();
for(std::vector<BeliefTypes>::iterator it = availableBeliefs.begin();
it!= availableBeliefs.end(); ++it)
{
const BeliefTypes eBelief = (*it);
CvBeliefEntry* pEntry = m_pBeliefs->GetEntry(eBelief);
if(pEntry)
{
const int iScore = ScoreBelief(pEntry);
if(iScore > 0)
{
beliefChoices.push_back(eBelief, iScore);
}
}
}
#ifdef AUI_RELIGION_FIX_POSSIBLE_NULL_POINTER
BeliefTypes rtnValue = NO_BELIEF;
if (beliefChoices.size() > 0)
{
// Choose from weighted vector
beliefChoices.SortItems();
int iNumChoices = MIN(beliefChoices.size(), 3); // Throw out two-thirds of the choices -- this was way too loose as choices way down were being selected now only top 3
#ifdef AUI_RELIGION_RELATIVE_BELIEF_SCORE
#ifdef AUI_FAST_COMP
int iToDecrease = -FASTMAX(beliefChoices.GetWeight(beliefChoices.size() - 1) - 1, 0);
#else
int iToDecrease = -MAX(beliefChoices.GetWeight(beliefChoices.size() - 1) - 1, 0);
#endif // AUI_FAST_COMP
for (int iI = 0; iI < beliefChoices.size(); iI++)
{
beliefChoices.IncreaseWeight(iI, iToDecrease);
}
#endif // AUI_RELIGION_RELATIVE_BELIEF_SCORE
RandomNumberDelegate fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);
rtnValue = beliefChoices.ChooseFromTopChoices(iNumChoices, &fcn, "Choosing belief from Top Choices");
LogBeliefChoices(beliefChoices, rtnValue);
}
else
{
rtnValue = availableBeliefs.at(GC.getGame().getJonRandNum(availableBeliefs.size() , "Choosing random Pantheon belief."));
}
#else
// Choose from weighted vector
beliefChoices.SortItems();
int iNumChoices = MIN(beliefChoices.size(),3); // Throw out two-thirds of the choices -- this was way too loose as choices way down were being selected now only top 3
RandomNumberDelegate fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum);
BeliefTypes rtnValue = beliefChoices.ChooseFromTopChoices(iNumChoices, &fcn, "Choosing belief from Top Choices");
LogBeliefChoices(beliefChoices, rtnValue);
#endif // AUI_RELIGION_FIX_POSSIBLE_NULL_POINTER
return rtnValue;
}



So, I read that as the AI randomly makes religious choices when deciding beliefs. It's copy and pasted for every type, should have just used 1 routine that was the same in that case.

There's no flavors to use, that would be the sanest way to handle it. Export out the options as flavors, make a new table with all 5's to start.

From there, you can check the resources in workable tiles, and focus the value more on that.

My base values for Pantheons for AI -
Spoiler :

Ancestor Worship +1 Culture from Shrines

Positive is that the AI doesn't need any special coding to use it, as it's passive. Just needs Shrines

Negative is that it's limited by the number of cities, but for Deity AI, that doesn't seem as bad. The AI tends to make a lot of cities, especially on Deity.

Dance of the Aurora +1Faith from Tundra tiles without Forest (Resource tiles on Tundra without Forest also qualify)

The AI shouldn't be working Tundra tiles. Maybe if you're surrounded in them.

Desert Folklore +1 Faith from Desert tiles (All types, including Flood plains and Oasis, as well as Resource tiles on desert)

If Desert then Choose.

Earth Mother BNW-only +1 Faith for each Copper, Iron, and Salt resource

If Copper, Iron, Salt then add up resources, count number against resource choices.

Should probably always choose resource choice, which ever is highest the most.

Faith Healers +30 HP healed per turn if adjacent to a friendly city

Too hard for the AI to use well. Any resource one should beat it.

Fertility Rites 10% faster Growth rates

It only works on food overflow, so it's not that great. But it's completely passive, so the AI will get it's use.

I think this is not a bad choice if no resource ones for the AI

God of Craftsmen +1 Production in cities with Population of 3+

There are better ones, but if no resources it's passive so that's great for the AI

God of the Open Sky +1 Culture from Pastures

Resource good

God of the Sea +1 Production from Fishing Boats

Resoure good, might be useful to queue a work boat if chosen (obviously must have sea resources)

Goddess of Festivals +1 Culture and +1 Faith for each Wine and Incense

resource

Goddess of Love +1 Happiness from cities with Population of 6+

The AI needs as much help with happiness on low levels, not on high levels. If you could separate it by difficulty, that'd be best I think. It's passive, that's good.

Ultimately not huge, but every bit helps.

Goddess of Protection +30% increase in city Ranged Combat Strength

Only if about to die, or extremely threatened

Goddess of the Hunt +1 Food from Camps

resource

God-King BNW-only Palace provides +1 Culture, Faith, Gold, Production, and Science

Best AI choice by far. Should be first one off the board. Entirely passive, all important. First choice unless land is insane.

Any AI that chooses God-King is going to be strong. It helps give buffer for odd or bad AI decisions on a lot of different areas.

Messenger of the Gods +2 Science in cities with a City Connection

Not a top choice for me, it's too particular. At the same time, the AI loves roads, and has a high build route flavor. I think that's fair considering how bad the military AI is, you need as much mobility as possible to engage threats.

I think there are other choices. I don't hate it.

Monument to the Gods +15% Production for Ancient/Classical Wonders


Maybe only if high wonder flavor

One with Nature +4 Faith from Natural Wonders

If natural wonder

Oral Tradition +1 Culture from Plantations

If plantations count > whatever

Religious Idols +1 Culture and +1 Faith for each Gold and Silver

resources

Religious Settlements
15% faster border growth

Positive it's passive, negative it's not great.

Sacred Path +1 Culture from Jungle tiles (Resource tiles in a Jungle also qualify)
if jungle

Sacred Waters +1 Happiness from cities on rivers

There are better happiness ones, the AI can't exactly just decide on rivers. Not for the AI

Stone Circles +2 Faith from Quarries

resource

... the rest are resources.
 
I'll have a look at boldness values then and see if I can find algorithms to fix.
I'm not in favor of setting it low for everyone, since a lot of non-combat decisions are also boldness-based. For example, an AI with low boldness will never settle cities near opponents' cities, even if it would nab them a crucial tile and they have the military to defend the new city.

Beliefs aren't selected randomly: instead, they are scored, then a random belief is selected out of a weighted list of the top 3 scoring beliefs. Firaxis realized they couldn't just make general flavors for beliefs because they are so conditional, so scoring is effect-based instead of per-belief (much like how promotions are also effect-based).
Scoring is done via ScoreBelief(), which is split into 3 parts doled out to 3 C++ functions: ScoreBeliefAtPlot() (where unowned plots, owned but not worked plots, and worked plots get different weighting), ScoreBeliefAtCity(), and ScoreBeliefForPlayer(). Each belief effect has a different way of getting scored, and although I did a bit of tweaking previously, it was fairly minimal and not that thoroughly tested (only the AtPlot() ones were out of necessity). If you want, I can try listing all effects' scoring so you don't have to read through my poorly written CvReligionClasses code.

I've done a few changes to plot patrolling, eg. the AI now prefers patrolling on border and/or road tiles (former to keep an eye on its territory, latter so that mobilization is quick), and coupled with the DangerPlots changes, I don't think it's that problematic in my v10 dev version.

I made a few code rearrangements to try to reduce undesirable unit disbanding (eg. the AI would start counting up its "obsolescence doomclock" even if it was in a war pre-v10, so I've rearranged that to no longer happen in my dev v10 version). I'm still quite reliant on the original obsolete unit disbanding logic though, primarily because I've been more worried about other things (like some combat bonuses actually being applied incorrectly, or the fact that the AI could not calculate the amount of ranged damage a unit would deal out of a tile other than the its current one) to address it properly.

I haven't been seeing that barbarian camp loop in my v10 version (and I've been looking a lot at how the AI calculates when to attack), so I assume my new DangerPlots eliminates the issue. Plus I've sort of reworked the attack launching algorithm due to having done away with queued attacks, which are quite possibly the stupidest thing Firaxis has ever made: they have absolutely no benefit, not even a minor one (like being able to handle groups of units a bit easier for operations), they require a boatload of extra code, and they lead the AI to make poorer decisions. Pre-v10, queued attacks mean that the AI always queues up units to attack a target based on expected damage output, then it fires off all attacks at once and hopes the random rolls go its way. In v10, the AI will fire off attacks one-by-one and decide whether to continue and/or attack with more units after the combat rolls have happened, just like a human player would.

Also, the Experimental GitHub branch for the mod is a bit outdated due to me having had a busy few set of weeks and not having the time to properly commit my changes.
 
I'll have a look at boldness values then and see if I can find algorithms to fix.
I'm not in favor of setting it low for everyone, since a lot of non-combat decisions are also boldness-based. For example, an AI with low boldness will never settle cities near opponents' cities, even if it would nab them a crucial tile and they have the military to defend the new city.

Boldness is my way of fixing the problem with Settlers being tied to boldness. Don't change boldness values, remove boldness from sending out settlers unescorted.
 
Beliefs aren't selected randomly: instead, they are scored, then a random belief is selected out of a weighted list of the top 3 scoring beliefs. Firaxis realized they couldn't just make general flavors for beliefs because they are so conditional, so scoring is effect-based instead of per-belief (much like how promotions are also effect-based).
Scoring is done via ScoreBelief(), which is split into 3 parts doled out to 3 C++ functions: ScoreBeliefAtPlot() (where unowned plots, owned but not worked plots, and worked plots get different weighting), ScoreBeliefAtCity(), and ScoreBeliefForPlayer(). Each belief effect has a different way of getting scored, and although I did a bit of tweaking previously, it was fairly minimal and not that thoroughly tested (only the AtPlot() ones were out of necessity). If you want, I can try listing all effects' scoring so you don't have to read through my poorly written CvReligionClasses code.

My mistake, I'm getting back into modding here, and it's been awhile. I will look into each of those parts.
 
I've done a few changes to plot patrolling, eg. the AI now prefers patrolling on border and/or road tiles (former to keep an eye on its territory, latter so that mobilization is quick), and coupled with the DangerPlots changes, I don't think it's that problematic in my v10 dev version.

The only question is, Do settlers patrol. If yes, it's a huge problem (current version yes) if no, I can turn back on patrolling as an option for units. I had to shut it off completely to fix it.

I made a few code rearrangements to try to reduce undesirable unit disbanding (eg. the AI would start counting up its "obsolescence doomclock" even if it was in a war pre-v10, so I've rearranged that to no longer happen in my dev v10 version). I'm still quite reliant on the original obsolete unit disbanding logic though, primarily because I've been more worried about other things (like some combat bonuses actually being applied incorrectly, or the fact that the AI could not calculate the amount of ranged damage a unit would deal out of a tile other than the its current one) to address it properly.

It has to be rewritten in my opinion. It's better shut off than left the way it is. My quick fix would be to only consider units obsolete if 2 techs behind current, instead of 1.

I haven't been seeing that barbarian camp loop in my v10 version (and I've been looking a lot at how the AI calculates when to attack), so I assume my new DangerPlots eliminates the issue. Plus I've sort of reworked the attack launching algorithm due to having done away with queued attacks, which are quite possibly the stupidest thing Firaxis has ever made: they have absolutely no benefit, not even a minor one (like being able to handle groups of units a bit easier for operations), they require a boatload of extra code, and they lead the AI to make poorer decisions. Pre-v10, queued attacks mean that the AI always queues up units to attack a target based on expected damage output, then it fires off all attacks at once and hopes the random rolls go its way. In v10, the AI will fire off attacks one-by-one and decide whether to continue and/or attack with more units after the combat rolls have happened, just like a human player would.

Also, the Experimental GitHub branch for the mod is a bit outdated due to me having had a busy few set of weeks and not having the time to properly commit my changes.

I'm excited to see the new version. I'm setting up DLL modding on my computer so I can participate.

I don't know what's best, do I fork the code and make my changes, and you can decide to merge them or not?
 
I loaded the latest code line with my changes. oh my god, this is amazing. Military is fixed, you did so much dude.

This is awesome to watch. I really love this first ai vs. ai on prince battle. Civilians still aren't protected enough, but whatever.

If we can get the AI to go after their taken civilians that'd be awesome.
 
I shut off AI Disbanding. The AI has much larger militaries. I also jacked turns from coming back to upgrade to 30 so the AI always sends units back when not busy.

AI is much fiercer this way. I haven't gone through all the money per turn yet, but you can tell the AIs are doing great in Science, and the Wars are interesting.

I think the AI gives up cities too easily in a trade to end war. When the AI ends war on the human, it's always white peace. AI should get the same deal.

This is seriously cool though.
 
So much fun. AI is doing really well for themselves. Tons of money, happiness was more of the problem.

It would be good to switch every city to Production 0 or less happiness, and normal allocations above.

AI was growing out of their mind, which is good, but causes problems. Also forces them to raise cities they take.

It's lovely. I think tomorrow I'm going to just play a game with it.
 
Be careful with the experimental branch: the dev v10 version is very much a dev version, and the fact that I had to create a separate compiler configuration dedicated to debugging elusive issues proves that the "experimental" tag applies for v10 a lot more than it did for the previous versions.

I'm still occasionally encountering DangerPlots-related crashes in my test games, not to mention some unintended military behavior when range 3 units start to be fielded (longbowmen, artillery, etc.). Plus, a lot of DangerPlots-related algorithms are still written with old DangerPlots functionality in mind (fortify to heal, for example), so you'll often get scouts and such just fortifying when under enemy fire. I only just migrated ScoreGreatGeneral() to the new DangerPlots in the early hours of this morning, since they were mostly scoring tiles based on the defending unit's strength, which is what made them sit in cities all the time; the scoring still isn't optimal, since the General still can't properly tell the difference between a defender that could die to attacks and one that's safe to be under.

... and I haven't even mentioned the Great Works swapping-related crashes, either; I thought I might as well remake the Great Works swapping logic as well when I started trying to adapt the original Great Works swapping algorithms to use my remade DangerPlots, since it was due for a rewrite anyway. If you need any explanation why, just look at the original code (brought to my attention after LoneGazebo commented that Great Works swapping was taking up a surprising amount of CPU cycles in AI turns) and feast your eyes on a gallery of bad coding design, from abuse of sequential search to post-incrementing iterators,
I may have fixed the most egregious one that was caused by a stupid mistake on my end (I stored the parameters for swapping great works with another player in the wrong, so the AI ended up trying to swap with the player whose ID matched the to-be-acquired Great Work's ID and vice versa), but I still don't really know how stable or how functional it actually is. It should be more functional than the original Great Works swapping system in theory (and faster, too, since I'm only working with two or three vectors and juggling pointers instead of Firaxis' method of constantly creating and recreating Great Works vectors, most likely written by someone who was more used to high-level languages that don't handle pointers as thoroughly as C/C++): for example, the AI should be able to swap with more than one player at once when trying to fill a single building (before, they'd only try to swap with other players if they were one slot short of fully theming the building), properly prioritize which Great Works are more or less important for them (based on Era/Player rarity), and properly attempt to fill buildings that offer non-theming bonuses if they are filled (eg. Assyrian UB giving military XP). I just don't know if my code holds up in practice though, much like how I'm unsure about my Parthian Shot code.

I still haven't touched the Deal AI or the Diplomacy AI; though the contents of peace deals is determined elsewhere (I haven't found it yet), the actual peace deal "type" the AI prefers is determined in CvDiplomacyAI:: DoUpdatePeaceTreatyWillingness(). By the looks of it, the entire thing seems very gamey and a bit too detached from the military end of things, which is why the AI's peace deals (among others) seem so illogical.
 
By the looks of it, the entire thing seems very gamey and a bit too detached from the military end of things, which is why the AI's peace deals (among others) seem so illogical.

I'd attribute it mostly to how poorly/ambiguously the given weightings for each threshold are calibrated compounded by the (at times) questionable nature of how the thresholds themselves are calculated (some of the benchmarks seem very arbitrary, others will use strength comparisons i.e. total military strength vs total military strength).

One cannot reasonably expect the sum of parts to be functional if the parts themselves are all wonky to begin with.

I mean the original design would, in theory, work decently well (a fuzzy logic based algorithm that takes into account various factors that do not have clear black-and-white thresholds).... but it has become warped to a point where it resembles a points-based step-wise system that is very poorly tuned (I guess they didn't sink much resources into testing the system out).
 
Back
Top Bottom