A Better AI.

I agree. I think a warmongering civ should have an automatic distrust of powerful warmongering civs.

I've changed all warmongerrespect values to 0.
They still like each other but not that much at least.
(taking away that +1/+2 hidden modifier)
 
You misunderstand this i think.
I'm very confident that 'MaxWarNearbyPowerRatio' and 'MaxWarDistantPowerRatio' mean how much power we must have compared to rival to able to declare war on them.
So 50 means 50% power is enough (would be foolish).
200% means you need double the power rating (cowardly :))
I dunno, the values I have Genghis set (as in the spoiler) cause Genghis to allways attack the border enemy after about 40 turns or so. This is irrelevent to relative power ratios. With these settings, I have never seen it go after a distant civ or any kind. Mind you, this behaviour could be attributed to other values. But if the civ cannot go to war unless the relative power ratios are on the better side of those nearby/distant power ratio values, then it is definitely false as I have seen it go to war with a neighbour and with an equal power ratio to that neighbour many a time (with a setting of 200).

Iustus (Blake team member) wrote here an explanation about this not so much earlier. The AI need to have a unit wanting to move to the territory of the rival AI and when it cannot do so due to closed borders then they evaluate a war declaration.

Blake's have written the code that after war decision they don't declare war instantly but send an attack stack and only declare war when it has arrived at the border which is cool.
Isn't this kind of like the same as the sneak attack war prob where they will move the units first and then declare war rather than declare outright? Mind you, I have no doubt Blake's version would be much better executed.

There are a few basic things with how AI's war, which cause AI-AI wars to be shorter than you would expect.

  • After 30-40 turns, if the war is going about even for both, then peace is made.
  • After 50 turns, peace is made, always.
  • unless you have aggresive AI checked, the chance of war goes down in proportion to the number of cities an AI has. (it rolls a die from 1 to number of cities, if it rolls a 1, then it will consider war that turn).
  • if an AI thinks it is in financial trouble, it will not declare war, under any circumstances. you would be supprised how often this occurs.

I am testing out a build right now that makes some changes in these:
  • (B) is completely removed.
  • (D) is changed, if a leader is determined to be warlike, then he will choose war to solve financial troubles
  • AIs performing dagger strats or who choose war to solve finances will be very relucant to end wars while they are winning
ARGHH! C) explains why I am left alone when I have a lot of cities. Hmmm. C) should be changed so that instead of using the value to reduce the odds of going to war, it uses that to influence it in finding more war buddies. That way there would be a kind of ganging up on the more powerful civs (one hopes).

D) Love it, love it, love it! :D. I would love to see whether the pillage strategy leaders, eh, 'profit' from it. The pillage strategies leaders should maybe be more ok with deficit spending and then using war to fund their treasury (while researching and expanding). The question is whether the AI can effectively judge deficit spending? I guess an algorithm could be set that takes into account the rate at which gold is coming in via pillaging/city capturing and also takes into account the amount of gold in the treasury when setting the research slider. So, maybe it could have an algorithm that, provided it is at war and has units in enemy territory, that it tries to keep it self with 10 turns of gold in the treasury to cover the deficit spending. Any more spare turns and it redistributes the research/cultural sliders, cottage working and merchant specialist accordingly. That could make for an interesting solution for the warmongers to research better while at war - by relying on pillaging/city capture gold.

When I play a game, I start the initial expansion phase and also build a city attack force by default - whether I aim to use it or not. At the very least it gives me a safety net if my neighbour wishes to annoy me. I mean, taking out their cities is the most effective way of ending a war ;) The point here is that maybe there could be something for the conquerors or the warmongers in general: to build a stack capable of taking down several cities as a default action to take. If the conquerors then use it, get a couple of cities, then they would be less likely to stop war and then it should just snowball into a continious conquest. The AI should at this point work on figuring out how to keep it going financially speaking rather than quit because of financial difficulties (and also factor in pillaging/capturing gold and deficit spending aswell).

Iustus, I am curious, would D) also kick in while they are at war? I mean, while they conquer, is their financial status used to decide whether to sue for peace? I have seen the algorithm with how it factors in razing a city instead of keeping it but I wonder if the financial status has any bearing on sueing for peace.

I agree. I think a warmongering civ should have an automatic distrust of powerful warmongering civs. They should be willing to ally with them to conquer a third party, but will always react to how the other is doing (trying to keep up in the power raiting, for instance). They will never be friends, though, and won't give them stuff that could be used against them (techs for military, for instance).
I agree with you but there is at least one exception (which may mean there are more): Genghis is a leader who definitely would have a warmonger respect as it was demonstrated numerous time during his conquests. He had a strong appreciation towards military capable people and even promoted conquered people into his ranks because of it. I believe there was a guy that shot him with an arrow in China (which is why he left China before the conquests were completed). Afterward, the guy was put into his army and promoted for it or something like that. I am a little vauge on the exact details. Mind you, it didn't exactly stop him from attacking and didn't stop him from continuing the war, so maybe it isn't so appropriate afterall (from the gamplays perspective).

