AI turn time

Voltage

Warlord
Joined
Oct 4, 2006
Messages
173
I merged BUG and Better AI together as described in the merge thread.

Without Better AI throughout a game i get no more than 12 second AI turn duration time. With Standard map, 8 Civilizations and going through the all the ages.
With Better AI im getting 25+ second turn duration time at only the renaissance era with the same set up.

Is this normal? If not is there any way to speed up AI turn time?
 
I get the same. This is the downside of betterAI, and possibly the stumbling block that prevents it from becoming "standardized" among civ players, at least until CPU speeds (effectively) double again.
 
Are there any functions in particular which take up so much time? Or is it rather all the small unit AI checks added together which lead to a large increase? This could probably be found out using techniques described here.
 
The next version of BBAI will be quite a bit faster ... my previous implementation of picking up stranded units was terribly inefficient and added a ton to turn times. It's now much much faster, cached and everything.

Dont mean to be a pest :lol: Can you give an estimate of the decrease percentage you hope the next version will give and roughly how long till that version is made public? I ask because i really want to play all the mods that use improved AI, i have avoided them because it takes too long to play a game :(

Im like the fat kid staring through the window of a cake shop :lol:
 
Any way to do some calculations like once every 10 or 20 turns? Faster turns and a less frequent pause would probably be acceptable and useful for things like victory strategy?
 
Any way to do some calculations like once every 10 or 20 turns? Faster turns and a less frequent pause would probably be acceptable and useful for things like victory strategy?

AI strategy calculations take very little time ... CPUs are incredibly powerful, things only slow down when there's tons of looping over large data sets. It's been interesting to see exactly what the code spends most of it's time doing, it's not what you'd expect.

For the late game on a huge map, here's some typical stats from my test runs:

- Handling graphics and other EXE stuff not in the DLL (ie, not AI) represents 40-70% of turn time.

- About 25-35% of turn time is spent moving units. Path planning is very fast, but a typical turn in the late game on a huge map involves tens of thousands of path generation calls, and each of those can search over hundreds of plots ... guaranteeing safe paths for non-combat units is the slowest.

- About 7% of turn time is spent deciding which plots each AI city should work.

- When plots change hands, roads get pillaged, or blockades are set, the game recalculates which plots are in the same trade plot groups for different players. This takes 5-8% of turn time.

- The profiler reports that 3% of turn time is spent on diplomacy decisions, but I think there's overlap between this and the plot group calculations above.

- AI cities spend 1.5% of turn time deciding what to build/train.

- Higher level AI calculations of strategies hardly register as time taken (very few loops).

These numbers are approximately correct for plain BTS and my current development version of BBAI. In BBAI 0.80 and past versions, some very inefficient code for detecting when units were stranded caused unit moving to balloon to 50-60% of turn time in some cases.

I've fixed the stranded code so it's now only a 0.5% increase in turn time, and I have a new idea which should cut it down to a negligible fraction. In addition, I've adapted some of the variable caching ideas from CAR to speed up path planning for non-combat units, these tweaks now require less cache invalidation so they're less likely to have bugs and they also take less memory (though the CAR ones don't take much in the grand scheme of things).

For testing turn times I generated a WBSave of a 1000AD Earth map simulated forward to 1980. I then run 25 turns for time on this Huge 1980 (ie late game) map with war/peace locked. (Note: when you load a WBSave or scenario, the first couple of turns will take extra time because Civ4 doesn't immediately allocate all the memory it will eventually use. So, I first let a handful of turns pass untimed so as to bypass this issue. This doesn't happen if you load a regular save game).

Here are some preliminary results:

Code:
BBAI 0.80		18m 48s		45s/turn
BBAI 0.81e		14m 00s		34s/turn
UP 1.1			13m 25s		32s/turn

These are turn times with the game open, not minimized, so they include graphics processing time. These then represent what you'd really get so long as you have quick combat on and show friendly/enemy moves off (and my computer ... a two year old laptop).

There are a few more things I want to do for 0.81 to bring the turn time down, including some further refinements to stranded unit detection and bringing over more a couple more things from CAR. With those pieces, turn times with BBAI may even be faster than plain BTS on this test, we'll see.
 
There are a few more things I want to do for 0.81 to bring the turn time down, including some further refinements to stranded unit detection and bringing over more a couple more things from CAR. With those pieces, turn times with BBAI may even be faster than plain BTS on this test, we'll see.
Well, you're close to it... and it would be incredibly cool! I hope you can pull that off!

Cheers, LT.
 
- Handling graphics and other EXE stuff not in the DLL (ie, not AI) represents 40-70% of turn time.

- About 25-35% of turn time is spent moving units. Path planning is very fast, but a typical turn in the late game on a huge map involves tens of thousands of path generation calls, and each of those can search over hundreds of plots ... guaranteeing safe paths for non-combat units is the slowest.
Careful -- the AI calls into the EXE to do pathing. You certain you got the in-EXE pathing code?
 
Good point, but I think the results are correct. The profile for function A is all of the time taken not just by the code in A but also any functions A calls. So when a path generation call goes into the exe to do A*, then comes back to the DLL for pathAdd, pathValid, etc, the total time taken for path generation will still be included in the profile for CvSelectionGroup::generatePath and thus included in the total profile for CvGame::update (the root DLL function it seems).
 
Development version 0.81g has been released, it's stable and has been tested but the new cache system needs additional testing. Please give it a try or look through the new cache code if you're able.

It includes significant improvements to AI turn time, both in improving some of the features in BBAI and borrowing some inspiration from CAR.
 
This is how my computer handles this mod now, 550 turns into the game...

Vanilla BTS 7-12s turn time
BBAI AI 0.81g 14-18s turn time
Older BBAI 35s+

thats a great improvement jdog5000, really good work :)
 
It includes significant improvements to AI turn time, both in improving some of the features in BBAI and borrowing some inspiration from CAR.

Would there be any improvement if BBSAI (the new or next one) was merged with CAR, say for a mod so there would be no save game compatibility issues?
 
Would there be any improvement if BBSAI (the new or next one) was merged with CAR, say for a mod so there would be no save game compatibility issues?

Some parts of CAR have been incorporated into this according to jdog, but I don't know how much and what else hasn't been included.
 
Back
Top Bottom