"so I says to Mable..."
 

Box Car 2D

March 12, 2011

The newest geekery for me is Box Car 2D a game you don't really play. Actually more than a game it's a demonstration of pretty good coding. The site describes the game as a "Genetic Algorithm Car Evolution Using Box2D Physics". The objective is simple, have you car travel as far as possible. However, you don't drive the car, instead you watch it evolve and can influence it in a number of ways.

The game uses is an example of a genetic algorithm to create the cars. The body of the car is made up of eight different vectors with differing magnitudes and angles. These vectors are then joined by triangles to make the car. You can decide whether your car should have anywhere from one to eight wheels of differing radii, each of which can be attached to one of the vectors that makes up the body. Each of these variables [the magnitude and angle for each of the vectors, the number of wheels, and the wheel radius and what vector it's attached to] becomes a "gene" and all together it makes up the chromosome. After a generation, which consists of X number of cars all running the course, parents are paired up and produce offspring. This passing on of genes is made helpful through color coding, therefore if one parent is all red and the other is all blue, you can see which parts come from which parent in the child. Lastly there is also a mutation rate you can control, this mutation will represents the likelihood that one of the genes gets a random value rather than being inherited from a parent.

There is a car designer that will allow you to create a car you can then use as the starting parent if you don't want to start with a random population. The designer is a bit hard to use because all the toggles are in terms of their values so the design isn't achieved by drawing our your car but by selecting magnitudes and angles.

There are different tracks for your car offspring to tackle. Some have a clear goal, like speedway, while others have a specific track feature, like the peak. The basic track doesn't seem to have any goal or specific feature and is the most frustrating to "beat".

During the week I tried to beat the normal track by inputting what I thought would be the best initial car, letting it run for some time and then taking the best performing car once performance plateaus and tweaking it in the designer.

My Best Initial Design
The initial design was based on the observation that cars with a big wheel in front and a small wheel behind tend to do pretty good at both taking a high fall and getting over peaks. In the higher distances of the default track [yes I played this thing enough to know the features of the track] you need good torque to climb up inclines so starting off with 91 torque seemed like a good start. After some number of generations the best I could get out of this initial design was a car that had a high score of 1033.8.

Best Car