Kev Adsett
A programming portfolio


24 October 2013

This little canvas experiment was the result of a few friends setting up a 2 week game-jam with the theme of "Genetics". I thought this was a great opportunity to dust of my genetic algorithm skills and try and evolve some little AI guys to become better at finding a ball.

First off, I have to say the experiment didn't work - even after running the programm for three hundred generations the poor little guys were still squirming their way around the screen, entirely oblivious to the red ball sat right there...

That aside, I really enjoyed writing this, as GAs are something that really excite me as a programmer - the idea of behaviour emerging that I didn't explicitly code myself - that's pretty cool.

My initial idea was to have a species of seekers and one species of blockers, who would co-evolve in a sort of cat and mouse scenario, but the scope of that ended up being way to big for two week's work! Instead I focussed on getting these colourful little worms up and running (or slithering) and trying to find the ball.

The rough idea was that an initially random population are produced, and the first two members of the population to randomly touch the ball become the parents of the next generation, whereby everyone is then killed (brutal I know) and a new population made of the previous two parent's children is spawned. Lather, rinse, repeat. Obviously it gets pretty incestuous from generation 2 onwards, but hey ho.

I tried a variety of techniques to actually get the worms tails to correctly follow their movement (you can see a bunch of attempts as different branches on the github).

Finally, as I was getting bogged down in physics code (yuck!) I opted for the simplest 'speed based' movement, which does have the unforunate side-effect of slower worms looking like they have shorter tails, but actually it's just that the tails have caught up with the head!

The results are pretty hypnotic even if the worms don't get any better at finding the ball.