Genetic AI Project

The Great Apple

Big Cheese
Joined
Mar 24, 2002
Messages
3,361
Location
Oxford, England
TGA's Genetic AI v0.33
Link to mod download

Current best AI: Little Bugger by Gunner (Fitness: 4870)

I've been beavering away for the past few weeks getting this project on the road, and now I think it's just about time to ask for some help off the community.

NOTE: This mod is currently only for vanilla Civ 4. I will add Warlords support after a few patches.

What it is:
A genetic AI is basically an AI which will learn and grow over time. The idea is that the AIs will play games, with their results logged, and the best AIs of the batch will then go on to be the base for the next set of AIs. I have written a script that will pit AIs against each other, recording the results, which I have another script which can analyse and build new AIs with. Unfortunetly this process is very time consuming and this is (hopefully) where you come in.

What I need:
I need time. On my AMD Sempron 2200+ a normal game between 6 AIs takes roughly one hour. Given the random elements in a Civ game, one game isn't nearly enough to judge a particular AI with, so each AI must be played many times to judge it's fitness. The more games the better data, but the more time consuming. At the moment I'm running 10 games per AI. A quick bit of maths will tell you that doing 6 AIs for 10 games each will take about 10 hours on my computer. This is far to slow to get meaningful results any time soon.

How to help:
You can help in quite a few ways.

The first is to download the mod at the bottom of this post, install it, and just play as normal. You'll get a slightly more unpredictable AI, and it'll take ages, but it'll show the AI's performances much more effectively. The AI will not reload after a save-game, so this option isn't really very plausable.

The second is to download the mod at the bottom of this post, install it, and run it autominously in the background while you are either away from your computer, or doing things which aren't performance intensive. I have included a setting which will cause the AI to play indefinately against itself until you tell it to stop. This will provide much much more results then the first method.

The third is to help me program new algorithms for the AI to test. These algorithms will be either enabled or disbaled based on the AI, and hopefully will generate significant improvements. To help with this I suggest you apply to join the CCP forum where I plan to hold discussions on this. To do this go to this page.

The bad news:
Either way you run it there are a few requests/limitations. I've disabled almost all of the python events, as well as the python callbacks for performance reasons. This will mean that a rather large amount of mods won't work with this.

I'd also rather people not play with too obscure rules. While I would suggest you have it going on your standard settings (which, incidently, will push the AI to become better at your standard settings), I think some results would be counter-productive (only diplomatic victory enabled... or something).

Installation and Running:
An important thing here: This mod will only work correctly if installed in the My Documents mod folder (My Documents/My Games/SMC4/Mods). Why? I think it's probably because I can't understand how SimCutie's event manager works... either that or it doesn't work :p. I will work on getting it to work in the install directory for the next version. Simply unpack the contents of the .zip there. Please don't change the folder name of the mod - this will cause errors with file reading/writing. You will also need some AI data files which are posted in the following post (with additional instructions).

I've replaced the Dawn of Man screen with an AI selecter screen. This screen allows you to view stats of the AI's currently in your AI store, as well as allowing you to swap them in and out of the game (upon pressing continue having done this there will be lag while it re-organises things). The firaxis default AI should be in your store named "Firaxis Team". This should let the progress of the new AIs be judged.

To get the AI's to auto-play. The keyboard CTRL-SHIFT-X sets them off. The game will restart as soon as one team wins, and continue to play with a fresh set of AIs. On completion of each game the AI data will be saved, and you can pick up from this data with a new game whenever you like.

Known issues:
Sometimes when exiting automation mode the game gets stuck with a "Waiting for other Civilizations" message. To fix this, enable debug mode (CTRL-Z with cheat code set), and cycle through the players (CTRL-ALT-Z) until you get to the working one. Thanks to suspendinlight for this fix.

If you come up with any crashing problems - please see this post for information on how to report it to me.

Credits:
The CCP team - I used the project as a base as it already had quite a few of the things I needed included within it.
jdog5000 - his autoplay code is the core to the code which restarts each game upon completion.

Link to mod download

Spoiler changelog :

v0.33
*Fixed slow memory leak (about 100k over 12 hours)
*Fixed autosave crash.

v0.32
*Fixed a bug where the alternative AI algorithms weren't being loaded correctly on game restart.
*Full load/save compatability.
*Performance enhancments (~ 0-1s a turn, depending on settings).

v0.31
*Big algorithm involving city specialization added
*AI names not displayed on scores instead of leader names.

v0.30
*Added a few AI algorithms controlled by genetics
*Removed some AI variables that shouldn't have been changing
*Upgraded method for scoring cultural victories
*Many more misc. internal tweaks

v0.29
*Changed the way that cultural ratings for the AI are worked out
*Updated file format
*Number of AIs per file increased to 24.
*Minor tweaks

v0.285
*Fixed crash on meeting another unit.

v0.28
*Impoved logic of data set completion popup
*Fixed UN - it now works.
*Hopefully fixed a crash on load

v0.27
*Untracking AIs now works correctly
*Ranks now shown starting at 1 (instead of 0)
*Fixed a load script bug
*New data format.

v0.26
*Several performance tweaks
*No more setting randomization
*Improved restart script - barbs now reinitiate correctly, contacts and vision are reset correctly.
*No more CTD on incorrect AI load. Instead it tells you that you have loaded them incorrectly.

v0.25
*Fixed a bug where AI's getting wiped out would cause a python errror.

v0.24
*Fixed a bug where one in three AIs would not build any units.
*Games needed for a complete test reduced from 10 to 8. As some sets are potentially being run twice this will increase speed.

