AI Turn Times

jmmendesp

Warlord
Joined
Jul 4, 2012
Messages
155
Hey there, folks.

I wanted to discuss the time the AI takes to makes its turns using the C2C mod, depending on settings, of course.

I know that playing on smaller maps and with fewer civs will speed up times, but I could've already read in any of the other threads you can find on google about "speeding up AI turn times". :lol:

So let's dig a little deeper.

What are the most important factors in your computer affecting AI turn time?

The video card should matter next to nothing as long as there's nothing graphical going on during turns (battles, etc.), correct? Based on this assumption, graphic options shouldn't make a difference, either. I see a lot of people recommending to lower resolutions, textures, etc. - how does this relate to the time the AI takes to "think" and make its moves (note that we're assuming no movement is seen by the player at all)?

How about memory? I have 8 GB of RAM. Will Civ 4 (and C2C) use them to its fullest? Is there a way for me to find out? I'm assuming with 8 GB ram wouldn't be a bottleneck - but maybe poor usage of it is.

Now, the CPU. I'm assuming this is the one most likely to be a bottle-neck. I have a quad-core, which I've read means bad news for AI turn speed in CIV 4. Is there any tweaking that can be done to maybe make CIV 4 get one of the cores all to itself, increasing (hopefully) turn speed?

I know C2C adds a lot of stuff, so probably I'm not the one with slow turns. I guess we could have this thread as a place to discuss this issue and keep a compendium of user experiences, tips and tricks. How long are your times, what settings you play on, what have you found usually helps you speed things up?
 
Hey there, folks.

I wanted to discuss the time the AI takes to makes its turns using the C2C mod, depending on settings, of course.

I know that playing on smaller maps and with fewer civs will speed up times, but I could've already read in any of the other threads you can find on google about "speeding up AI turn times". :lol:

So let's dig a little deeper.

What are the most important factors in your computer affecting AI turn time?

The video card should matter next to nothing as long as there's nothing graphical going on during turns (battles, etc.), correct? Based on this assumption, graphic options shouldn't make a difference, either. I see a lot of people recommending to lower resolutions, textures, etc. - how does this relate to the time the AI takes to "think" and make its moves (note that we're assuming no movement is seen by the player at all)?

How about memory? I have 8 GB of RAM. Will Civ 4 (and C2C) use them to its fullest? Is there a way for me to find out? I'm assuming with 8 GB ram wouldn't be a bottleneck - but maybe poor usage of it is.

Now, the CPU. I'm assuming this is the one most likely to be a bottle-neck. I have a quad-core, which I've read means bad news for AI turn speed in CIV 4. Is there any tweaking that can be done to maybe make CIV 4 get one of the cores all to itself, increasing (hopefully) turn speed?

I know C2C adds a lot of stuff, so probably I'm not the one with slow turns. I guess we could have this thread as a place to discuss this issue and keep a compendium of user experiences, tips and tricks. How long are your times, what settings you play on, what have you found usually helps you speed things up?

It's utterly CPU limitted, and since it's single-threaded, it's all down to single thread CPU performance. Windows will already give over a full core to C2C unless you are runnign a ton of hungry background stuff too, so there is basically not much you can do apart a hardware upgrade, or some over-clocking.

Havign said that, the code still has plenty of scope for further optimization, so if you get cases that seem worse than average (i.e. - something in the game seems to eb slowing things down more) post the save game with any observations and I'll do an analysis of what is consuming the time on end turn for th posted save.
 
It's utterly CPU limitted, and since it's single-threaded, it's all down to single thread CPU performance. Windows will already give over a full core to C2C unless you are runnign a ton of hungry background stuff too, so there is basically not much you can do apart a hardware upgrade, or some over-clocking.

Havign said that, the code still has plenty of scope for further optimization, so if you get cases that seem worse than average (i.e. - something in the game seems to eb slowing things down more) post the save game with any observations and I'll do an analysis of what is consuming the time on end turn for th posted save.

Thanks for your response. First thing I've ever read in this kind of threads that isn't just common sense (play smaller maps, etc.).

Is there anything I can do, having a quad-core processor, to make it execute civ more efficiently, "more like a single core processor"?
 
I think Civ4 came out before widespread use of multiple cores, so I don't know if Civ4 is capable of running on multiple cores. I do know that multi-threaded applications are significantly more complex than single thread applications. The reason is that CPUs access memory on the RAM, if only a single thread is accessing and changing information then there is no problem. However when multiple threads want to access and change the same information problems can occur.

That said it is possible to write multi-threaded applications. Before multiple cores though multi-threading didn't really improve the performance, it only let you do multiple things at once. The reason is that when multi-threading a single core the CPU is essentially just switching very quickly back and forth;the speed of the CPU doesn't change. As such we need to know not just whether Civ4 can be multi-threaded, but whether we can get other cores to work on Civ4 as well. Only when multiple cores work on a single program does multi-threading improve performance.

Like I said though I haven't begun to work on Civ4 code yet, so think of this as a little tutorial on multi-threading and cores.
 
I've asked about multi-threading opportunities, and there is a good amount of it that can be done in the DLL, which we have full control over. However, the resoponse was mostly that Koshling wanted to find more code optimizations before working on making parallelism in certain CPU-hungry functions.

Also, there is another pre-existing thread on performance.
 
I read few posts in performance area and here is the conclusion:
- you don't see way to improve AI turn processing because CIV 4 is actually not mutlicore capable,
- you can only improve small parts of calculation which won't really influence the whole performance as most of the things are done sequentially and even if small portion of calculation is done using multi threading it will still wait for other calculations to be done,
- the last and most important performance was never the subject of concerns in C2C project
Please correct me if I'm wrong.

Juts running game on 8core CPU PC with 16 GB of RAM on Gigantic map with 30 civs. AI turn processing is now 25 minutes and still not done.
 
Did you expect a Gigantic Map and 30 Civs to run fast? Your 8 core CPU and more than 4GB of ram means Nothing in speeding up a single core engine's processing capabilities.

In fact Gigantic maps are not recommended for C2C play, Especially if you are using more than 15 Civs with the REV, Barb World, Barb Civ, Start as Minors, etc Game setup Options that allow new Civs to come into being during the game.

JosEPh
 
Then why those options are available there at all ? providing options which doesn't work as expected might be annoying for users. I run game in such configuration because I wanted to check if it can handle that - it seems it cannot.
Once I click on 'end turn' button I have no idea what is happening - if application freezes because of error or whatever else. Are you familiar with any plans for providing something like progress counter or something like that (can we calculate number of turns which have to be processed by AI ?)? I am not saying I expect it tu run fast - I would like to know if application is working and know the progress- this is simple application design rule.
 
Then why those options are available there at all ?

C2C is specific mod. Is HUGE. You can play on gigantic map for sure but with 4-6 civilizations. For more civilizations choose smaller map.
 
Then why those options are available there at all ? providing options which doesn't work as expected might be annoying for users. I run game in such configuration because I wanted to check if it can handle that - it seems it cannot.
Once I click on 'end turn' button I have no idea what is happening - if application freezes because of error or whatever else. Are you familiar with any plans for providing something like progress counter or something like that (can we calculate number of turns which have to be processed by AI ?)? I am not saying I expect it tu run fast - I would like to know if application is working and know the progress- this is simple application design rule.

The whole process of making C2C has been to discover the "boundaries" of the BtS game engine. Over the course of the Mods 6 year development cycle the boundaries in many areas have been discovered thru the use of various game setup and BUG options. It was only a recent thing that Gigantic was considered to be removed from the map size list. The Mod did have 2 more sizes Bigger than gigantic just last year. But because players have this idea that they can run a game with 50 Civs (because someone out in the Modding BtS Community Made a 50 civ DLL with No consideration for map size), the options are still available. But it is up to You the Player to find out what you Comp can handle and what limits your play style and preferences can use. There are many ways to play this Mod and many combinations of Options that do work. But with it's size alone don't expect it to run smoothly if you throw in every thing, use the largest settings, etc..

As Sparth just pointed out you can play a gigantic map with a handful of AI on a slow speed and have an excellent game, especially if you like the eXploration part of the 4X strategies ( eXplore, eXpand, eXploit, and finally eXtermination).

It's really up to you to explore the possibilities of the Mod and find out what your "Limits" are. And as you have now discovered 30 Civs on a Gigantic Map (with who knows what Options you have chosen because you have not said what they are) runs slow at whatever Era (again not stated) your current game is in.

JosEPh
 
- the last and most important performance was never the subject of concerns in C2C project
Please correct me if I'm wrong.

Huge improvements in turn times have been made in C2C over base BtS. The main problem is that as the improvement code performance increase so does the amount of stuff which slows the game play down again.
 
I'm not putting it past things to have some delay spots at the moment that shouldn't exist... one was recently fixed, a big one. But more new ones could exist. There's some bugs that need to be found soon but so far of late I've been finding the turn times are actually surprisingly good compared to what they once were. Particularly considering how many new processes have been put in that I was concerned COULD represent a slowdown... seems its actually real bugs that tend to cause big problems more often than code that actually does work. The speed of processing sometimes amazes me what it can manage to calculate in such a small amount of time - its when we run needless loops thousands-millions of times that it causes major issues.
 
I'm not putting it past things to have some delay spots at the moment that shouldn't exist... one was recently fixed, a big one. But more new ones could exist. There's some bugs that need to be found soon but so far of late I've been finding the turn times are actually surprisingly good compared to what they once were. Particularly considering how many new processes have been put in that I was concerned COULD represent a slowdown... seems its actually real bugs that tend to cause big problems more often than code that actually does work. The speed of processing sometimes amazes me what it can manage to calculate in such a small amount of time - its when we run needless loops thousands-millions of times that it causes major issues.

It's possible make, for example, the trade route calculation in another separated core?
 
It's possible make, for example, the trade route calculation in another separated core?

In that case it would not be worth the effort to see if it is possible. Because the trade route calculation only takes a few milliseconds per turn.

At the moment the UnitAI takes alot of time so it could be worth checking if it is possible to use multithreading there.
 
In that case it would not be worth the effort to see if it is possible. Because the trade route calculation only takes a few milliseconds per turn.

At the moment the UnitAI takes alot of time so it could be worth checking if it is possible to use multithreading there.

Will be very nice.
 
Now I used huge map and 12 civs - around AD 1660 AI turn already processing for 20 minutes and still not done. As far as I remember my previous game stopped working around same year. Please provide mi information how I can turn on logging and where those logs are stored in order to know if this some kind of error or something - (maybe some infinite loop ?)

Got latest version still cannot go to next turn. Any hints? I saw there was some fix for infinite loop in revision 8262 but even with this fix it is not working.
 
The first post in the Bugs threads tell you how to turn on logging and where the logs are. It wont help in the case of waiting for civs problems though.

You have not used the option to limit the number of units on a plot have you? That is known to cause this endless loop on occasion. If you have raise the number for a few turns before setting it back to what you play on it will clear the problem.

Otherwise we will need to wait for one of the dll experts to have a look at your save to find the cause.
 
There's a known infinite loop bug. It's not often found but when it is it's a pain. Alberts has already resolved it but to solve other issues the resolution causes expands that project a bit into territory where some development was desired anyhow. So all I can say on that matter is if you go into worldbuilder and kill just the right Master Hunter unit on the map you can solve it. Rather unfair to the AI, sure, but the problem lies in one of them and what happens when he tries to join up with escorts to a Great General who wants to go on a self development driven hunting expedition.
 
Hi I tried to debug and here is what I found:
Game freezes when you end turn (I've been waiting more that 15 minutes and nothing - previous turns were fine)
http://szredziu.ayz.pl/AutoSave_AD-1641.CivBeyondSwordSave

I have SVN revision 8283.

I debugged it and here it what I found - can anybody verify correctness of my investigation ?
In CvGame.cpp is declared a method void
Code:
CvGame::update()
and it has defined label 'again':
Code:
}
			bSetSMCached = true;
		}
	}