Thanks for all the info!
I think you should try to remove C too. It's a real nonsense. :)
And if aggressive AI turns that off you could take and use that code by default.
Agree, definitely. It would be good if it tried to gain allies though rather than just ignore the higher number of cities.

Kettyo said:
I've changed all warmongerrespect values to 0.
They still like each other but not that much at least.
(taking away that +1/+2 hidden modifier)
Try making them all -2. That should (might) neutralise the warmonger bonus. I have forgotten how it exactly works, but there is a thread on how the <BaseAttitude>, <iBasePeaceWeight>, <iPeaceWeightRand> and <iWarmongerRespect> all relate to one another. Apparently a 0 BaseAttitude, 0 BasePeaceWeight, 0 PeaceWeightRand and a -4 WarmongerRespect resets it so that everyone is neutral when they start. These numbers are from memory though, but I think they are right.
 
I agree with you but there is at least one exception (which may mean there are more): Genghis is a leader who definitely would have a warmonger respect as it was demonstrated numerous time during his conquests. He had a strong appreciation towards military capable people and even promoted conquered people into his ranks because of it. I believe there was a guy that shot him with an arrow in China (which is why he left China before the conquests were completed). Afterward, the guy was put into his army and promoted for it or something like that. I am a little vauge on the exact details. Mind you, it didn't exactly stop him from attacking and didn't stop him from continuing the war, so maybe it isn't so appropriate afterall (from the gamplays perspective).

Still, you have to balance historical accuracy with good gameplay. In a multiplayer game, smart players will always prefer to build units until they are equal to an opponent if they think that the other person could become a threat of attack or avoid giving them something that lets them build axemen (for example). They don't necessarily hate that team, but they watch out for them.
 
Montezuma on the other hand:
Code:
<iWorseRankDifferenceAttitudeChange>-3</iWorseRankDifferenceAttitudeChange>
<iBetterRankDifferenceAttitudeChange>0</iBetterRankDifferenceAttitudeChange>

hates people worse than him, and has no modifier to those stronger than him.
Isn't this the other way around?
 
To clarify:

Code:
RankDifference = rank(Saladin) - rank(WhiteElk);

if (RankDifference > 0)
	iAttitude += Leader.WorseRankDifferenceAttitudeChange * RankDifference) / (playersInGame + 1));
else
	iAttitude += Leader.BetterRankDifferenceAttitudeChange * -(RankDifference)) / (playersInGame + 1);


RankDifference here will be greater than 0 if WhiteElk has a higher score since rank(Player) returns 0 for the best player, 1 for the second best etc.

So unintuitively the higher the score the lower the rank.

Which confirms our experience that Monty always hates us since most players are almost always high up in score.
 
Score or power rating? I have only ever had Monty attack me twice - and both times were because I had a very low power rating. I usually end up with him being annoyed with me all game but does nothing because I am too big (aka 'C)' :)).
 
Iustus said:
Thanks for the screenshots. I understand what you are getting at here, but in reality, I think the choice of city locations is pretty good right now, good enough for our 1.0 release. What you are talking about would involve huge changes in how city placement works.
Thanks for the explanation, Iustus. That helps a lot and also confirms my suspicions.

I don't have a huge problem with it as is. And, I completely understand about getting the 1.0 release out. I would, however, appreciate if you would add this to the "wish list" for release 2. :)

Wodan
One more data point. New game, Cyrus' capitol is out on the end of a peninsula. It widens out such that there is pretty much optimal spacing for two cities about 5-6 apart and also about 5-6 from the capitol itself. There happen to be 2 food resources in the middle, which would go one to each of the new cities.

What does he do? (11-26 build) He puts a single city smack in the middle, so that it nabs both food resources. Oh, and by the way it has the old problem of being 1 tile in from the coast, making it impossible to build Lighthouse/Harbor, reducing long term city food/growth, and eliminating more lucrative coastal trade routes. Cyrus also has to choose an overlap of 6 tiles for the 3rd city or else put the 3rd city way far away from the capitol, incurring greater maintenance.

Anyway, bottom line, seems to me the current algorithm is giving way too much priority to maximizing resources for a single city, not enough priority to being on the coast, and not enough priority to spacing things out.

Please do add this to the "wish list" for v.2.0!

I'll even help with programming or testing, if you like.

Wodan
 
Look in this link some results of my last game with the Better AI heh!

PS: I was ALWAYS the last in the power Graph in this game and NOBODY declared war on me the whole game..I think the AI needs some tweaks for war between small islands(archepelogo or whatever its spelled)...That Cyrus war in the screenshot I think was the SECOND I sAw in THE WHOLE GAME!
 
Try making them all -2. That should (might) neutralise the warmonger bonus. I have forgotten how it exactly works, but there is a thread on how the <BaseAttitude>, <iBasePeaceWeight>, <iPeaceWeightRand> and <iWarmongerRespect> all relate to one another. Apparently a 0 BaseAttitude, 0 BasePeaceWeight, 0 PeaceWeightRand and a -4 WarmongerRespect resets it so that everyone is neutral when they start. These numbers are from memory though, but I think they are right.

