AiGameDev.com
Welcome to your new online hub for Game AI!

“Join the official #gameai IRC channel on irc.freenode.net for discussion about AI in games!” – Alex

Are Evolutionary Algorithms Suitable for Building AI in Games?

Alex J. Champandard

Last week’s developer discussion covered a controversial topic: the applicability of computational intelligence techniques in games, specifically neural networks. This week, the topic is genetic algorithms (GA) and evolutionary strategies.

Remember, you can win an AiGameDev.com T-Shirt for posting interesting comments this month! Click here to join in the discussion.

Evolutionary algorithms (EA) fall into the category of general optimization strategies, which can be used to find approximate solutions to problems given a measure of fitness. Approaches based on artificial evolution rarely perform as well as specific optimization techniques on known problems, but they tend to provide satisfactory solutions generally for reasonably-sized problems.

Modern game developers certainly uses specific optimization techniques heavily, in particular for character animation, evolutionary algorithms still haven’t found a regular place in the development process — including for game AI.

  • Are there simply too few problems in games for GA/EA to become widely applied?

  • Do you think applying GA/EA in game design and development requires a specific skillset?

  • Is the evolutionary approach less useful than specific optimization techniques that are already used?

Certainly, the independent game development scene seems less reluctant to apply EA/GA into gameplay and AI…

Be sure to contribute to the discussion by posting a comment below!


Bookmark and Share

Comments

Comment on this article. | Show full forum thread.


by Mithrandir 21.November 2007
I believe that there are yet too few problems in games that require those techniques. It may seem from that that this approach is not so useful. Moreover, this approach is hard to code so there are few those who use it. However, this can't be neglected in more complex AI games. Take for example the game of Go. I am working now on a different AI using neural networks and genetic algorithms. I believe that this may be a good solution, but it will take at least a year until I'll have finished this.

by Serge 21.November 2007
I think that evolutionary algorithm (GA/GP specifically) are not suitable for "real time" control of the game, due to their huge CPU resource consumption, but they could be useful for off-line, behind the scene AI optimization or even bulding. In fact I have tried create genetically evolved AI for multiagent turn-based system on the grid I was something like overgrown "programmable" cellular automata - capable of consuming energy pulses and using internal structure converting them into attack pules. The internal structure - several triggers and converters - was evolving. The results were ambiguous - I *think* I had seen improvement in effectiveness of evolved agents. But I'm not completely sure, and the rate of improvement (number of replicated agents after 100 turns in duel with other) was very slow - like 2-3% per 24 hours of 3Hhz CPU running.

by naz 21.November 2007
im a games development student in my final year at uni, im thinking of implementing a neural network ( for an autonomous game agent ) for obstacle avoidance - i may use them for other aspects too im not sure how simple/hard they will be to implement....

if any one can help with the understanding or coding of neural network of even point me to the relevant resources id be very grateful! lol



I think there are scenarios in games, certainly in the more complex games, where this sort of AI would certainly be beneficial and would result in much better gameplay. Im sure other gamers, like myself, have grown a little bored of the predictable AI that is produced using tradional FSM and the likes, although it has to be said that the tradional methods can be coded to cover just about any situation - which is probably why developers are reluctant to learn/introduce new unknown techniques.

True if these techniques are used in run-time they use much more resources than current techniques however the results would be very interesting - imagine an enemy that knows as much as you about the environment, and learns from its mistakes and from watching you + other npc play. At first it may keep running into your territory or put itself in your firing line but pretty soon it would learn not to and start avoiding such actions. I think this will pick up in the near future with the dual core cpu now fast becomming mainstream. Also as graphics cards are getting better there is less load on the cpu therby leaving more time to process the AI. Currently only 10% of available cpu time is used by the AI!!! if this was doubled imagine the results...

(its my first post - sorry about the length guys! )

naz

by Mithrandir 21.November 2007
I believe that one mistake that programmers do is to consider that using GA is only possible offline, behind the scene. I consider that a powerful AI needs a part of GA and NN during runtime in order to become performant and powerful. More on this later, I write this during a small break (stundent at university)

by Walker Lindley 21.November 2007
Someone above mentioned that GAs were difficult to write, but my experience has been the opposite. It may be more difficult with game-specific applications, but I'm using a GA in the research I'm working on and the first version of it took me a couple of days to write. I think GAs could definitely be used offline, but I think they could be used in-game, too. For instance, the monster AI in an MMO could be evolved over time. But instead of having the monsters fight each other to determine fitness, put them out in the real world and see how they do against players. You could then graduate the better AIs to higher-level zones so that you don't overwhelm lower-level players. This would be slow, of course, but I think the results could be pretty interesting.

by Zeroth 21.November 2007
Well, first of all, evolutionary algorithms do have a place, mainly when finding local/global optimums is an NP-complete problem. EA/GA are able to find effective solutions in much less than polynomial time.

However, and this is the caveat with any such silver bullets: it takes knowledge and creativity to properly build one. I would suggest that people should read any of Richard Dawkin's books on evolution, in particular "The Blind Watchmaker".