again:
	if (!gDLL->GetWorldBuilderMode() || isInAdvancedStart())

and goto statement in same method below:
Code:
CvPlayerAI& kActivePlayer = GET_PLAYER(getActivePlayer());
	if ( (!kActivePlayer.isTurnActive() || kActivePlayer.isAutoMoves()) && !kActivePlayer.hasBusyUnit() && !isNetworkMultiPlayer() &&
		 getBugOptionBOOL("MainInterface__MinimizeAITurnSlices", false) )
	{
		updateTimers();

		goto again;
	}

	PROFILE_END();
I noticed that even after 20 minutes application is still in this GOTO loop.
Maybe this is the reason why sometimes game freezes after ending turn ?
 
Hi I tried to debug and here is what I found:
Game freezes when you end turn (I've been waiting more that 15 minutes and nothing - previous turns were fine)
http://szredziu.ayz.pl/AutoSave_AD-1641.CivBeyondSwordSave

I have SVN revision 8283.

I debugged it and here it what I found - can anybody verify correctness of my investigation ?
In CvGame.cpp is declared a method void
Code:
CvGame::update()
and it has defined label 'again':
Code:
}
			bSetSMCached = true;
		}
	}

again:
	if (!gDLL->GetWorldBuilderMode() || isInAdvancedStart())

and goto statement in same method below:
Code:
CvPlayerAI& kActivePlayer = GET_PLAYER(getActivePlayer());
	if ( (!kActivePlayer.isTurnActive() || kActivePlayer.isAutoMoves()) && !kActivePlayer.hasBusyUnit() && !isNetworkMultiPlayer() &&
		 getBugOptionBOOL("MainInterface__MinimizeAITurnSlices", false) )
	{
		updateTimers();

		goto again;
	}

	PROFILE_END();
I noticed that even after 20 minutes application is still in this GOTO loop.
Maybe this is the reason why sometimes game freezes after ending turn ?

Could you please post this in the Bug sub forum in the SVN Bug thread--> http://forums.civfanatics.com/showthread.php?t=532170

It's more likely to be seen by the AI coders there than here.

Thanks for the report.

JosEPh
 
Top Bottom