Version 0.41 Discussion Thread

The main argument against having a big money reserve is that if you have on average 2000 gold pieces more in gold reserve, then on average, you're 2000 research points behind in research. Is it bad to be 2000 points behind in research? Sometimes, it doesn't matter if it is a technology that you won't immediately start using. But more often then not a technology starts producing benefits from the moment it is available. For some technologies, this means a bigger multiplyer for hammers, gold or research, for others a civic change and again for others it means a military advantage.

You can't have it both: have a large gold reserve (on average) and be at the most advanced state that you could be. Note that these small advantages in technology tend to strengthen oneanother. If you have that economic boosting technology one turn earlier, then you can use it to improve your economy one turn earlier which means that other new technologies will come faster, that you can start expanding again one turn earlier, that you can build a gold reserve while still having the same research as before the technology was researched.

All of the above doesn't mean that it's bad for the AI to have a money reserve. Unlike the human player, the AI cannot plan ahead. An AI will be far more susceptible to a surprise attack. It will not see it coming and thus it will not have set aside money for upgrades or have started upgrading troops. The human will do these things as it will see the 'surprise attack' coming 5 turns in advance and react to it.

It's not exactly clear whether a gold reserve is a good thing for the AI. It probably needs some gold in reserve in order to react to changing circumstances. Whether it needs 6000 gold? I doubt it.
 
I'm not that great a bug finder - usually the only problems I notice are with how the city governor assigns citizens. Naturally, I've observed issues once again with the citizen automation.

I understand that the automation code is not the easiest thing in the world to tinker with due to complexity of the algorithms and the sacrifices that must be made for speed and space, but I think the problem here is unusual.

Basically I have noticed cities working ocean tiles before coast tiles. In this game, playing as Victoria (financial leader), I was losing 2 base commerce for every ocean tile the automator chose to work instead of coast tiles.

Here's a screenie of the city Coventry. It pretty much doesn't matter what emphasise buttons are pressed, the governor still picks that ocean square to work. Picking emph food or commerce both cause the automator to take the citizen from the iron mine onto the ocean square (making matters even worse), and all else left the same. Emph production does a better job unsurprisingly.

I would hope that this is a bug because I don't remember the automator being this poor - previously it only had issues when the picking of optimal tiles was more complicated.

Having said all that, keep in mind I am running 100% culture. I notice that if I increase either tax, science or esp up by 10%, the citizens are taken from ocean tiles to fill up the coast tiles first. So is this working as intended? Why would the automator pick tiles with less commerce only when it's all going into culture? Is there a something in the code that checks for net increases in beaker or gold income (when checking for optimal tiles) but neglects to consider culture income? <-- That is what I believe it will be.

Note the exact same effect can be observed in York - going from 100% to 90% culture takes a citizen off an ocean tile (when there was a coast tile available) and puts it on a plains town.

For reference, I'm using the latest version of Better BTS AI (ver 0.41B I believe). No other mods.

Post #29: http://forums.civfanatics.com/showpost.php?p=7489183&postcount=29

Bumping to see if I can get a reaction. Does no one else find it odd that the governor makes plainly wrong decisions when culture slider is on 100%?

If anyone can tell me where in the code to examine this stuff I will, but I don't know where to start. :(

Should I raise this issue in the UP forum instead? It seemed more like an AI issue to me but I could be wrong.

Also, the bug in Better BtS with the Spread Culture mission is really bothering me since I am avoiding the mission when I really want to use it. If it's easy to fix I'll do it myself, but again I'm not sure what I need to do...
 
Thanks for keeping the focus on this ... this is certainly a bug in BTS but an AI bug so it seems to fit both this mod and the UP.

I think the problem will be in some calculation in CvCityAI::AI_yieldValue ... I looked but didn't see anything that immediately seemed to be the problem, but this is where the AI is valuing different plots I believe.
 
I think the problem will be in some calculation in CvCityAI::AI_yieldValue ... I looked but didn't see anything that immediately seemed to be the problem, but this is where the AI is valuing different plots I believe.

