1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

AI turn time

Discussion in 'Civ4 - Better AI' started by Voltage, Aug 13, 2009.

  1. Voltage

    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?
     
  2. sourdiesel

    sourdiesel Warlord

    Joined:
    Jun 30, 2009
    Messages:
    158
    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.
     
  3. The_Reckoning

    The_Reckoning Prince

    Joined:
    Sep 21, 2005
    Messages:
    419
    Location:
    UK
    Same here.
     
  4. Maniac

    Maniac Apolyton Sage

    Joined:
    Nov 27, 2004
    Messages:
    5,588
    Location:
    Gent, Belgium
    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.
     
  5. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    Thanks for bringing the profiler techniques to my attention Maniac, that's some cool information which should really help.

    I know of one function I wrote which is horribly inefficient, will see what else I learn from profiling.
     
  6. scu98rkr

    scu98rkr Prince

    Joined:
    Nov 2, 2004
    Messages:
    463
  7. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    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.
     
  8. Maniac

    Maniac Apolyton Sage

    Joined:
    Nov 27, 2004
    Messages:
    5,588
    Location:
    Gent, Belgium
    Weeeeeeeeeeeee!
     
  9. Voltage

    Voltage Warlord

    Joined:
    Oct 4, 2006
    Messages:
    173
    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:
     
  10. Grashopa

    Grashopa Emperor

    Joined:
    May 16, 2009
    Messages:
    1,307
    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?
     
  11. armand453

    armand453 Chieftain

    Joined:
    Jul 25, 2007
    Messages:
    45
  12. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    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.
     
  13. Lord Tirian

    Lord Tirian Erratic Poster

    Joined:
    Nov 30, 2007
    Messages:
    2,724
    Location:
    Liverpool, UK
    Well, you're close to it... and it would be incredibly cool! I hope you can pull that off!

    Cheers, LT.
     
  14. Dom Pedro II

    Dom Pedro II Modder For Life

    Joined:
    Apr 3, 2002
    Messages:
    6,811
    Location:
    Exit 16, New Jersey
    I could definitely use a faster-than-BtS BBAI :)

    Because my mod changes will certainly be dragging it a bit.
     
  15. Yakk

    Yakk Cheftan

    Joined:
    Mar 6, 2006
    Messages:
    1,288
    Careful -- the AI calls into the EXE to do pathing. You certain you got the in-EXE pathing code?
     
  16. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    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).
     
  17. jdog5000

    jdog5000 Revolutionary

    Joined:
    Nov 25, 2003
    Messages:
    2,601
    Location:
    California
    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.
     
  18. Voltage

    Voltage Warlord

    Joined:
    Oct 4, 2006
    Messages:
    173
    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 :)
     
  19. Jawa'sRevenge

    Jawa'sRevenge Warlord

    Joined:
    May 6, 2009
    Messages:
    246
    Location:
    Galaxy Far Far Away
    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?
     
  20. Dom Pedro II

    Dom Pedro II Modder For Life

    Joined:
    Apr 3, 2002
    Messages:
    6,811
    Location:
    Exit 16, New Jersey
    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.
     

Share This Page