That's a negative modifier towards every other AI's not just the other warmongers. I won't like to isolate them too much. That way they'll not be warmongers but much more warsuckers :)

If you set every leader as you wrote that would be a totally flat attitude system you're right.
But be aware that by default this will grant open borders to everyone except Tokugawa which means there'll be no wars except religious unless you increase the openborders threshold.
I wouldn't like a sympathy-free attitude system i rather tweak the current one a little bit for myself.
 
It already does a lot of this. The thing it doesnt do, which I am not convinced it _should_ do, is absolutely try not to waste any tiles. I waste tiles on purpose when I play. I want good cities, not a ton of mediocre cities. Then, when I get around to it, I might found some half-cities to fill the empty spaces later. The AI seems to do the same thing. It will not found junk cities until there are no other options left.

Since there is a lot of discussion about it, here is what the AI does currently (I went through some effort to make it human readable, if there are any typos, it was probably in my translation):

Spoiler :
Code:
if GameStart
{
	if goody hut -> zero value
	if any plots off the edge of the map -> zero value
}

if count the number of plots which we cannot use (off map or another team) > 7 -> zero value

iBadTile = 0;

count bad plots:
if plot is off map, or a peak, count as 1
if plot is not hills and not directly connected to fresh water (river/lake)
	if zero food or one food and nothing else, count as 1
	else if ocean and not coastal city and food less 2, count as 1/2
else if plot owned by a city in our team, count as 1/2

if not GameStart
{
	if bad plots > 10
	{
		check all the unowned plots that are either water or on the same land mass as the city
		is there a bonus resource which we do not already have, or which scores higher than 10?
		if not -> zero value, quit
	}
}

iGreed = 100;
if not GameStart
{
	if hasTrait UpkeepModifier (Organized)
		iGreed -= 25 [actually +UpkeepModifier/2]

	if hasTrait CultureChange (Creative)
		iGreed += 40 [actually CommerceChange * 20]
}

iTakenTiles = 0;
iTeammateTakenTiles = 0;
iHealth = 0;
iSpecialFoodPlus = 0;
iResourceValue = 0;
iSpecialFood = 0;
iSpecialFoodPlus = 0;
iSpecialFoodMinus = 0;
iSpecialProduction = 0;
iSpecialCommerce = 0;

value = 1000;
for each plot
{
	if off map, iTakenTiles++

	if within another city radius, iTakenTiles++

	if within our team's city radius, iTeammateTakenTiles++;

	else 
	{
		determine food/production/commerce yield of the plot
			(adjusting the city home plot negative the value of the improvement of a bonus resource, if trying to found on one)

		tempValue = 0

		if city home plot
			tempValue = 60*food + 60*production +40*commerce
		else if food >= 2
			tempValue = 40*food + 40*production +30*commerce
			if GameStart tempValue *= 2
		else if food == 1
			tempValue = 25*food + 25*production +20*commerce
		else
			tempValue = 15*food + 15*production +10*commerce
		
		if coastal city and this plot water and this plot commerce > 1
			tempValue += 40

		if this plot borders river
			tempValue += 10

		if home plot
			tempValue *= 2
		else if this plot already in our culture, or within 1 distance of home
			tempValue *= 3/2
		else
			tempValue *= iGreed/100

		value += tempValue

		if this plot has forest or jungle (and not home plot)
			iHealth += health of feature
			iSpecialFoodPlus += any food over 2 on this plot

		if this plot has a bonus resource
		{
			if not GameStart and this the first bonus of this type for this city
				tempValue = bonusValue() * 80
			else
				tempValue = bonusValue() * 20
			
			tempValue *= iGreed/100
			
			if plot distance 2 from home and our culture not already on it
				tempValue *= 2/3 * iGreed/100

			value += tempValue

			if not home plot
			{
				if an improvement exists for this bonus resource
				{
					iSpecialFood += food after bonus improved
					
					iSpecialFoodPlus += any food over 2 after improved (zero if less than 3)
					iSpecialFoodPlus -= any food under 2 after improved (zero if more than 1)

					iSpecialProduction += production after improved
					iSpecialCommerce += commerce after improved
				}

				if jungle, iResourceValue -= 30

				if water bonus resource
					if coastal, value += 150
					else value -= 150
			}
		}
	}
}


iResourceValue += iSpecialFood * 50
iResourceValue += iSpecialProduction * 50
iResourceValue += iSpecialCommerce * 50
if (iResourceValue > 0)
	value += iResourceValue

if (iTakenTiles > 7) and (iResourceValue < 250), zero value, quit

if iTeammateTakenTiles > 1, zero value, quit

value += (iHealth / 5)

if coastal city
{
	value += 300

	if not GameStart
	{
		if we have no other cities on this land mass
			value += 400

		value += 200
	}
}

if city home plot is hills
	value += 200

