[MOD] More Naval AI

Now that the AI is placing its second city further away from the capital what is happening is that the closest AI will tend to place its second city right next to the human capital if it's a good spot.

Interesting. I have also noticed that the AI is more willing to place a city farther out from its empire. I had found and removed a line that was resetting the iGreed variable in the AI_foundValue() function. I'm not sure if higher difficulty levels make the AI even more aggressive when placing cities or not. I generally play on Monarch myself.


Their economies seemed to be dragged down by overbuilding low level troops but I didn't check carefully what they were doing.

I suspect it's related to poor tech choices, which I'm hoping to fix for the next version.

One comment on game balance; I did find that the Tsunami spell seemed too powerful and overwhelming for both naval and coastal battles.

Tsunami is indeed a very powerful spell. But at the moment, I'm trying very hard to avoid changing any significant game mechanics (the changes to naval units was done with much reluctance). I'm hoping to remain focused on the AI and avoid the slippery slope of balance tweaks and changes (at least for now).


Thanks for the feedback from both of you! Glad to hear you're enjoying the mod!
 
After playing a couple games with the new patch, i have two problems to report. I've noticed that the AI is radically overvaluing its health and luxury resources, to the point where when i try to ask for a trade it'll only consent if i give up 3 resources, one of which is a mana. For sheep.

Also, they will ask for trades where you already have resources, like proposing they give you sheep, which you already have 2 of, for law mana.

Good work aside from that.
 
Acctualy i tend to observe the opposite in my games, like giving me iron for sheep or mana for copper.
 
like giving me iron for sheep

This actually does fit with the above complaint, (I think, though only Tholal could answer). If Sheep is valued too highly, AI's will be reluctant to give it away, while if you offer it, AI's will be willing ot offer something more valuable.
 
Quote:
Originally Posted by UncleJJ
Their economies seemed to be dragged down by overbuilding low level troops but I didn't check carefully what they were doing.
I suspect it's related to poor tech choices, which I'm hoping to fix for the next version.

I've just been working with this same issue in the DuneWars AI and have made some really impressive gains in the AI's economic performance, especially in the crucial early game. I'd suggest turning on the debug/cheat mode ('chipotle' code + alt-z) and watching the AI's commerce levels in the early game as it founds new cities. The biggest problem I had in DuneWars was the city AI was continuing to build new settlers before it built up the economic ability to support them and still keep a significant level of research. From CvCityAI::AI_chooseProduction, it only sets a target number of settlers if certain economic conditions are met:

Code:
    int iMaxSettlers = 0;
    // ALN DuneWars Nextline...
    // if (!bFinancialTrouble)
    // don't allow AI to burry it's economy early on
    if (!kPlayer.AI_isFinancialTrouble(60, /* bIgnoreWarPlans */true))
    {
     	iMaxSettlers= std::min((kPlayer.getNumCities() + 3) / 4, iNumAreaCitySites + iNumWaterAreaCitySites);
     	if (bLandWar || bAssault)
     	{
     		iMaxSettlers = (iMaxSettlers + 2) / 3;
     	}
    }

The original logic is straight from Better BUG AI that the current version of DuneWars is built on, and I don't know what code base you've got, but the !bFinancialTrouble part is from original vanilla BTS code regardless. In the Original AI_isFinancialTrouble() function, it basically gives a percentage of net Commerce (ignoring culture/espionage) after expenses / Total Commerce. The higher this percentage, the better economic state the civ is in. The problem isn't what it's calculating or how, it's that in the code it was used as a one sized fits all cut-off switch to anything that might add additional costs. Once the 'FundedPercent' goes below 40%, all sorts of things won't happen (like building new settlers), but at 41% it's all good... By the time they stopped building new cities, maintanance costs were forcing most civs to drop to 10-30% research rates, while a human could play it smarter in the early game and consistently keep a higher tech rate. That means getting important economic techs much earlier than the AIs on average, and you know how the snowball effect goes from there...

I can't tell if your AIs are making the same mistake without testing it myself, but this is a good thing to check. I've made the original function a pass through for DuneWars that uses the original numbers, but I can also call it with a higher or lower FundedPercent cutoff for cases where it's appropriate. You can also see that if the civ has any war plans, it drops the threshold even lower to return true, but not all decisions should take this into account, really only building more troops should. So if you look back at the top 'code' tag I've set it so that if the funded percent drops below 60%, regardless of war plans, cities will no longer produce settlers until the economy can support the new cities they would found.

