Better economic AI (V. 0.5)

Oh, so this is what purity is? It means that if they have a new religion appearing, if they already have another religion widespread, they will consider the new one much less? It kinda makes sense. I'll take a look...

Edit: Just checked. I don't quite understand it. Don't know why but the logic of this snippet of code eludes me.
Code:
	int iBestCount = getHasReligionCount(eBestReligion);
	int iSpreadPercent = (iBestCount * 100) / std::max(1, getNumCities());
	int iPurityPercent = (iBestCount * 100) / std::max(1, countTotalHasReligion());
	if (iPurityPercent < 49)
	{
		if (iSpreadPercent > ((eBestReligion == eFavorite) ? 65 : 75))
		{
			if (iPurityPercent > ((eBestReligion == eFavorite) ? 25 : 32))
			{
				return eBestReligion;
			}
		}
		return NO_RELIGION;
	}
This purity thing bugs me.
 
Oh, so this is what purity is? It means that if they have a new religion appearing, if they already have another religion widespread, they will consider the new one much less? It kinda makes sense. I'll take a look...

Edit: Just checked. I don't quite understand it. Don't know why but the logic of this snippet of code eludes me.
Code:
	int iBestCount = getHasReligionCount(eBestReligion);
	int iSpreadPercent = (iBestCount * 100) / std::max(1, getNumCities());
	int iPurityPercent = (iBestCount * 100) / std::max(1, countTotalHasReligion());
	if (iPurityPercent < 49)
	{
		if (iSpreadPercent > ((eBestReligion == eFavorite) ? 65 : 75))
		{
			if (iPurityPercent > ((eBestReligion == eFavorite) ? 25 : 32))
			{
				return eBestReligion;
			}
		}
		return NO_RELIGION;
	}
This purity thing bugs me.
What does "?" operand mean?
If I knew it, it'd be much clearer for me.
 
The ?: ternary operator is a short form of an if-else statement:

Code:
<condition> ? <expression1> : <expression2>

This is equvalent to:

Code:
if (<condition>)
	<expression1>
else
	<expression2>
 
Is this compatable with the other AI mods?

And can somebody try and make a FF one please?

Thanks
 
Is this compatable with the other AI mods?

It can be combined quite easily, but needs some adjustments.

Anyway new version is coming soon and the noble AI is getting scary. (As in: tech tree can get finished by turn 400 and the AI is a credible military threat.)
 
It can be combined quite easily, but needs some adjustments.

Anyway new version is coming soon and the noble AI is getting scary. (As in: tech tree can get finished by turn 400 and the AI is a credible military threat.)

I just wrote some code that helps the Lanun AI develop Pirate Coves. Do you want to add that to your build?

Spoiler :
On a water map, Hannah is a frightening tech monster.
 
I just wrote some code that helps the Lanun AI develop Pirate Coves. Do you want to add that to your build?

Spoiler :
On a water map, Hannah is a frightening tech monster.

Yeah that's one of the last big things I could not do. Would be great if you could post the code.
 
Yeah that's one of the last big things I could not do. Would be great if you could post the code.

Bear in mind, it's only simulated coving. Without ripping apart the .dll, there's no way for them to build work boats and actively build Pirate Coves. The AI doesn't understand spells enough.

What I did was make it so when the Lanun found a city, they check their first ring for coastal tiles. If one is found, they check a two-square region around it, too see if there are any conflicting Pirate Coves. If there are, the tile is skipped. Same thing happens if they don't control the tile, or if the tile has a resource. Otherwise, a Cove is placed. Whenever a city expands, another check is made, this time within the first two rings of the city. Same conditions for placement as above, except in the second check, it also ignores lakes. This usually leads to cities having two coves, and occasionally having three (with lucky placement).

The Lanun AI has to have Fishing before it kicks in, so they won't have an immediate rush out the gate. They'll start coving about the same time a human player would.

This goes into CivEventManager, under the CityBuilt method:
Code:
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LANUN'):
			eTeam = gc.getTeam(pPlayer.getTeam())
			if not pPlayer.isHuman() and eTeam.isHasTech(gc.getInfoTypeForString('TECH_FISHING')):
				iX = city.getX()
				iY = city.getY()
				iCoast = gc.getInfoTypeForString('TERRAIN_COAST')
				for iiX in range(iX-1, iX+2, 1):
					for iiY in range(iY-1, iY+2, 1):
						pPlot = CyMap().plot(iiX,iiY)
						if pPlot.getTerrainType() == iCoast and cf.isCoveValid(pPlot,True):
							pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_PIRATE_COVE'))