if city home plot has river
	value += 40

if city home plot has fresh water
	value += 100 [really uses the define for health change from fresh water]

if GameStart
	for every plot within 5 distance
		value += 10*food + 10*production + 5* commerce
	if first starting city assigned
		value += max distance on map * 100
	else
		value += distance to closest other start city * 100

if (distance to our nearest city) < 5
	value -= (5 - (distance to our nearest city)) * 500
else
	value -= ((distance to our nearest city) - 5) * 500

if number of cities on land mass is zero
	value *= 2
else if every city on land mass is our team
	value *= 3/2
else if every city on land mass is our team or barbarians
	value *= 4/3
else if our team has zero cities on land mass
	value *= 5/4

if iSpecialFoodPlus > 8
	iSpecialFoodPlus = 8

value *= (100 + (20*iSpecialFoodPlus))
value /= (100 + (10*iSpecialFoodMinus))

value /= (num bad plots over 5) + 3

if Gamestart
	value /= (num plots on different land mass over 14) + 2

as you can see, it is rather complicated :)

-Iustus


Wow, that was an interesting read. As expected, the settling algorithm is fairly complicated. It's not an easy decision and thus many aspects have to be taken into account. Thank you for taking the time to make this code readable so that any sensible discussion about the settling code is possible.

As I can see, there are 2 bonusses for settling on the coast:

Iustus said:
Spoiler :
Bonus 1:


if coastal city and this plot water and this plot commerce > 1
tempValue += 40

Bonus 2:

if coastal city
{
value += 300

if not GameStart
{
if we have no other cities on this land mass
value += 400

value += 200
}
}

Both bonusses look good and surely significant. They should make coastal founding more attractive. I don't think this needs any improvements in the near future. Maybe some refinements after a lot of testing. I could imagine that ocean tiles could also get a smaller +value (compared to coastal tiles) if the city is coastal. Ocean tiles aren't that great, but sometimes they're better than nothing and if it allows more cities to fit on an island, then that's nice. The bonus shouldn't be too big though as ocean tiles aren't that great.

Some other random comments on the code:

Iustus said:
Spoiler :

if city home plot
tempValue = 60*food + 60*production +40*commerce

This value is higher than the value for other tiles that are not city home plots. Was that done to encourage founding on plains hills (for 2 hammer founding positions) and other tiles that give a bonus to center plot food/commerce/production? It might have bad effects for founding on special resources. You mention that there is a special negative modifier for founding on special resources, but the size of that modifier is not mentioned in the part of the readable code that you showed us, so I can't see if the penalty is large enough. I guess it is ok, just asking.

By the way, I hope that the values for food, production and commerce used in the above calculation are adjusted for the city founding tile bonus. Otherwise fouding on a desert tile will not be considered good by the AI.


Iustus said:
Spoiler :
iResourceValue += iSpecialFood * 50
iResourceValue += iSpecialProduction * 50
iResourceValue += iSpecialCommerce * 50
if (iResourceValue > 0)
value += iResourceValue

Most people agree that food is more valuable than hammers which in turn are more valuable than commerce. Also the commerce bonuses of special resources are usually larger than the production bonuses which are in turn larger than the food bonuses. Should therefore the multiplier for food not be bigger than the multiplier for production which in turn would be bigger than the multiplier for commerce? Otherwise commerce resources will be valued very high compared to production resources.

Iustus said:
Spoiler :

if iTeammateTakenTiles > 1, zero value, quit

Isn't this a bit harsh? 2 or 3 tiles of overlap isn't that bad is it?


The following modifier makes the AI not settle cities too close or too far. It's very close to the suggestion of Wodan. There is also an exception where the AI will not settle a city very close to the enemy, but this is the main modifier that will ensure that the AI settles not too close and not too far.

Iustus said:
Spoiler :

if (distance to our nearest city) < 5
value -= (5 - (distance to our nearest city)) * 500
else
value -= ((distance to our nearest city) - 5) * 500

I personally think that this could be refined. It would be better if the AI took into account which tiles will be 'lost' if they settle further than 5 tiles away and which tiles are already in the fat cross of another city if they settle closer than 5 tiles away. For instance, if the tiles that are going to be lost are desert tiles and peaks, then I don't see a reason to get the quoted negative modifier. And I also don't see a reason to get the value of tiles that are already in the fat cross of another city of yours.

My suggestion would be to increase the value of the tiles that are at distance 3 of cities that are already founded by multiplying them with a certain value. That would ensure that these tiles are not lost without reason and especially if there are many high value tiles about to be lost by settling too far away.

Code line something like (added a red line to a part of the code that was supplied by you):
else if food >= 2
tempValue = 40*food + 40*production +30*commerce
if GameStart tempValue *= 2
if distance to nearest city = 3, then tempValue *=1.5

The red code line should then of course be added at multiple points in the code.

To ensure that the AI doesn't settle to close another code line could be added

