Natural Selection

A few days ago I tweeted about boxcar2d.com, and since nobody said HOLY CRAP THAT’S THE MOST AMAZING THING EVER, I assume none of you went to look at it. Or maybe I’m just overexcited. The website is a program designed to simulate natural selection and evolution, using a track and a vast population of little cars. The program uses a physics engine called box2d as its base, so the cars have weight and size and speed as defined by a simple list of traits, and the goal is to get as far along the track as possible. the traits for each generation’s best cars are used to create the next generation, and thus, over time, the cars become better at navigating the track, and can go much farther.

What I love about this program is the wonderful way it emulates evolution as a combination of natural selection and mutation; it’s the most perfect illustration of how those concepts work together that I’ve ever seen, and it almost makes me want to be a biology teacher just so I can use it in class. The natural selection part is obvious: cars that perform better on a certain track will survive to pass on their traits to the next generation, thus providing continuity over time. If that’s all you had, though, the population would stagnate–eventually every car would be as good as the best car, but no better. Mutation guarantees that every now and then a new trait is introduced into the gene pool, and if it’s valuable it gets carried on, and if it’s not it disappears. Thus the species actually improves over time.

Let’s look at an example. The tracks the program uses are essentially a series of obstacles: Big Air is a set of progressively harder jumps, The Gap is a set of progressively wider potholes, Hang Ten is a set of progressively steeper hills, and so on. My favorite is Big Air, because it’s thrilling to watch the cars figure out how to clear the longer jumps, but for this example I’m going to use Blockhead, a straight, flat track blocked by a set of progressively bigger walls made of stacked bricks. Moving along the track requires knocking the walls down, moving over the fallen bricks, and so on.

Each population starts with a generation of completely random traits–they can be any shape, with any number of wheels attached to any number of points on the car. Most of these cars aren’t even recognizable as cars, and indeed most of them can’t even move; think of them as the single-celled organisms in the primordial soup. Some of my first-generation cars could actually move forward, usually on one wheel, either pushing their body ahead of them or pulling it behind them. Of these, most of them could knock down the first wall or two, but had trouble going any farther. This continued for a generation or two until one of the one-wheeled cars showed up with a wedge-shaped body, like the prow on the front of a train. This proved incredibly useful in plowing through the first several walls, and the car got farther along the track than any car before it. All of a sudden the next generation was filled with variants of this wedge, some more successful than others: one wedge was lower to the ground, digging under the blocks but eventually getting too buried to move; another wedge was so small that the wheel ended up flipping it around, using it like a mace, which knocked over walls with no problem but couldn’t get past the rubble. Over several generations the wedge refined itself into a blade-like triangle capable of plowing under the walls and knocking them over its back, and then one of these cars grew a second wheel. This proved much more useful than one, with much better ability to climb over piles of fallen blocks, and within a couple of generations the population was filled with sleek, two-wheeled blades that rammed the blocks at full speed and raced over the fallen debris. These cars proved useless against the heavier walls until another mutation showed up; many of the cars had developed third wheels here and there, sometimes giving them extra speed or stability, but the winning combination was a third wheel perched on a small spike in the front, jutting forward like a buzz saw, which knocked down all the walls before the main body of the car even got there, preparing the way for the two main wheels to just crawl over the wreckage. With this new adaptation the cars could travel much farther than ever before.

The previous paragraph evoked one of two reactions in you: either you were bored, and you’re still reading because your job is even more boring than this, or you were completely fascinated and already clicked the link at the top of the article. (I suppose technically there was a third group that got so bored they stopped reading altogether, but those people aren’t here anymore so I don’t have to talk to them. I can talk about them, though: what losers! How is this not the most fascinating thing you’ve ever seen?) One of the things you may have noticed in that description is the way the simulation demonstrates even the subtler aspects of evolution, such as increased complexity, increased efficiency, and the carrying on of key traits long after they become vestigial. The wedge-shaped bodies ceased to be important when the second wheel showed up, because the cars were no longer using them as plows to knock down walls, but they hung around anyway because there was no significant selection pressure to get rid of them. The human appendix is the same way: we don’t use it anymore, but people without one are pretty the same as people with one, so the trait never gets weeded out of the gene pool and we continue to produce babies with a useless extra organ.

When you try out the program, make sure to try it with several different tracks, because it’s fascinating to see which traits get selected for on which tracks. It’s also interesting to see which traits get selected for on every track: most cars will end up with two large wheels on the front and back, no matter which track you’re on, because it’s simply the most effective means of travel. This is another real-life analog: cows and crocodiles don’t share a lot of common ancestry, and thrive in very different environments, but they both have a head, body, tail, and four legs. Some shapes are just too efficient to not use.