That's definitely on the right track. Under 100% culture that function is assigning coast and ocean squares equal value (2132) because the commerce is getting completely discounted. Here is where it happens:
Code:
	for (int iI = 0; iI < NUM_COMMERCE_TYPES; iI++)
	{
		if (aiCommerceYieldsTimes100[iI] != 0)
		{
			[COLOR="Red"]int iCommerceWeight = GET_PLAYER(getOwnerINLINE()).AI_commerceWeight((CommerceTypes)iI);[/COLOR]
			if (AI_isEmphasizeCommerce((CommerceTypes)iI))
			{
				iCommerceWeight *= 200;
				iCommerceWeight /= 100;
			}
			if (iI == COMMERCE_CULTURE)
			{
				if (getCultureLevel() <= (CultureLevelTypes) 1)
				{
					iCommerceValue += (15 * aiCommerceYieldsTimes100[iI]) / 100;
				}
			}
			[COLOR="Purple"]iCommerceValue += (iCommerceWeight * (aiCommerceYieldsTimes100[iI] * iBaseCommerceValue) * GET_PLAYER(getOwnerINLINE()).AI_averageCommerceExchange((CommerceTypes)iI)) / 1000000;[/COLOR]
		}
	}
In PoM's game, looking at what happens with the red line we see the 4 commerce types have the following weights according to AI_commerceWeight: :gold:=100 :science:=110 :culture:=8 :espionage:=130. Pretty strange for a guy running 100% culture, don't you think? (Actually I was running 70% culture and 10% everything else to determine those numbers but the culture weight was still 8 at 100%). More on this later.

As a result of the tiny weight, the purple line is returning 1344000/1000000 = 1 for the coast tile (aiCommerceYieldsTimes100[iI] entry of 600) and 446000/1000000 = 0 for the ocean tile (aiCommerceYieldsTimes100[iI] entry of 200). And since it is 100% culture, those are the only increments to the iCommerceValue counter; at 90% culture and 10% something else, the something else would also increment the counter resulting in an iCommerceValue of 2 for coast or 1 for ocean. Later the commerce value is adjusted again:
Code:
	[COLOR="DarkGreen"]iCommerceValue *= (100 + (bWorkerOptimization ? 0 : AI_specialYieldMultiplier(YIELD_COMMERCE)));[/COLOR]
	[COLOR="Blue"]iCommerceValue /= GET_PLAYER(getOwnerINLINE()).AI_averageYieldMultiplier(YIELD_COMMERCE);[/COLOR]
	iValue += iCommerceValue;
The first statement (green) results in an iCommerceValue of 100 for the coast tile and 0 for the ocean tile but then the second statement (blue) is giving a zero result in both cases because AI_averageYieldMultiplier(YIELD_COMMERCE) is 150. So the end result is the tiles are identical. With the 90%/10% distribution, the coast tile will have a final iCommerceValue of 200/150 = 1 and so it does get a slight preference over the ocean tile.