Code line something like:
else if food >= 2
tempValue = 40*food + 40*production +30*commerce
if GameStart tempValue *= 2
if distance to nearest city = 3, then tempValue *=1.5
else if distance to nearest city < 3, then tempValue = 0

Maybe the multipliers of 1.5 and 0 are not that well chosen. I would have to think about that and check it for some ingame examples.


The code quoted below could also causes the AI to settle cities which envelop multiple food resources while other cities that are settled afterwards won't get any food resources at all. Now I know that food resources are great, but normally I would rather have two cities with one food resource each instead of one city with 2 food resources and one without any food resources. An exception of course would be a great person factory.

Iustus said:
Spoiler :

if iSpecialFoodPlus > 8
iSpecialFoodPlus = 8

value *= (100 + (20*iSpecialFoodPlus))
value /= (100 + (10*iSpecialFoodMinus))

I would limit the iSpecialFoodPlus to something like 3 or 4 instead of 8. The special food resource tiles still get lots of bonuses from other lines of code, but this is a really dominating bonus as it multiplies the total value of the city instead of the value of one tile. A city location with 3 food resources will surely be preferred above one with 2 food resources even if the one with 2 food resources has many other benefits.

By the way, I wrote a long post (no 253) about combat strategy for the AI. I wonder if the post was noticed? It might be useless as the AI might already do the stuff that I mentioned there. I just want to know if the post was read.


Wodan said:
One more data point. New game, Cyrus' capitol is out on the end of a peninsula. It widens out such that there is pretty much optimal spacing for two cities about 5-6 apart and also about 5-6 from the capitol itself. There happen to be 2 food resources in the middle, which would go one to each of the new cities.

What does he do? (11-26 build) He puts a single city smack in the middle, so that it nabs both food resources. Oh, and by the way it has the old problem of being 1 tile in from the coast, making it impossible to build Lighthouse/Harbor, reducing long term city food/growth, and eliminating more lucrative coastal trade routes. Cyrus also has to choose an overlap of 6 tiles for the 3rd city or else put the 3rd city way far away from the capitol, incurring greater maintenance.

Anyway, bottom line, seems to me the current algorithm is giving way too much priority to maximizing resources for a single city, not enough priority to being on the coast, and not enough priority to spacing things out.

Please do add this to the "wish list" for v.2.0!

I'll even help with programming or testing, if you like.

Wodan

It might be very difficult to get the AI to settle the second city in a different spot. You have to remember that the AI cannot think ahead. If you could only build one more city, would you build it at the spot that the AI picked or at one of the two spots that you chose?

The only solution would be to make the AI think ahead. Let it plan 3 future cities and add the value of the 3 cities. The highest combination of the 3 cities would be chosen. It might be difficult to code and it might not even work as it could chose to fill a far larger area with the 3 cities than you would do. So then you would have to limit the area that the AI can use for settling the 3 cities. I foresee a nightmare to code that.

All that being said, I made some suggestions to refine the city settling code. I hope that they prove useful.
 
Don't have time at the moment to tear into your other suggestions but they look like you put a good bit of thought and I'll be very interested to look at them later, for sure.
It might be very difficult to get the AI to settle the second city in a different spot. You have to remember that the AI cannot think ahead. If you could only build one more city, would you build it at the spot that the AI picked or at one of the two spots that you chose?
A good hypothetical test but ultimately futile because it's an invalid hypothesis. I (or the AI) can indeed build more than one more city.

So, let's look at the assertion that it is required for the AI to "think ahead" in order to accommodate this desired programming change.

The only solution would be to make the AI think ahead. Let it plan 3 future cities and add the value of the 3 cities. The highest combination of the 3 cities would be chosen. It might be difficult to code and it might not even work as it could chose to fill a far larger area with the 3 cities than you would do. So then you would have to limit the area that the AI can use for settling the 3 cities. I foresee a nightmare to code that.
That's one way to implement, let's see is there's another.

We're already assigning "values" to all tiles. The current system results in the AI simply choosing the highest-value tile.

Let's look at two different cases: (1) no water to complicate things, simply a huge landmass, and (2) huge gaps caused by water tiles.

For case (1), the AI's first city will go for the single best spot anywhere. My only comment here is that I think the "distance" modifier could use some tweaking. I think the AI gives way too little precedence to distance. Here's a test anyone here can easily do. Load up a game-end save from your latest game or two. Look at the spacing of the AI cities. You'll see that the AI ends up having a TON of cities, crammed together, with one single reason being the largest cause: the AI slams down early cities to hit the resource concentrations, and then later on in the game the AI will cram cities wherever they can fit (as we all know from seeing them settle on ice and whatever), which ends up being in the bitty area between existing cities.

So, if that tweaking is able to be accomplished (which it should be), then I think case (1) will take care of itself for the most part.

For case (2), This is both the more likely map setup, and also the bigger problem. So, it should warrant more attention. I have already suggested that coastal tiles should get more priority than they do currently If they get more priority than the multiple resource sites, then this will do the trick. There may be other solutions.