This goes into CivEventManager, under the CultureExpansion method:
Code:
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LANUN'):
			eTeam = gc.getTeam(pPlayer.getTeam())
			if not pPlayer.isHuman() and eTeam.isHasTech(gc.getInfoTypeForString('TECH_FISHING')):
				iX = pCity.getX()
				iY = pCity.getY()
				iCoast = gc.getInfoTypeForString('TERRAIN_COAST')
				for iiX in range(iX-2, iX+3, 1):
					for iiY in range(iY-2, iY+3, 1):
						pPlot = CyMap().plot(iiX,iiY)
						if pPlot.getTerrainType() == iCoast and cf.isCoveValid(pPlot, False):
							pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_PIRATE_COVE'))

Finally, this goes anywhere in CustomFunctions:
Code:
	def isCoveValid(self, plot, LakeValid):
		cove = gc.getInfoTypeForString('IMPROVEMENT_PIRATE_COVE')
		harb = gc.getInfoTypeForString('IMPROVEMENT_PIRATE_HARBOR')
		port = gc.getInfoTypeForString('IMPROVEMENT_PIRATE_PORT')
		iX = plot.getX()
		iY = plot.getY()
		owner = plot.getOwner()
		if owner == -1:
			return False
		player = gc.getPlayer(owner)
		if player.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_LANUN'):
			return False
		if plot.isLake() and LakeValid == False:
			return False
		if plot.getBonusType(-1) != -1:
			return False 
		for iiX in range(iX-2, iX+3, 1):
			for iiY in range(iY-2, iY+3, 1):
				pPlot = CyMap().plot(iiX,iiY)
				imp = pPlot.getImprovementType()
				if imp==cove or imp==harb or imp==port:
					return False
		return True
 
Ah so you basically let the AI cheat and they get the coves for free without sacrificing a workboat. That would not work for me.
Getting the AI to build an (extra) workboat is pretty trivial. There is also some code in the Final Frontier mod for AIs to Construct Starbases by moving Constructor ships to a designated plot. I was hoping to adapt that for workboats by modifying AI_UnitUpdate.
Should be possible with just Python.
 
AI_unitUpdate (the python callback) is run only for barbarian units
 
Ah that explains why I had no success doing anything. Are there more callback functions that are similarly modified?
 
Ah so you basically let the AI cheat and they get the coves for free without sacrificing a workboat. That would not work for me.
Getting the AI to build an (extra) workboat is pretty trivial. There is also some code in the Final Frontier mod for AIs to Construct Starbases by moving Constructor ships to a designated plot. I was hoping to adapt that for workboats by modifying AI_UnitUpdate.
Should be possible with just Python.

It's actually not as bad as it sounds. I played a game as the Lanun, with a Lanun AI, and they kept up with me cove-wise.

You could check whenever the Lanun build a workboat, and hijack it. Then the code I wrote could still be used in it's entirety; you can either physically send the workboat to the first valid tile, or remove the workboat and place the cove. The second option would work most of the time, except when there's a two-tile or three-tile thick strip of land with water on both sides (likely to happen on an Archipelago map). You could easily modify the CityExpansion/CityBuilt code to queue up a workboat whenever a valid tile is located.
 
Ah that explains why I had no success doing anything. Are there more callback functions that are similarly modified?
hopefully not. You can try to put the workboat stuff into the end player turn function. That one should be run after a workboat is constructed and before unitupdate kicks in to give move orders
 
updated version uploaded in the first post. Lots of improvements, especially the Rhoanna Hippus AI is very scary now.

I'd be very curious if anyone can beat the emperor+ AI on a Pangaea map with no Acheron.
If you do, please post a save!

edit: Aww why doesn't the text of the title get changed? Now I'm stuck at 0.5 forever :(
 
How will this work with FF and FF+?
Will it need any modifications to fit into there?
 
Yes it will need adjustments.
Combining the code should be pretty trivial, however the changes of FF probably make a lot of my changes not desirable.
 
blank.gif
 
How will this work with FF and FF+?
Will it need any modifications to fit into there?

Yes it will need adjustments.
Combining the code should be pretty trivial, however the changes of FF probably make a lot of my changes not desirable.

That's actually why I haven't attempted to merge either this or the AI mod... FF has already fixed some of the same issues, usually in different ways. Much simpler to start fresh than to attempt to merge them... Which Sephi is already doing. ;)
 
Back
Top Bottom