Fang Talks

Do the impossible, see the invisible

I mailed myself this Codegolf challenge to maybe try out for casual learning sometime, and figured I might as well say something about it.

Genetic algorithms, or their parent category evolutionary algorithms, for that matter, are the most radical thing since evolution itself. Before we dive into that though, let me explain the premise of the exercise I linked. A grid (field) is randomly generated and contains walls, traps, and regular ol’ floor tiles. Your subjects (mice) will have to traverse this grid from left to right, and get to the rightmost tile to score a point. Additionally, the further to the right a subject is located, the more likely it is the next subject that spawns will inherit part of its genes. Subjects can only see a 5×5 part of the grid around their current location, and can not in any way interact with other subjects. The algorithm with the highest score after x generations wins.

So what’s the deal here? The fact that the better a subject does, the more likely it is to pass on its genes is key here. Does that sound somewhat familiar? Evolution theory, that’s right. The idea here is that, by starting with random genes (guessing patterns for what the path ahead is, in this context), and then letting subjects with those genes loose in a “only the best can survive for long” environment, optimal genes will eventually emerge.

Some of you may have seen this video, originally published in 1994. It does something similar, except for three-dimensional movement in an environment and other actions, with “real” physics included in the simulations. Look at all the things that evolved from it. Again, look familiar, don’t they?

“My code… it’s alive!”
~ Fang


  • 24/01/2015 (2:39 AM)

    There are a number of different games like that out there. Though most of the ones I’ve played don’t have some kind of major goal outside of “Last as long as possible”. It’s neat to see there’s one where there’s an actual goal. I might have to give it a go.

Post a comment

Your email will stay hidden, required field are marked with a *.

Experimental anti-spam. You only have to do this once. (Hint: it's "Fang")