To all of you science geeks: your welcome. To all the rest of you: thanks for reading anyway. I promise to talk about something more pertinent to your interests next time, probably a movie comparison between The Social Network and Jumper. I know that sounds weird, but seriously, it’s really interesting.

10 Responses to “Natural Selection”

  1. Brad Wheeler says:

    Dan, that website blew my mind. I probably spent a good hour yesterday off and on just watching my little cars evolve. I don’t know if this happened to you, but I got attached to specific cars and started hoping that they did well enough to survive.

    I also found the program interesting from a theological perspective – you could consider designing your own cars to be “creationism,” if you will, or “predestination,” but it was much less satisfying than watching them make it on their own. I’m not exactly sure what this means, if anything, but my mind went there right away.

    And I didn’t manage to get 3200 words yesterday, though that wasn’t the cars’ fault.

  2. Juliana says:

    Actually, I spent at least an hour completed hypnotized by the evolving lines and tires. I totally forgot where I’d found the link, though, until you posted this. I even threw the link on Facebook for others to enjoy! :)

  3. BC Woods says:

    http://fantasticcontraption.com/

    I was reminded greatly of this game, where you have to design machines to conquer certain obstacles. After playing this, you get an appreciation of how powerful evolution can be where design will emerge out of chaos. Conscious design is so much harder.

  4. Ben says:

    This is the worst thing that has ever happened to me! Haha. I ran across this post at about 10:30pm last night, right before I was headed to bed. I ended up staying awake until 2:30am watching my cars evolve. I let it run overnight, and I’m on generation 48. The cars aren’t getting significantly better. In fact, from the graph I can see that at some point during the night they were doing better than they are now.

    Brad, the same thing happened to me. I got really attached to certain cars, almost like they were my kids! And I felt bad for the poor deformed things that couldn’t even move. I kept thinking of the dragons from Robin Hobbs’ Dragon Keeper book.

  5. Jace says:

    The website sounds amazing. I almost wish I used Twitter so I could hve found out about it sooner.

    I’m in a fourth group: I read the article, found it fascinating, and I can’t look at it right now because I’m not sure my laptop will run it.

    But as soon as I can, I will check it out.

    I’m sure you feel so much better knowing that a random stranger is paying attention. :P

  6. Brent says:

    I confess I doubted the awesomeness the first time I saw your tweet, but this post convinced me to check it out. It really is a cool program. I’ve been having fun watching the cars evolve. Thanks for sharing!

  7. Sean - Texas says:

    So… confession time. Didn’t get any work done Friday because I was too busy watching cars evolve. Once I got home from work, I kept the hang time program running on my laptop all weekend long. Poor little things could never make it past the fourth jump, even at generation 200+, which was a little frustrating. The block program was much more satisfying. I kept the option up for them to have 8 wheels, and so you got some vehicles that looked vaguely similar to a sherman tank blasting through walls. I tried the other tasks too, but found they were not as satisfying as the block and jump programs. In all, I probably spent 24 hours or so tinkering with it.

    My wife thinks I’m nuts. My boss is probably pissed. I am happy.

  8. Jay Weight says:

    Thanks for the awesome site recommendation. I love your books by the way.

    I messed around a little with the cars and built a car that scored 777.7 on the random terrain. It didn’t do quite well on Big Air though, but it’s still fun to mess around and check out which cars will do best. I’ve found myself copying and pasting my car codes into word and plugging them into different terrains to make them better. I think I’m addicted…Thanks.

    jayweight.blogspot.com

  9. Jared says:

    One note: the appendix isn’t really vestigial, and until (geologically) recently never was, whether in humans or in other animals (even now, it’s only vestigial in the presence of high-quality medicine). It’s probably no more important than your tonsils, but the same can be said of several of your fingers and toes. It was initially though to be a remnant of the once-larger first-stage of the large colon, but 1) that doesn’t even make sense unless there were two first stages and the small intestine connected between them, and 2: http://www.sciencedaily.com/releases/2009/08/090820175901.htm ) we now know that many animals where that first stage is large ALSO have an appendix. Appendixes don’t ‘devolve’ from another part, but instead ‘split’ from a part to form a new part.

    So, appendix: not vestigial.

  10. Dot says:

    That’s the most amazing thing, and fascinating to leave running in the background.

Leave a Reply