So the base problem seems to me to be a poor understanding of a human's commerce preferences, particularly noticeable with culture since that has the lowest AI weighting. This is what AI_commerceWeight() has to say about culture:
Code:
	case COMMERCE_CULTURE:
		// COMMERCE_CULTURE AIWeightPercent is 25% in default xml
	
		if (pCity != NULL)
		{
			if (pCity->getCultureTimes100(getID()) >= 100 * GC.getCultureLevelInfo((CultureLevelTypes)(GC.getNumCultureLevelInfos() - 1)).getSpeedThreshold(GC.getGameINLINE().getGameSpeedType()))
			{
				iWeight /= 50;
			}
			else if (AI_isDoStrategy(AI_STRATEGY_CULTURE3))
			{
				int iCultureRateRank = pCity->findCommerceRateRank(COMMERCE_CULTURE);
				int iCulturalVictoryNumCultureCities = GC.getGameINLINE().culturalVictoryNumCultureCities();
				
				// if one of the currently best cities, then focus hard, *4
				if (iCultureRateRank <= iCulturalVictoryNumCultureCities)
				{
					iWeight *= 4;
				}
				// if one of the 3 close to the top, then still emphasize culture some, *2
				else if (iCultureRateRank <= iCulturalVictoryNumCultureCities + 3)
				{
					iWeight *= 2;
				}
			}
			else if (AI_isDoStrategy(AI_STRATEGY_CULTURE2))
			{
				iWeight *= 3;
			}
			else if (AI_isDoStrategy(AI_STRATEGY_CULTURE1))
			{
				iWeight *= 2;
			}
			
			iWeight += (100 - pCity->plot()->calculateCulturePercent(getID()));
			
			if (pCity->getCultureLevel() <= (CultureLevelTypes) 1)
			{
				iWeight = std::max(iWeight, 800);				
			}
		}
		// pCity == NULL
		else
		{
			if (AI_isDoStrategy(AI_STRATEGY_CULTURE3))
			{
				iWeight *= 3;
				iWeight /= 4;
			}
			else if (AI_isDoStrategy(AI_STRATEGY_CULTURE2))
			{
				iWeight *= 2;
			iWeight /= 3;
		}
			else if (AI_isDoStrategy(AI_STRATEGY_CULTURE1))
			{
				iWeight /= 2;
			}
			else 
			{
				iWeight /= 3;
			}
		}
		break;
Since PoM isn't an AI and so none of the strategies apply, the base 25 weight is then divided by 3 to get the final value of 8. So the question is how should the governor accurately guess a human's commerce preferences? The simplistic answer would be that if the player is a human to use the slider for the weighting rather than the AI XML values especially since those values are partially leader-specific. (Base values are defined in CIV4CommerceInfo but the Espionage weight is overridden by personality type.) But I'm not sure if the slider is always the most reliable way of ascertaining a human's preferences (for example what about a tiny science slider in a Specialist Economy or culture slider increases due to WW). Also, this level of AI tweaking is beyond anything I've ever tried before and I don't know what the repurcussions would be.
 
That's a good thought. The humans (global) commerce biases being the global percentages is an interesting thought. It isn't perfect -- someone running 0% cash might still value cash from merchants. :)

Another problem is that this could cause a feedback loop, where upping your commerce% changes your allocation, which means you can lower your commerce%.

Another idea would be to boost the weights of everything by a factor of, say, 1024 or 1000, to eliminate rounding errors. This is a rounding error -- it isn't that the two tiles are identical, it is that the difference is too small for the governor to notice the difference!

So long as we scale everything by the same factor, and the math is linear, and we take care not to have the multiplier 'leak out' too much into other AI, the times 1000 solution might make this particular problem go away.
 
Wow, thanks for the info Dresden! Very interesting ... a problem at least partly because AI strategies don't apply for the human player. Yakk's proposal would work I think, so long as it was done carefully ... if it wasn't applied everywhere it would screw things up pretty good.

It also seems to me that if the human's culture slider is over 50 and certainly if it's over 80 then they're gunning for a cultural victory. We could also adapt the AI rules for the human player that way.
 
Thanks for the v0.45 release guys. Looks good so far

Should we start up a 0.45 discussion thread?

By the way, it seems better AI has turned the Mongol civ into a bit of a monster among AIs.
 
Any chance of tweaking the late game code concerning how many Workers the AI seems to think it needs. If I enable the autobuild governor it seems to have a crazy idea that late game I need something like 1-2 workers per city, even after I have railroaded the whole damn continent. If I build a city on an island, hey look, it wasted 15 turns building a worker. Grrrr. If I summarily execute half the workers it just builds them again.

Maybe a check after railroads are available, if >50% of territory is railroaded, then ideal # of workers is 1/2 normal value.
 
Ah, but on a single-tile island at least it builds only ONE worker! ;)
 
Back
Top Bottom