Genetic Algorithms for Parameter Tuning
Recently the Tech Toolbox at GDC had a call for submissions, I saw it last year and thought it was a great session, with some great ideas. So I have been thinking, is there any useful stuff I have made for Yucatan which other people might find useful?
After 30 failed attempts I have a car that can drive up a hill. Solution? Stick a rocket on the back. pic.twitter.com/CJfUrvE0Pl— Joe Bain (@oh_cripes) December 17, 2015
I have shown a few people my hill climbing test and my handling tests. I used these to tune the parameters on the car in Yucatan. It's quite fun to watch all the little cars run around and fall over, but also I found the approach I worked quite well and, based on the reactions I got, seemed quite novel. What I had been doing was very similar to a genetic algorithm - only I had been doing it manually, but what if I could automate the process? I spent yesterday and today putting together a proof-of-concept, and as you can see in the video below, it works! I plan to tidy this up now and when that's done I'll offer it as an open source asset.
To give a basic overview of how the plugin works here is what I did to create the video. I first created a copy of my car control code which has most of the same parameters, but it drives itself - in this case, just straight forward. Then I added the car to a simple scene which is just a flat plane - with the car's default parameters, it slides backwards. Then I added the GA controller, set the original car as the control, and entered the names of the properties I wanted the GA to tune. I also wrote a simple fitness function for the test, it just uses the Y coordinate, i.e. the height traveled up the hill, to score the cars. What you can see in the video is the algorithm running - each generation, the best performing car is chosen, cloned, and randomly mutated. And we end up with a bunch of cars racing up the hill!
Check back here in the coming weeks for the source code, or follow me on GitHub.