|
• cs bots using a ga
ixi,
I don't know how far you are into your project, but here is my first impressions. Pretend like we are playing cs_assault, and you and I are on the terrorist team with a bunch of humans. On the ct team, trying to infiltrate the warehouse are a team of bots. You want to evolve the best behavior for the team, so do it like a team of humans would. Probably what will happen is that human ct's would buy a variety of weapons and attack from a variety of directions. Assuming a constant level of skill amongst the humans (all bots have the same basic ai to keep it simple) the humans with the best strategy (preferred weapon, attack location, and attack team size) will be the most successful, and later, the other humans would try to take advantage of the successful strategies by mimmicking them.
Encode these strategies into a genotype. For example, we can list traits like:
1 - 'I like to be attacking with _X_ number of people, if the group gets bigger than this, I will go off on my own'
2 - 'I will camp for _X * 10_ number of seconds before attacking'
3 - 'I will buy _X_ gun if I have the money'
4 - 'I will attack route _X_ first.'
5 - 'If _X_ teamates die before I do, I will go into camp mode.'
This is probably a good number of characteristics for each bot. The bots can start with random values for each of these characteristics for the beginning of the map. After each round, you can mate the most successful bots to create the strategys that the bots will use next round. This reflects how actual human matches work!
Ok, so to encode these traits (AKA chromosomes), we can say that each trait has 8 possibilities. So for this, we need 3 bits per trait. All the information describing a bot's strategy will look like this:
1 2 3 4 5 = corresponding trait
101 001 111 100 101 = gene for a bot
This is the genotype for each bot. Lets convert this binary gene into a bot's strategy.
1 => 101 = 5, plug 5 into the first trait:
1 - 'I like to be attacking with _5_ number of people, if the group gets bigger than this, I will go off on my own.'
2 => 001 = 1, plug 1 into the second trait (1 * 10):
2 - 'I will camp for 10 number of seconds before attacking.'
3 => 111 = 7, plug 7 into the third trait:
3 - 'I will buy gun number 7 if I have the money' (maybe colt, or awp, however you number them)
etc...
When the round ends we want to mate the most successful bots from the previous round to make the new bots. A review for how you might mate your bots:
example: a bot with a gene of 101 001 111 100 101 might mate with another bot with a gene of 110 001 101 001 101
101 001 111 100 101 = parent 1
110 001 101 001 101 = parent 2
___ 001 ___ ___ 101 = traits that both parents share
so except in the case of mutation or crossover, the traits that the parents share should be reflected in the child. To fill in the blanks for the child, you should flip a coin for each trait to decide which parent to take the trait from. I don't recommend flipping a coin for each bit, it works much better to do it by trait. Pick another pair of parents to mate and create another child for the next generation until all the bots have been created for the team.
A tip that you may already know for selecting parents is called 'tournament' mating. You randomly select 3 parent candidates, and let the best 2 mate. You can use more than 3 if you want. I pick the parent candidates at random, but skew my pick towards the most fit parents with a function like this:
candidate = oldPopulation[ random()^2 ];
This only works if the population is sorted from most fit at the beginning of the array, to least fit and the end of the array. (I recommend a good quicksort algorithm for this).
One thing you should note is that the more traits you have for your genetic algorithm, the longer it takes to see improvements in the population. This is because many traits depend on each other. In the example, the camping trait will only work well if the bot tends to select a gun that works well for camping. The favorite attack place trait also depends on the number of teamates the bot likes to be around, etc. The more traits you have, the longer it will take for the dominating strategies to emerge and be used in your population.
I have an applet on the internet for playing around with genetic algorithms that you can use to get a feel for what population sizes work with what problems, etc. http://www.missouri.edu/~clj4hf/TravellingApplet.html
This may help tune your intuitions to what works well with genetic algorithms, but writing your own will help better!
I hope this helps =)
tr0p
|