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

Discussion in 'Civ4 - Community Enchancement Project' started by Olleus, Jun 2, 2006.

  1. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
    When I get Warlords I'm going to start work in earnest on the genetic AI. It's going to be quite a chore going through all the variables adding tags for them... I might just identify a few important looking ones to start off with, and optimise them first.

    Anybody got any suggestions for key variables? Values of food/commerce/hammers for cities seems like a pretty key one to me. Also might filddle with the tech decisions, and war decisions.
     
  2. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
    Right. Well I found a quicker way of adding the AI variables (wrote a program to do it for me), so that's done now. I'm starting to run some tests, but I think I will have to put some major in work on my fitness function - final score, while it may be a good representation of how the AI has done in a particualar game only gives me one value per AI, per game... which is not only slow, but fairly dependant on starting positions.

    I'm getting times ranging between 30mins and 1 hour for a 6 player standard map game... so that's between 5 and 10 mins per AI per map, which, with a generation size of 50, and 10 games per AI gives generations lasting 2.5 days. Perhaps a bit too long. I need to find some way of speeding this up. I have ~ 1500 variables, and I have a strange feeling to get results I'm looking at a massive amount of time.

    I think my next task will be to generate/try to find a map script which will give each AI a fair starting position, to remove that element of randomness. I'm not too sure though - would this not eliminate AIs which were particularily good in poor starting positions, or which could maximise good starting positions? I'm still undecided about this.

    BTW - I decided not to work on Warlords for a few months until it seems that they have stopped patching it. While the new method of adding variables is quciker, it's still slow.

    EDIT: On further investigation it would seem that the changes I made had more of an influence on the game speed then I thought they had. Quite some slowdown going on. Going to have to a trim removing python events/callbacks and suchlike.
     
  3. Impaler[WrG]

    Impaler[WrG] Civ4:Col UI programmer

    Joined:
    Dec 5, 2005
    Messages:
    1,750
    Location:
    Vallejo, California
    Yes I'm thinking all the Python callbacks that we have in the project are a major source of slowdown, I think we should drop them as their not currently being used for any mod. I'm im the middle of porting all my XML mods into Warlords, I'm droping all the Python stuff and will make the new sourcecode avalible for mod makers to use without having to worry about Python memory leaks or crashes.

    TGA I recomend you develop your code in isolation on a virgin SDK thus removing any conflicts with the rest of the project, it can be merged into Warlords when ready and or patching is done.
     
  4. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
    I use one or two of them in the 40k mod. I'm really not sure how much of a slowdown they cause as I'm hardly being very scientific with my tests (just have Civ slowly bashing through while I do other thigns on the computer).

    EDIT: I think I'd get a big kick in speed if I could lower the MAX_PLAYERS variable... unfortunetly it doesn't seem to like going below 18. Might test it a bit more... unfortuently it needs a full re-compile every time I change it.
     
  5. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
    Right. Turns out much of the speed issues was stuff in the background. It turns out Civ goes to "Below Normal" priority when alt-tabbed.

    I've pretty much got everything strapped down and ready to go. I'll post up a few screenies tomorrow - I might even upload a working copy if tonight's test goes well. I'm having a slight problem with some AIs not building anything at all, which is a bit awkward... I think I might have to manually dive in and fix that variable, although tracking it down is going to be fun! (Current plan is to write a program to look for similar variables in AIs which don't build units)

    Currently all I'm doing is fiddling with the fudge values in pretty much all of the AI calcualtions. I've decided against creating fair maps for the AI to play on. Next task is to write some test algorithms which will either be enabled or disabled in each AI, and hopefully it'll migrate to them.

    Fitness is still based soley on end score, although I'm recording some other stuff alongside score... currently just for the purposes of cool stats. This end score takes into account the early victory bonus, so that should push the victories to be more likely.

    I'm also contemplating releasing it to the public. I think I'll wait until I get the "no-units bug" squished, but I think it would market fairly well without the AI improvement aspect as a way to make the AI more variable.
     
  6. Olleus

    Olleus Warlord

    Joined:
    Oct 30, 2005
    Messages:
    6,478
    Location:
    England
    If you need more computer power then feel free to ask me. My computer is pretty fast (2GB of ram, 256MB video card, 3.14GHz processor), so I should be able to get a few games ran for you.
     
  7. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
    A screenshot of the UI I bodged together. The idea is to allow users to play with their AIs a bit.



    How it works:

    During each game the score, as well as some other stats relating to the AI's characteristics (shown by the bars), as well as the game info, are recorded and appended to the AI's data file. Currently the score is used for fitness, although I've come up with some other criteria for letting an AI continue to either breed, or stay unchanged for the next generation.

    I'm probably going to go for generation sizes of 18, so that a full sized game can be played with all the AIs at once, and so that they don't take too long. These packs of 18 AIs will be downloadable from somewhere (not sure where to put them yet), and people will be able test them, and then send the results back to me for proceesing. Each AI has to play a minimum of 10 games for it to be eligable for proccessing, although they will be able to play more. Once all of a user's AIs have played AI games a prompt will come up when they load a game reminding them to send the AIs back to me.

    The track AI feature allows users to select an AI to follow the progress of. This doesn't really have any effect on the algorithm, however is quite a nice tool to play with. I'll probably add a few more features in this direction such as more detailed stats on tracked AIs, or on-screen updates as the game is running.

    The little +/- buttons by the AI don't do anything at the moment, and might never. The idea was to class AIs based on these factors and from that determine which alterations increase that factor. By using the +/- buttons it would be possible for the user to enhance that factor (although it's more then likely this would degrade other factors).

    It's also possible for the human to play against the AIs. The screen above lets you pick specific opponents to play against which should not only provide a slightly more unpredicable AI then people are used to, but also hopefully a better one.

    I'll probably make a post in main C&C about this later on today. Might be tomorrow if something comes up.
     
  8. Impaler[WrG]

    Impaler[WrG] Civ4:Col UI programmer

    Joined:
    Dec 5, 2005
    Messages:
    1,750
    Location:
    Vallejo, California
    Wicked :goodjob:

    I'm looking forward to contributing my un-used cycles to beefing up the AI's. Might I recomend that "Team Firaxis" be the name for the default game AI and that it is always sticked to the top of the list so it can be easily useded as a standard for guaging the overall improvment in the AI.
     
  9. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
    Good idea. I'll implement that.

    I still can't get SC's event manager to work when I place it in my Program Files directory which is a pain - especially with the logging that I have to do. I'll have to ask people to stick it in the My Documents folder.
     
  10. The Great Apple

    The Great Apple Big Cheese

    Joined:
    Mar 24, 2002
    Messages:
    3,361
    Location:
    Oxford, England
  11. Impaler[WrG]

    Impaler[WrG] Civ4:Col UI programmer

    Joined:
    Dec 5, 2005
    Messages:
    1,750
    Location:
    Vallejo, California
    If you havent already, read this paper on the NERO evolving nural network.
    http://nn.cs.utexas.edu/downloads/papers/stanley.ieeetec05.pdf
    Many good principles are elaborated on, the genetic encoding of the Nural network looked very interesting and the concept of "total population fitness" could also be key to modularizing the AI as I had sugjested.

    Their code is also avalible for download and could probably be put directly into the SDK which might also have the advantage of speeding things up as it would reduce Python calls, the current system only changes weights, but perhaps we could even do away with Firaxis code and use the dynamic nural nets.
     
  12. Craterus22

    Craterus22 Chieftain

    Joined:
    Oct 7, 2001
    Messages:
    689
    This may be off topic now (though it wouldn't have been if I was here to post for the first page)...

    Concerning Ai target priorities during war:
    Would it be possible for the AI to target an enemy city based (or at least have it as a higher factor) on the value of attacker culture (either in the enemy square or surrounding squares)?

    If above a certain threshold value this could allow the ai to attack multiple targets and/or keep the war close to there border to increase the likelyhood of second wavve forces reaching the target to be of use.

    While not necessarily helpful for long distance wars - it could be of use in border squirmish wars
     

Share This Page