Survival, the game

Download Survival
Download Source code to Survival

During the summer of 2004, after receiving my bachelor's degree, I decided to write a game. I was enthralled by genetic algorithms and really wanted to do something that would let me explore them further. Eventually I decided on what I call Survival. You can download the game and it's source code using the links above.

In Survival their are two species of bugs. I call them them Turtles ( the player controlled species ), and the Roaches ( the pc species ). I call them that because that's what they look like. When the game begins there is only a single member of each species at opposite corners of the map. Each bug only has a life span of 3 minutes. The object of the game is to make sure your species survives and that the other species doesn't.

You may be wondering how you are supposed to do this when all bugs have the same life span. Well, you have to reproduce. When you do reproduce, you behavior is passed on to your children. When the bug that you control dies, you will gain control of your newest descendant. If you are constantly reproducing, your children will constantly reproduce. Once you have a nice population you can begin to seek out and try to kill members of the other species. Hint: As soon as the game begins, hit R ( reproduce ).

There is also an observe mode, where 8 members of each species are randomly placed on the map and allowed to run wild. I've had a lot of fun just watching the kinds of behavior that will emerge from the simple runs placed in the game.

Environment Variables: ( top right in light blue )
Comp:The number of Roaches on the map
Player:The number of Turtles on the map
Fertility Rate:The global rate of fertility that a bug needs in order to reproduce.

Bug Variables:( Lower right in yellow )
State:The current state that the bug is in ( Eating, Drinking, Fighting, Reproducing, Resting )
Age:The age of the bug in seconds ( it will die when this reaches 120 )
Fertility:How fertile the bug is, more on this below.
Hunger:When this reaches 255 the bug will begin to age faster.
Thirst:When this reaches 255 the bug will begin to age faster.
Energy:When this reaches zero, the bug will begin to age faster. You have to have 128 to reproduce.

Controls:
Mouse movement:Turns the bug left or right
Mouse Left Click:Moves the bug forward
R:Reproduce
E:Eat ( increases fertility )
D:Drink ( increases fertility )
F:Fight ( decreases the victims energy )

The theory behind Survival is this: a genetic algorithm is an algorithm that can change over time based on some evaulation function. In this case, that evaluation function is your actions. The game watches what you do and when you do it and modifies the code running the bug brains accordingly. If you reproduce a lot, then so will your children. If you are constantly stopping for a bite to eat, so will your children.

While working on this I learned a few things about genetic algorithms. First off, if a trait doesn't directly affect the rate of survival, it will be ignored and unused. By survival I mean survival of the species, which means reproduction. Originally, eating and drinking restored energy, which could also be done much easier through resting. All the bugs would do was rest and then reproduce, rest and reproduce. Also, I didn't have a fertility rate at first. This, combined with the rest and reproduction behaviors that always emerged would cause the program to run out of control. The bugs would number in the hundreds for each species and they wouldn't even fight each other. I added the fertility rate, and made eating, drinking, and later fighting, affect the fertility rate. Finally the bugs started to exhibit more diverse behavior.