Thanks to that book, I actually have an understanding of some of the processes of how evolution works, and its easy to see how to apply them to EA/GA.

The first issue is that evolution in nature is a slow process, but not necessarily continual. It may or may not work in fits and starts. And for GA/EA's to work, you need to make hundreds, thousands of them, have them "compete" which is on the order of O(n) at least.

As well, multiple iterations of the same GA/EA will not produce the same solution due to the random mutation factor. Unless of course you seed your rng with a known number. ;)

Then there is the actual design of the dna strand. Do you make it so that there is a specific range and function for each "gene"? Or do you make it more deterministic? Those are both valid questions, with their own degree of difficulty and effort required.

In my view, GA/EA are an inefficient means by which to produce an AI due to their unpredictability, general lack of surprising changes, and difficulty to make a good GA/EA. For indie game devs, its simply too much effort, for too little of a result.

by Jose E. Rodriguez 21.November 2007
I think the problem with this approach and most GA/EA is that while the monster is in training the user experience is kind of awkward (sp?) (maybe unpredictable if you are using GA) since it takes too many iterations or training steps for your system to come up with something that would present a rich or interesting experience for the user. That I think is the main reasons why it is done offline.

Another problem that i see could arise from using such systems is that they can be susceptible to miss-training. Allowing users to cheat :P so care must be taken when deciding what to assimilate and what not to.

Speed is not such a problem with todays technology, new gfx cards coming up, dual core processors, the universal shader model etc, soon (if not already) there will be enough CPU cycles to spare in the AI systems.

Implementation isn't a problem ether since there are tons of free open source AI toolkits around the net for people to play with. That of course if you are lazy or cant be bothered to make your own.

I think for now a solution could be to some sort of experts system like Bayesian networks based on probabilistic data (not too hard to implement). That way you could allow each monster to have a specific behavior within his life time according to his own experiences (players he has fought etc.) and still have some control over the monsters reactions etc. Over time the seeds for the network could evolve based on gathered data.

Id like to hear what you guys think.

by Nik 23.November 2007
I am taking a GA/GP class this semester and have some experience with this. It is definitely not easy to get something that is both effective and resource-efficient in real-time.

But if it was in real-time, that would be ignoring the whole 'evolution' foundation of these methods. In a way, they are MEANT to take long in real life (forgetting modern genetics research for the moment).

I think that there are several very worthwhile offline uses for Evolutionary Algorithms in games, namely in terms of procedural content generation during loading periods between levels.

For example: evolving a population of enemies or other characters (represented in terms of specific 'personality'/emotional traits, physical features, behavioural characteristics, etc).

Although the basic models may be limited and pre-built to a large degree, you could use EAs to create a wide range of different 'masks' for these models.

I have also read a recent article that used EAs to evolve soccer strategies for AI opponents: http://www.gamasutra.com/view/feature/1901/using_genetic_programming_to_.php?page=3

So there is definitely a place of GAs in game development, particularly where there are no known optimal solutions to a particular problem.

by Rafael 23.November 2007
I have the same experience as Walker: it's very easy to implement GA.

And, contrary to some comments, I think it could be very useful in games, as we can see in Nero: http://nn.cs.utexas.edu/NERO/about.html
It's a kind of RTS game where the units evolve in real-time using genetic algorithms (combined with neural networks, resulting in the NEAT approach).

Again, agreeing with Walker, I think that evolving monsters in MMOG's would be very cool (both AI and appearance), and I have already a project on it.

Another approach would be to evolve entire stages/maps. The more difficult is it to the player to complete the stage -> more fitness it has (it's a form of competitive coevolution). So the difficult level would grow naturally.

by Teneo 01.December 2007
I was first exposed to a combination of NN and GA in some Quake 2 bots, called Neural Bots, created by Nicholas Chapman (who abandoned the project when he got hired by Crytek, who makes so very snazzy AI ;). I was just a high school student who loved to program at the time and running across it pretty much made up my mind on what I wanted to do for a career.

The project is 8 years old and abandoned, but the website is still up. It's pretty fun to tinker with the values and try to get a really killer bot AI working with it. I've played with this thing alot and only ever got 2 AI's that really gave me a run for my money out of hundreds of attempts of letting them evolve 20-100 thousand generations. My best results came when I broke down and learned the Q2 coding to edit how the inputs are entered by the game.

Here's a link to the site
http://homepages.paradise.net.nz/nickamy/neuralbot/nb_about.htm

by D?afar Sadik 10.June 2008
Hi, at the very beginning I'd like to apologise for my weak English. I can say that EA/GA may be used for creating interesting solutions for games. You may have probably heard of use for creating patterns or terrains. Another thing is to create optimized movements before putting it into game ( I implemented movements of arm playing with ball ). When you have movement data simply learn neural nets with them :) You may use here two kinds of nn: S.O.M. and B.P. N.N. First SOM used for choosing BPNN which is learned to solve proper movement kind.

Possibilities are endless ...


D?afar Sadik