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.