For the most part, I would suggest that the multiple-resource condition be changed in two ways. (2a) Instead of resources being a SUM function, let's use a MAX function. In other words, 2 food resources (valued at X each) does not equal 2X, it still equals X. At minimum, let's make it X+1 (assuming X is a large number... at least 4).

(2b) Probably the value algorithm already has a clause which computes total probable food for the hypothetical city. If it doesn't, then it needs this regardless of this other stuff.

Wodan
 
Looking at that last post, I see I left off a bit and need to draw out the logical conclusion. By enhancing the value of a tile bordering the coast, this should ensure that a city is on the coast, regardless of the size of the available area.

It's arguable that's a good idea. Certainly, I can imagine a test case where multiple resources but not quite wide enough for 2 cities would warrant NOT settling on the coast. However, that would be very rare. And, if the "coast modifier" is bigger than the "multiple resource modifier" but not hugely bigger, than using the X+1 system for multiple resources should result in fixing this rare case as well.

Wodan
 
So, let's look at the assertion that it is required for the AI to "think ahead" in order to accommodate this desired programming change.


That's one way to implement, let's see is there's another.

We're already assigning "values" to all tiles. The current system results in the AI simply choosing the highest-value tile.

Let's look at two different cases: (1) no water to complicate things, simply a huge landmass, and (2) huge gaps caused by water tiles.

For case (1), the AI's first city will go for the single best spot anywhere. My only comment here is that I think the "distance" modifier could use some tweaking. I think the AI gives way too little precedence to distance. Here's a test anyone here can easily do. Load up a game-end save from your latest game or two. Look at the spacing of the AI cities. You'll see that the AI ends up having a TON of cities, crammed together, with one single reason being the largest cause: the AI slams down early cities to hit the resource concentrations, and then later on in the game the AI will cram cities wherever they can fit (as we all know from seeing them settle on ice and whatever), which ends up being in the bitty area between existing cities.

So, if that tweaking is able to be accomplished (which it should be), then I think case (1) will take care of itself for the most part.

For case (2), This is both the more likely map setup, and also the bigger problem. So, it should warrant more attention. I have already suggested that coastal tiles should get more priority than they do currently If they get more priority than the multiple resource sites, then this will do the trick. There may be other solutions.

For the most part, I would suggest that the multiple-resource condition be changed in two ways. (2a) Instead of resources being a SUM function, let's use a MAX function. In other words, 2 food resources (valued at X each) does not equal 2X, it still equals X. At minimum, let's make it X+1 (assuming X is a large number... at least 4).

(2b) Probably the value algorithm already has a clause which computes total probable food for the hypothetical city. If it doesn't, then it needs this regardless of this other stuff.

Wodan

I did make two suggestions just above where I quoted you that should help accomplish what you (and I) want. It will probably be necessary to read the simplified readable city placement algorithm posted by Iustus to see what my changes entail. That will take some time as it is a lengthy algorithm. For instance, your suggestion to limit the effect of food resources on city placement is almost exactly the same as the one that I did just above the section where I quoted you. So we agree on that.

However, you can't just beef up the value of coastal placement. That would indeed result in coastal city placement in the case that you described in your previous post, but it might also result in coastal city placement in situations where it is not desirable. For instance where two cities are placed on opposite shores of an island with a narrow strip of unused land inbetween them. That land will not be used (except by a marginal city), while the 2 coastal cities will only get some ocean tiles that would otherwise be unused.

We humans often think ahead when we place cities and it is hard to get the AI to do similar city placement without thinking ahead. In the present code, there are already big incentives to place cities on the coast. I commented on them in my previous post. They seem to be ok. They might be overshadowed by the food resource bonuses on city placement and thus I suggested some refinement on those similar to what you did in your post.

We actually agree completely on the things that could use some refining. I only think that you cannot get the AI to place cities like a human without making it think ahead. And that might be infeasible for the AI-mod team (however, I should not underestimate them).
 
To Iustus:

I think that Wodan has a point with a distance modifier. I didn't see one in the readable code that you showed us. Something like

Value *= (100 - (distance from city home plot to capital)/mapsize )

Where capital of course means the closest capital-like city and mapsize is a variable also used in the city-distance upkeep formula (something like (mapheight + mapwidth)/2). This would ensure that the AI will first build cities that are closer to the capital if the difference in value between two possible city locations is small. The modifier is not that large that it will mess up city placement.
 
To the 'too few wars' issue:

My changes that:
-setting warmongerrespect to 0
-increasing openborders threshold by one (exlc. Tokugawa)
-taking back nowarattitudeprobs values
-giving free mysticism to everybody
seem to work well for me.
There are quite a few wars in current games between AI-AI and also Shaka attacked me with a huge stack taking a major city :goodjob: but made a mistake he had almost only melee units so with a crazy axemen rush i could stop them. Now it's payback time. My city is recaptured and i also took a small of theirs. Now amassing for my drive on their major city (with military instructor in). I'll only accept capitulation ;)
 
Roland Johansen said:
As I can see, there are 2 bonusses for settling on the coast:
Bonus 1:


if coastal city and this plot water and this plot commerce > 1
tempValue += 40

Bonus 2:

if coastal city
{
value += 300

if not GameStart
{
if we have no other cities on this land mass
value += 400

value += 200
}
}

Both bonusses look good and surely significant. They should make coastal founding more attractive. I don't think this needs any improvements in the near future. Maybe some refinements after a lot of testing. I could imagine that ocean tiles could also get a smaller +value (compared to coastal tiles) if the city is coastal. Ocean tiles aren't that great, but sometimes they're better than nothing and if it allows more cities to fit on an island, then that's nice. The bonus shouldn't be too big though as ocean tiles aren't that great.
I've underlined the bit which deals with Ocean tiles, if the tile only has 1 commerce it DOESN'T get a coastal bonus - in other words coastal tiles are given no extra value beyond their 1-0-1 value, which makes them nearly worthless. As such the AI will try to found cities which bring in a maximum of *coast*.

Another VERY important piece of code I added for coastal sense:
Code:
if water bonus resource
	if coastal, value += 150
	else value -= 150


What this does is creates a bonus for founding ON THE COAST with SEAFOOD IN RANGE. It creates a PENALTY for founding OFF THE COAST with SEAFOOD IN RANGE. Originally I had a single +300 bonus, but I found that made the AI too obsessed with sea cities in general, while reducing the size of bonus made them continue to found inland cities with seafood in range, splitting it into a bonus and penalty resulted in much better balanced founding logic, especially combined with the other bonuses for founding on the coast.

Code:
iResourceValue += iSpecialFood * 50
iResourceValue += iSpecialProduction * 50
iResourceValue += iSpecialCommerce * 50
if (iResourceValue > 0)
value += iResourceValue

Most people agree that food is more valuable than hammers which in turn are more valuable than commerce. Also the commerce bonuses of special resources are usually larger than the production bonuses which are in turn larger than the food bonuses. Should therefore the multiplier for food not be bigger than the multiplier for production which in turn would be bigger than the multiplier for commerce? Otherwise commerce resources will be valued very high compared to production resources.
Here I originally used something along the lines of "50, 40, 25" but I found I had to increase the commerce value to prevent the AI founding on commerce resources. If the tile has a high "yield count" you generally don't want to found on it - whatever the yield is.

Food is valued more highly separately, in the later multiplier for "food balance".



I would limit the iSpecialFoodPlus to something like 3 or 4 instead of 8. The special food resource tiles still get lots of bonuses from other lines of code, but this is a really dominating bonus as it multiplies the total value of the city instead of the value of one tile. A city location with 3 food resources will surely be preferred above one with 2 food resources even if the one with 2 food resources has many other benefits.

What this REALLY does is penalizes any site without good food - it heavily discourages founding cities without enough food to work special resources. I however updated this code to make it less "food obsessed".

Since I've returned to this code I've tweaked this stuff a little with some more "anti-clumping" stuff, adding a penalty (to offset some of the bonuses) for founding cities which claim multiples of bonuses, especially unique bonuses (the high point value for claiming a resource the AI has none of yet can get a bit overpowering).

I've also written some code which detects when a (typically coastal) resource will be "deadlocked" by the placement of a city and have the AI make all reasonable efforts to avoid this case.

Here's what I'm talking about by deadlocked resources:
Spoiler :

deadlockedresourcesip8.jpg



I was worried about the run-time of this but now I think it'll be quite acceptable and I can make the foundValue stuff run about 1/10th as often if needed...

By the way, I wrote a long post (no 253) about combat strategy for the AI. I wonder if the post was noticed? It might be useless as the AI might already do the stuff that I mentioned there. I just want to know if the post was read.
I read everything it was just mostly stuff the AI already does.
 
I've underlined the bit which deals with Ocean tiles, if the tile only has 1 commerce it DOESN'T get a coastal bonus - in other words coastal tiles are given no extra value beyond their 1-0-1 value, which makes them nearly worthless. As such the AI will try to found cities which bring in a maximum of *coast*.

Yes, I understand. I was talking a bit about how the coastal tiles that were not linked to land (the 1-0-1 tiles) were valued very lowly even by coastal cities. I agree that those tiles are not great. But they are better than some other bad tiles. But I don't think that this really needs any change as giving it a low value would not alter the city placement by the AI and I also don't think it is needed.
Blake said:
Another VERY important piece of code I added for coastal sense:
Code:
if water bonus resource
	if coastal, value += 150
	else value -= 150


What this does is creates a bonus for founding ON THE COAST with SEAFOOD IN RANGE. It creates a PENALTY for founding OFF THE COAST with SEAFOOD IN RANGE. Originally I had a single +300 bonus, but I found that made the AI too obsessed with sea cities in general, while reducing the size of bonus made them continue to found inland cities with seafood in range, splitting it into a bonus and penalty resulted in much better balanced founding logic, especially combined with the other bonuses for founding on the coast.

Yes, a very nice piece of code. I can see this working just right.


