Using genetic algorithms to 'train' my AI

Hi,

My name is Peter Norberg and I’ve previously written about my game AI in this thread: AI in a turn based strategy game. It’s been a while since my last update and due to this I thought it would be best to start a new thread. But there’s been a lot done on the AI and it’s now quite developed and able to do most of the needed actions as well as simple diplomacy.

Now I’ve just started to see if I can ‘train’ the AI by using genetic algorithms. I’m not sure if this will be a success or not. At my blog, Words from the Netherlords, I’ve described how I intend to do it and my intention is to write down my conclusions when I’m finished with it, good or bad…

Rising Empires uses an utility-based AI which depending on the sitiuation and its free resources can make multiple decisions each turn.

All thoughts on the subject are welcome!

Once you have a system that can develop good AI’s you can incorporate it into the game, have the AI learn with the Player and become better at defeating / defending against the Player as the game goes on.

The first results and comments on my trials have now been added to the blog. I’ve tried to improve the Human and Greenskin races and at least the Greenskins show some promising improvements. I intend to fine tune my algorithms a bit (I hope I remember to add the code in my next update) and try two of the other races as well.

This is very fun! :slight_smile:

Crap, this is gold. I probably will try a bit of my own spin of it. I didn’t have time to read the entire blog post, but the idea itself brought this to my head (aka, Idk if this is what you already did). You make the game, and have people play it. You make the enemy ai start with 2 actions. Attacking, and defending. They attack, and see how much damage occurred. The first time will be the baseline. That will be what they remember, and compare all other attacks to. Anyways, after that, they take damage while defending. Again, that will be a baseline. After that initial data, they will shake stuff up every generation. Like maybe spin before they attack, or whatever. But, here is the catch. If they die in a battle, and did not pass on their skill to the next generation, that skill will be lost. Similar to ‘Survival of the fittest.’ So, after about 40 generations, they will get more and more advanced in their attacks, and defenses. And the other catch, is once their current stats are 150% of the original data, they will be a new species, and that bar where it is a new species rises in that species. So the first division of species will be set at 150%. Next, 200%. Until it gets to the maximum attack range.

Thanks for giving me the idea! I might try this myself, but my hands are kind of full at the moment.
Keep up the good work! ;D

Thanks wesley.laferriere. Remember that you need to randomly test new skills and in what order to use them for the AI to develop. It might be that the spin before the attack won’t be effective and then it won’t be used, but it might also be that the spin is only effective in combination with another special attack and for that to evolve you must mutate randomly, i.e. test new crazy stuff. Most times it won’t be anything good but once in a while a new interesting attack will evolve.

I’ve completed the third part of my tests to see if I can improve my AI with the help of genetic algorithms. If you’re interested it can (as usual) be found at my blog. Training the Elf and Ende races didn’t give as good results as did the Greenskins…

Be careful with this adaptive AI, if it’s not flexible enough, it may find a suitable method that becomes repetitive to the player over time!
Try to keep the player from taking advantage of it, you don’t want the player to lose several times so the AI loses it’s good strategies so that the player can have an easy epic win to upload to youtube and brag.
Also if you decide to have the AI save results, make sure it doesn’t take a chunk of memory.

And be aware that having an adaptive AI means that players may have to become extremely adaptive, or may just brute-force their moves from a lack of it’s understanding- You can help this by using ‘inequalities’, choices that cannot be compared to each other, e.g. apple + orange.