Back to Home

JavaScript car racing evolution

Box2d · Box Car 2D · Genetic Cars · genetic algorithm · evolution

JavaScript car racing evolution

    You may have seen the game Box Car 2D - car racing cars generated using the genetic algorithm. The game runs on the Flash platform and uses the box2d physics engine. One can watch for hours on how quite decent racing cars develop out of formless freaks in a few dozen generations. The game has been around for several years, and its fans are competing in breeding new “breeds” of cars on different types of tracks. Recently, a clone of this game called Genetic Cars , written in HTML5 and JavaScript, has appeared on the web . Although there is still much missing (for example, a typewriter editor), some things are much better done than in the original. For example, it is possible to observe the arrival of all cars simultaneously. And most importantly - you can poke around in the source!



    The JavaScript version was written from scratch by Rafael Matsunaga . In addition to the open source and the simultaneous arrival of all the machines in its version, it is possible to disable rendering - in this case, only physics is calculated, and evolution is several times faster. Unlike Box Car D2, the behavior of cars is not completely determined - the same machine on the same track can show slightly different results, so sometimes a new generation shows worse results than the previous one. However, the trace generated pseudo-randomly based on the string that the user can specify is always the same for the same string, so there is a chance to compete.

    Genetic Cars also has slightly less initial genetic diversity — all cars have two wheels. In total, the genome of the car consists of 14 genes - much less than in Box Car 2D. 8 of them regulate the length of each vertex of the "body", and 3 on each wheel - location, size and weight.

    While I was writing this article, in the background window of Chromium on the track generated on the basis of the string “habrahabr.ru” three dozen generations of cars managed to compete. The record result is 178.87 meters.

    Read Next