Blake said:
Here I originally used something along the lines of "50, 40, 25" but I found I had to increase the commerce value to prevent the AI founding on commerce resources. If the tile has a high "yield count" you generally don't want to found on it - whatever the yield is.

Food is valued more highly separately, in the later multiplier for "food balance".

Ok, I can see how the code that prevents founding on resources could make this change necessary.



Blake said:
What this REALLY does is penalizes any site without good food - it heavily discourages founding cities without enough food to work special resources. I however updated this code to make it less "food obsessed".

Since I've returned to this code I've tweaked this stuff a little with some more "anti-clumping" stuff, adding a penalty (to offset some of the bonuses) for founding cities which claim multiples of bonuses, especially unique bonuses (the high point value for claiming a resource the AI has none of yet can get a bit overpowering).

That sounds great. It seems that the settling code has again gotten more complicated after the version that was shown by Iustus.



Blake said:
I've also written some code which detects when a (typically coastal) resource will be "deadlocked" by the placement of a city and have the AI make all reasonable efforts to avoid this case.

Here's what I'm talking about by deadlocked resources:
Spoiler :

deadlockedresourcesip8.jpg



I was worried about the run-time of this but now I think it'll be quite acceptable and I can make the foundValue stuff run about 1/10th as often if needed...

Yes, I can see that it would be difficult to make the AI avoid such a situation. The resources are very attractive. You're talking about the run-time; did you make the AI think ahead in this case? Or did you make it realize that it won't be using a lot of good (2 commerce) coastal tiles? However you did it, great work.


Blake said:
I read everything it was just mostly stuff the AI already does.

Ok, thanks. I had hoped that the AI was more capable on the strategic level if it were already doing that stuff. I often find little resistance of a defensive army after I've beaten its offensive army. I guessed that the AI didn't use a strategic defense force, but apparently it does but just not very effective. I have not fully experienced your latest changes yet, but I'm going to play a bit after this post.


Great Person Factory:


I have another suggestion. I hope it can be useful. You have written many lines of code to avoid the situation where an AI farmes many tiles while it could build more useful terrain improvements on those tiles like cottages. You also learned the AI to use the whip. Both elements are great improvements and make the AI more competitive. However, the AI used to apply the extra food to get some specialists in its cities. A far from optimal strategy, but it did give it some great persons. I can imagine that it will get a lesser amount of great persons now. The human player will often use a great person factory to get its great persons. In the late game those cities can get a much as 100 Great People Points per turn. It would be great if the AI also tried to get a great person factory.

A possible method to do this might be to have a triggering event. After the AI has researched certain technologies that allow it to build buildings that enable specialists (temple, grocery, market, forge and libary for instance or maybe just 5 specialist enabling buildings to make it mod friendly), the AI will scan its lands for the potentially highest food producing city and then change the land around that city (into farms and windmills) so that the city can support many specialists to produce great persons. It will designate this city as the future location for the National Epic (+100&#37; Great Person Points) and the Globe Theatre (no more unhappiness in this potentially large city). And the governor setting will be to focus on specialists.

You of course don't want an AI that is being beaten to a pulp and has only 2 cities left to start changing one of its cities in a great person factory. So you probably would like an empire to have a minimum number of cities (map size dependant) and not being at war to start building such a city.

Would such a thing be possible or is this far too hard or just not as effective as I hope it would be?

Good luck with your future improvements!
 
Hi BetterAI-team.

I've found an instance where the governer has some strange behaviour when I emphasize commerce. It is clear that it would use the cottaged tile instead of the oasis as the cottage can grow to produce more commerce, but I see no reason to use the coastal tile instead of the oasis. See the picture below.

Strange Governer.JPG
 

Attachments

  • Strange Governer.JPG
    Strange Governer.JPG
    154.9 KB · Views: 159
Hmm. Okay I see where my previous suggestion didn't work. Here's another one that I think has more promise.

We already have a modifier based on distance from already established cities (though I've suggested this could be tweaked to give it more emphasis in relation to other modifiers).

This modifier could be imagined as a band of concentric rings surrounding each of your cities. The band of color, say, green, is darkest at range 5.

Let's add a further adjustment modifier, based upon number of potential city sites within the distance range of the current tile. For example, pick a spot, X, and imagine it has its own distance band, in another color, say, blue, darkest at range 5 from the current tile. Add them all together, and weight each one heavily by the green band. Water and mountain tiles add 0 or null.

Just trying to think outside the box...

Wodan
 
Hi BetterAI-team.

I've found an instance where the governer has some strange behaviour when I emphasize commerce. It is clear that it would use the cottaged tile instead of the oasis as the cottage can grow to produce more commerce, but I see no reason to use the coastal tile instead of the oasis. See the picture below.

Could the fact that the city has hit its happy cap be the determining factor? It's only anecdotal, but I've noticed a tendency on the part of the city governor to slow down growth at the cap, unless explicitly instructed otherwise (with Emphasize Food) or manually shifted.

Codex
 
Back
Top Bottom