Code:
// ALN DuneWars Start
bool CvPlayerAI::AI_isFinancialTrouble() const
{
	return AI_isFinancialTrouble(40, false);
}
// ALN DuneWars End

// XXX
// ALN DuneWars NextLine...
bool CvPlayerAI::AI_isFinancialTrouble(int iSafePercent, bool bIgnoreWarplans) const
{
	//if (getCommercePercent(COMMERCE_GOLD) > 50)
	{
		int iNetCommerce = 1 + getCommerceRate(COMMERCE_GOLD) + getCommerceRate(COMMERCE_RESEARCH) + std::max(0, getGoldPerTurn());

		int iNetExpenses = calculateInflatedCosts() + std::max(0, -getGoldPerTurn());
		
		int iFundedPercent = (100 * (iNetCommerce - iNetExpenses)) / std::max(1, iNetCommerce);
		
		// ALN DuneWars NextLine...
		// int iSafePercent = 40;
		if (AI_avoidScience())
		{
			iSafePercent -= 8;
		}
		
		// ALN DuneWars NextLine...
		// if (GET_TEAM(getTeam()).getAnyWarPlanCount(true))
		if (!bIgnoreWarplans && GET_TEAM(getTeam()).getAnyWarPlanCount(true))
		{
			iSafePercent -= 12;
		}
		
		if (isCurrentResearchRepeat())
		{
			iSafePercent -= 10;
		}
		
		if (iFundedPercent < iSafePercent)
		{
			return true;
		}
	}

	return false;
}

I've also created a function that just returns the current funded percent to use in picking technologies as well as other things. Again, I don't know if you'll have the same thing, but the original code below in CvPlayerAI::AI_techBuildingValue() (used to calculate the value of buildings unlocked by a technology) from Better BUG AI just added value if in financial trouble. By that time it's too late usually to think about it because the AI's research rate is shot and they'll never get the tech in a decent time to turn things around. I've set it up where at FundedPercent < 70% it starts thinking about it, where the worse the economic condition, the higher these tags are valued. If you do the math, at 40% Funded Level, the multiplier will be 30, twice the original value, while at the 70% threshold it'll have the same values as the original function.

Code:
int CvPlayerAI::AI_getFundedPercent() const
{
	if( isBarbarian() )
	{
		return 100;
	}
	int iNetCommerce = 1 + getCommerceRate(COMMERCE_GOLD) + getCommerceRate(COMMERCE_RESEARCH) + std::max(0, getGoldPerTurn());
	int iNetExpenses = calculateInflatedCosts() + std::max(0, -getGoldPerTurn());
	
	int iFundedPercent = (100 * (iNetCommerce - iNetExpenses)) / std::max(1, iNetCommerce);
	
	return iFundedPercent;
}

Code:
if (AI_isFinancialTrouble(70, true))
{
	int iMultiplier = (100 - AI_getFundedPercent()) / 2;
	iBuildingValue += (-kLoopBuilding.getMaintenanceModifier()) * iMultiplier;
	iBuildingValue += kLoopBuilding.getYieldModifier(YIELD_COMMERCE) * iMultiplier/2;
	iBuildingValue += kLoopBuilding.getCommerceModifier(COMMERCE_GOLD) * iMultiplier;
}
// if (bFinancialTrouble)
// {
	// iBuildingValue += (-kLoopBuilding.getMaintenanceModifier()) * 15;
	// iBuildingValue += kLoopBuilding.getYieldModifier(YIELD_COMMERCE) * 8;
	// iBuildingValue += kLoopBuilding.getCommerceModifier(COMMERCE_GOLD) * 15;
// }

Another example in CvCity::AI_chooseProduction() is I've set the AI's to prioritize any buildings to increase gold or reduce maintanence available when the funded percent is getting close to that old 40% mark.

Code:
	// ALN DuneWars - prioritize tribunals etc. when available
	if (kPlayer.AI_isFinancialTrouble(60) && !bDanger && !(bLandWar && iWarSuccessRatio < -30))
	{
		if (AI_chooseBuilding(BUILDINGFOCUS_MAINTENANCE | BUILDINGFOCUS_GOLD), MAX_INT, 3*iWarTroubleThreshold)
		{
			if( gCityLogLevel >= 2 ) logBBAI("      City %S uses choose BUILDINGFOCUS_PRODUCTION 1", getName().GetCString());
			return;	
		}
	}

