limitations to AI in spreading past bad terrain?

davidlallen

Deity
Joined
Apr 28, 2008
Messages
4,743
Location
California
Hi, I have been working with keldath on his dune mod at this link, and we cannot figure out how to get the AI to spread new cities past certain terrain. Unfortunately you cannot see this behavior in the current release. Keldath is in the middle of updating bunch of files, but a new release will probably be out in the next day or two.

We have added a terrain "deep desert" which is land, but has the terrain flag bFound 0 so that cities cannot be founded on it. We have converted the mapscripts such as archipelago or continents, so that what used to be ocean and coast is this new terrain. So the player can expand normally on the "real" land, and you can move land units across the deep desert to found new cities on other "continents".

This works fine for the human player, but we have never seen the AI send settlers across the deep desert. The AI civs fill up whatever archipelago or continent they are on, and then stall. They never expand across the desert even when the other side is rich, and unoccupied.

Can anybody think of a way to affect this with xml or python? Maybe if we model the desert differently, the AI would have a better time.

We have discussed about treating the deep desert as ocean territory and using modified ocean transports as the units to carry settlers and armies across. In fact the present release version works that way. One problem with this is that you have a fake concept of a "port city" on the edge of the deep desert, and the AI won't move transports across the land anyway. Perhaps this setup is closer, but it does not seem to help either; you can see some details of this in the thread and the earlier dev thread.
 
No answers so far, just more questions. In the dune wars thread, komas13 wrote:

If that is true it would explain why ai isn't expanding. The only way for AI player to found a city far away would be placing it in another area. The problem is if we replace ocean plots with land plots, the whole map will be counted as only 1 area. To fix that behaviour we have remove the restriction where ai can found cities.
SDK.

I can try but I could need some help. Keldath, do you think you can look into it? A good start (imho) would be CvUnitAI::AI_settleMove() and CvPlayerAI::AI_foundValue().

I looked into AI_foundValue. It is a *900* line long single function with minimal comments, so it is a little difficult to understand. However, it may be that the problem is the city distance cost. There is some code there which rejects sites where the distance cost would be high. If so, then adding a city > 20 squares away would be right out of the question. That sounds like it might be the problem.

An experiment to prove this would be to set the distance cost to zero, and then see if we get colonies there. But I am not sure how to do this.

There is the civic option iDistanceMaintenanceModifier which some civics like TECH_UTOPIA give. I can try setting this to -100 for *all* civics, but I cannot find any evidence that AI_foundValue respects this.

Does anybody know how to set the distance cost to zero, in a way which AI_foundValue will respect?
 
You'd probably have better luck re posting this thread in the BetterAI forum. I know jdog will eventually see it, and he'll have some useful information on the subject if you do. I don't think he reads this forum though, at least never seen him post in it.
 
Yep, some of those long DLL functions are pretty damned confusing. :crazyeye: (<-- Interesting fact: That smilie is actually based on the expression on my face when I first looked at the DLL code)

But, hidden somewhere in the very bowels of that AI_foundValue function is a bit of code where the AI player tests the distance of a plot from its nearest existing city (the 'ideal distance' is either 4 or 5 squares in the default BTS DLL). It then also reduces the value of plots further away from your capital (and increases it for plots closer to it).

Here's the relevant code:

Code:
		    int iDistance = plotDistance(iX, iY, pNearestCity->getX_INLINE(), pNearestCity->getY_INLINE());
		    int iNumCities = getNumCities();
		    if (iDistance > 5)
		    {
		    	iValue -= (iDistance - 5) * 500;		    	
		    }
		    else if (iDistance < 4)
		    {
		    	iValue -= (4 - iDistance) * 2000;
		    }
			iValue *= (8 + iNumCities * 4);
			iValue /= (2 + (iNumCities * 4) + iDistance);
			if (pNearestCity->isCapital())
			{
				iValue *= 150;
				iValue /= 100;
			}
			else if (getCapitalCity() != NULL)
			{
				//Provide up to a 50% boost to value (80% for adv.start)
				//for city sites which are relatively close to the core
				//compared with the most distance city from the core
				//(having a boost rather than distance penalty avoids some distortion)
				
				//This is not primarly about maitenance but more about empire 
				//shape as such forbidden palace/state property are not big deal.
				CvCity* pLoopCity;
				int iLoop;
				int iMaxDistanceFromCapital = 0;
				
				int iCapitalX = getCapitalCity()->getX();
				int iCapitalY = getCapitalCity()->getY();

				for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
				{
					iMaxDistanceFromCapital = std::max(iMaxDistanceFromCapital, plotDistance(iCapitalX, iCapitalY, pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE()));					
				}
				
				int iDistanceToCapital = plotDistance(iCapitalX, iCapitalY, iX, iY);
				
				FAssert(iMaxDistanceFromCapital > 0);
				iValue *= 100 + (((bAdvancedStart ? 80 : 50) * std::max(0, (iMaxDistanceFromCapital - iDistance))) / iMaxDistanceFromCapital);
				iValue /= 100;
			}

The simple way around your problem is to make this distance tests a bit more relaxed (i.e. lower the penalty for being further away from the capital/nearest city), but you could then see some strange city placement behaviour when the AI doesn't have bad terrain around, so it would be best if it could be made situational somehow. Maybe just lower the player's 'minFoundValue' (which you can find elsewhere in CvPlayerAI) if it has no good city sites left locally?

