You are watching a neural network piloting a spaceship in a Box2D simulation (and all that running in the browser). It evolved on its own within a genetic algorithm.

You can run the evolution live here:

Even though I've been playing around with genetic algorithms for some time now, they still fascinate me. That neural network wasn't trained or programmed; it doesn't know what its inputs mean; and it doesn't know what its outputs do. It has no assumptions on the ship's thruster setup, no sense of left or right, fast or slow, good or bad. It doesn't even know it's a ship. 

It just evolved in an environment which rewards – in this particular case – ramming into other ships. :) And still, it's way better at that than any human player could ever be (there are 7 thrusters on this ship that can be fired independently with different forces).

I wrote most of the code during two long train rides over the weekend.

Yesterday, I split the genetic algorithm runner into its own library, which is now available on pub as darwin. It automatically does things like niching, elitism, crossover, and mutation for you.

The reason I made this is – once again – the electronic gamebook hobby project of mine ( Here's the thing: I don't want the gamebook to be just a series of simple decisions that only slightly modify the story you're reading. I want your decisions to have realistic and meaningful impact on a simulated world. I want you to be able to solve things in unanticipated and surprising ways.

A big part of the gamebook will be commanding a huge cargo ship through space. Obviously, since this is a gamebook, it doesn't make sense for the player to take the controls directly (left, right, forward, back). But it makes sense to give commands to the ship, which are then carried out by the ship's artificial intelligence (or crew). Commands like evade, flank from left, turn towards ship, dock at station, or ram. All this in a physics simulation – so you can, for example, try docking at a station while being bombarded by a military ship, and there will be all the expected (but maybe also unexpected) consequences. (Maybe your devious plan is for the military ship to hit the station by mistake and thus incite a conflict?)

I, for one, would love to play such a gamebook. And, selfishly, that's why I'm making it.
Animated Photo
Shared publiclyView activity