v0.23
*Fixed a loading bug meaning old files could not be loaded.

v0.22
*Fixed a big bug not causing results to be recorded!

v0.21
* Fixed a crash when selecting more then 7 players.
 
Attached are 5 AI Data sets. Try to download the one with least downloads to prevent duplicate work being done - while it's not a waste of time, it's perhaps not as efficient as it could be. I'll try and keep new ones popping up often. Simply drop the text file into the GeneticAI mod folder (not into Assets) before running the mod. You only need one of these data sets to run the test.


These datasets will only work on version 0.31 onward. Do not try to use with an old version.
 

Attachments

  • AIData62.txt
    119 KB · Views: 398
  • AIData63.txt
    119.4 KB · Views: 206
  • AIData64.txt
    119 KB · Views: 218
  • AIData65.txt
    119.1 KB · Views: 277
  • AIData77.txt
    119 KB · Views: 259
And 5 more...
 

Attachments

  • AIData66.txt
    119 KB · Views: 256
  • AIData67.txt
    119.1 KB · Views: 186
  • AIData72.txt
    119 KB · Views: 198
  • AIData74.txt
    119.1 KB · Views: 204
  • AIData91.txt
    381.8 KB · Views: 278
These 5 datasets have twice as many AIs as the other 10. For people who get through them quickly.
 

Attachments

  • AIData82.txt
    238 KB · Views: 225
  • AIData83.txt
    238.1 KB · Views: 190
  • AIData85.txt
    238 KB · Views: 210
  • AIData86.txt
    238 KB · Views: 191
  • AIData87.txt
    238.1 KB · Views: 212
Wow what an project. Sounds too good to be true. I have studied AI for years. How many generation does your AI have in the zip?

You must have simplified a lot of imputs/outputs.
 
Each attached zip is 20 AIs (I figure about 30 hours work). Every time I need a new bunch I'll run the AI filter on my computer which will analyse & sort out all the AIs which I have recieved back (or done myself). I'm going to be working some more on refining that while I wait for some results to get back.

In other words the generation system isn't really generations as such, much closer like a free flow of births and deaths. If this gets big enough I'll probably set up a web system to do all this for me.

I, unfortunetly, have very little experience with this sort of thing, so I have no idea how long it will take to produce meaningful results. Hopefully we'll see...

As soon as I see the zips get one view I'll replace them with a fresh one. Might get one or two duplicate sets, but this just means they're more accurate, as I can combine before filtering.
 
Definitly a sig worthy mod. :goodjob:

Potentially Stupid question though, but do we PM you the results, or does it automatically send the results or what? I didn't see any mention of what to do after you install the mod and the AIs.
 
A good question. You can either upload it on this thread (might get a bit messy) or email it to me (a prompt should come up when you're done).

If lots of people do get involved I'll see if I can sort out some sort of auto-upload system.
 
suspendinlight said:
Sounds really interesting. I'll give set 1 a few runs, but my first attempt crashed when loading the map.
Are you sure you had the text file in the right place? It shouldn't do a hard crash, but this is the only cause I can think of off the top of my head. It should be in the Genetic AI root folder (with the .ini file).
 
suspendinlight said:
There's some kind of problem with AI data set 1. I switched over to data set 2 and I have no crashes now.
Argh, forget it...it's not the data set. It seems to have to do with the number of players in the game. If I use more than the default (more than 7 on a standard size map), it crashes.
 
suspendinlight said:
Argh, forget it...it's not the data set. It seems to have to do with the number of players in the game. If I use more than the default (more than 7 on a standard size map), it crashes.
That still shouldn't be a problem, unless you use more then 18, which isn't possible.

I'll run some tests. Thanks for the info.

EDIT: You are right. Strange, I'll try and figure out what's wrong.

Okies, think I've got it. I forgot to compile the final source code, going to compile and upload a fix in ~ 10 mins.
 
I tried with set 9 and 8, both windowserror-crashed after I tried to load the mod (after the splash screen, before the loading dialogue). The txt for 9 says "aidata9" instead of 8's "aidata", don't know if that means anything. The files are in the root folder, sitting courteously adjacent to the assets folder for the mod.

Edit: Belay that, I'm ******ed and don't know how to read instructions all the way through.
Edit 2: Definitely ignore that whole thing. It works fine, AI selection and all.
Edit 3: Good gravy, turn times are long. I will have to run one of these overnight or something. I'll send results tomorrow if I remember to.
 
Fixed. You should now be able to have up to 18 players.

The build that was in was a test build which I was using to test an alternative way of doing things which I was going to be using for the next release.... looks like it didn't work too well. Sorry about that.

For anybody who has download v0.2 there is now v0.21 in the main post. Instructions are exactly the same.
 
GRM7584 said:
Edit 3: Good gravy, turn times are long. I will have to run one of these overnight or something. I'll send results tomorrow if I remember to.
To be honest, I doubt you'll have results tomorrow. As I mentioned before I've found completing results for a single AI takes over an hour. Completing each of these sets I'm expecting to take about 30 hours.

It'll go a bit quicker if you run them on smaller maps, but then you might end up with a duel-demon! Also I think speed will be largely dependant on processor speed rather then anything else.

If you have a 4GHz thingy running on tiny maps you might just about do it overnight.
 
I'm intrigued :)

Your mod is running in the background, so please allow me to ask you a question: in what exactly are the different AIs different? I suppose it is mostly XML values, namely the AIWeights for different buildings/units, but is there also something else?
 
Top Bottom