EDIT: komas13's point is also pretty good. Can you change the code so that the AI uses deep desert to separate 'areas' instead of ocean? Will that work properly (for the AI) without transport ships?
 
i dont know much about sdk,

but my first idea for having an all land terrain,
was to somehow -
change the water terrain - to behave just like land terrain, meaning it will still be a seperate domain then water, but it will still have same functionallity like land, same properites,

or i dunno, maybe to create an all terrain domain, using land domain as basis, but can access all terrain.


that would probubly solve the problem much better , since the ai will behave the same as always. we sont have the problem of map gen, or ai behaviour on sea - casue it will think its water, but with land properties,

maybe im just babbling.....:)
 
Thanks for the investigation. What we observe is that the AI *never* sends settlers across the deep desert. We *think* this may be due to high distance cost. One possibility is to hack the dll with some different values. Sadly, I am not able to attempt this; I have not gotten into building the dll. If there is any way to affect this with python or by modifying existing xml parameters, I can do it.

Is there somebody who could take a crack at changing the dll to see if this is really the problem? You can dl the mod and apply "patch 1" from keldath in this post, then you will see the problem.

I think we need to prove whether the distance cost is really the problem; it could be something else. It seems if distant colony sites were *possible* even if they had low value, we would not see the behavior we are seeing. What we would like is to have nearby sites considered first like they are today; but at least *consider* distant sites. Maybe there is a threshold somewhere else in the code which is *preventing* distant colonies; that is what we need to find and get rid of.

Regarding whether the deep desert should be land or ocean, in the dune thread and its previous dev thread we have gone around in circles on this. Basically, it is important to have some kind of transport vehicles to get the dune feel; nobody believes tanks driving through the deep desert. It is known that the AI cannot take advantage of land transport. It is also known that the AI does "poorly" at amphibious assault. So it seems that neither approach will work well. We need some kind of solution for this to get a good dune feel. Any discussion or new ideas would be greatly appreciated.
 
davidlallen,

im not so sure that this has to do with the distance,
ill explain why,

deep desert and desert waste are basically - land defined terrain,

when we tried it - the ai as we know didnt crossed it - even when the settler can move over it.

but,
if you start a game , and set - low sea/desert level - they ai will settle normally on the regular terrain, and expand till theres no more room.
thus, it should behave like this on the new terrain types,

so i think, somthing in the map script is replacing the tiles to desert. but, it does not replace its designation - in the ai'S "eyes" - its still water - so perhaps in the map script - theres some place that needs to be replaced.
 
I agree we don't know the answer. But, all the mapscript is doing is putting terrain into each plot. So if there is a problem with the terrain definition somehow still being "waterlike", the solution is in xml\terrain\civ4terraininfos.xml, not in the mapscript.

(EDIT: What you have described is still consistent with a high distance penalty; it does not prove or disprove the theory. We agree that the AI will successfully expand through connected, foundable terrain, regardless of whether this is large or small. The question is why doesn't the AI show interest in founding at some long distance away. Yes, the settlers can cross it, but it is possible that the AI gives such a high penalty to the site, due to distance, that the AI decides not to bother.

I do not think it is a terrain issue. But we have not yet proved that it is purely a distance issue, and we cannot prove it without a hack to the dll in order to relax the distance penalty. If there is another way to test this, I am open to suggestion.

It would also be interesting to play a game, and establish a colony on the other side (as a human player). The distance cost will, in fact, be painful. I have won several small games on low difficulty (I am no expert player) but I have always run out of gold. I wind up surviving on the pillage bonus and destroy all but one or two of the enemy cities. So the AI may actually be right about avoiding to establish distant colonies; there may not be enough gold income to make it reasonable.

I also notice that the AI does not attack distant enemies. I will try a game with aggressive AI and higher difficulty, to see if I can at least generate some distant attacks.
 
Sadly, I am not able to attempt this; I have not gotten into building the dll. If there is any way to affect this with python or by modifying existing xml parameters, I can do it.

In my experience in many ways modifying the SDK has been easier then hacking things in with Python. You should really just go for it, the only inherent issue that makes it a little bit more complex is setting up the compiler, but that's more of a skill of following directions then technical skill. Once you set up the compiler, as I said, dll modding is just as simple and in many ways easier then Python.

[SDK] Using Microsoft Visual C++ 2005 Express Edition Walks you through setting up the compiler.
An Idiots Guide to Editing the DLL Was helpful for me, but probably not necessary for you, since you are a programmer. Walked me through how to add in XML tags, and discusses how to expose new functions you create in the gamecore to python.
 
If you want to be certain if it is a Terrain issue or a Distance issue, create a small map. Make 2 small land masses (only big enough for 1 or 2 cities)separated by 1 tile of your new terrain. Put an AI on one of them and watch what it does.

If it is a distance issue, the 2nd 'island' will get colonized. If it is a terrain issue then it will not.
 
Sounds like a distance issue, then. Either that or your squares aren't producing enough food (I don't know how you're handling resources with the mod being desert-based) and the city sites are being rejected because the AI thinks they have too many 'bad' tiles. This would affect city sites right next to your capital equally, though.
 
Back
Top Bottom