I really didn't mean to go into so much detail when I started this post, but I'm hoping it'll be helpful if you've got the same problem. I've got the AI's no longer tanking their economies early like they were before in my test games. Before, playing on monarch, no tech-trading, I almost never had AI's anywhere near my tech lead by the mid game, now the top AI's are consistently a little ahead of me even on good starts.
 
Ok, WTH is this? I've reloaded autosave where I've completed divination tower and picked my tech, but instead of a tech I've got message "txt_key_cheaters_never_prosper".
 
Ok, WTH is this? I've reloaded autosave where I've completed divination tower and picked my tech, but instead of a tech I've got message "txt_key_cheaters_never_prosper".

Heh. No idea. I've never seen that before.

Edit: Ok. Found it in the code.

Code:
/************************************************************************************************/
/* UNOFFICIAL_PATCH                       12/07/09                             EmperorFool      */
/*                                                                                              */
/* Bugfix                                                                                       */
/************************************************************************************************/
	// Free Tech Popup Fix
	if (widgetDataStruct.m_iData2 > 0)
	{
		CvPlayer& kPlayer = GET_PLAYER(GC.getGameINLINE().getActivePlayer());

		if (!kPlayer.isChoosingFreeTech())
		{
			gDLL->getInterfaceIFace()->addMessage(GC.getGameINLINE().getActivePlayer(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_CHEATERS_NEVER_PROSPER"), NULL, MESSAGE_TYPE_MAJOR_EVENT);
			return;
		}
		else
		{
			kPlayer.setChoosingFreeTech(false);
		}
	}
/************************************************************************************************/
/* UNOFFICIAL_PATCH                        END                                                  */
/************************************************************************************************/

Not exactly sure whats going on here but I'm guessing that there was some exploit where you could get multiple techs by saving and reloading? Try reloading the previous save and playing from there and let me know what happens.
 
Playing at Immortal on a Highlands map, Thessa made one of the typical AI "in your face" aggressive city plants (first ring for me, third or fourth for her). The city has a bunch of grassland forests and an unimproved rice. A few turns after planting, the city had grown to size 2, then within a dozen or so turns it was at size 4! Does the AI have some outrageous food/growth cheats, or is this a bug?
 
Playing at Immortal on a Highlands map, Thessa made one of the typical AI "in your face" aggressive city plants (first ring for me, third or fourth for her). The city has a bunch of grassland forests and an unimproved rice. A few turns after planting, the city had grown to size 2, then within a dozen or so turns it was at size 4! Does the AI have some outrageous food/growth cheats, or is this a bug?

The AI growth percent is 60 in FFH (including this mod) at Immortal, compared to 85 in vanilla BtS. So you should expect their cities to grow a little bit slower than twice as fast as yours would in an identical position. It's up to you to decide if this is an "outrageous" cheat, but it seems like it's growing as intended, anyway.
 
Ran into a bug playing as malakim: if you cast revelation when barbarian or hidden nationality ships are in range, a blockade will be placed from the ships current position, with no way to lift it.
 
I really didn't mean to go into so much detail when I started this post, but I'm hoping it'll be helpful if you've got the same problem. I've got the AI's no longer tanking their economies early like they were before in my test games. Before, playing on monarch, no tech-trading, I almost never had AI's anywhere near my tech lead by the mid game, now the top AI's are consistently a little ahead of me even on good starts.

Interesting stuff Chris. Thanks for the details! I do make use of the AI_isIFinancialTrouble() function quite a bit, but I never looked into the code for it. I'll keep what you said in mind as I wrestle with the various Tech valuation functions (things are progressing on that front, but it's a lot of work and every little tweak can result in major cascading changes to how the AI decides what tech to research.)
 
In my current game playing as the Doviello I was the first to research Mercantilism. I received two Great Merchants rather than the normal one.
 
Just started getting into FFH2 again and of all the modmods, yours looks to be the most interesting/stable. :thumbsup: Thank you for putting so much effort/time into this! 2 Changes I hope you are able to do: :confused:

1. Add on BUG Mod (or some equivalent)

2. Turn forts back into functional ports again. For the life of me, I don't know why this was changed in the first place, other than to force me to build unproductive towns to grab a resource on a single square tile - or deny access if an additional resource is 2 squares away!

Thanks and again, it looks like you (and others) have done a lot of really killer work on this! I appreciate it! :)
 
Back
Top Bottom