There exist greeners (the ships) and greens (the food). When greeners are born, they have a given amount of health and an age of zero. As they live on, their health decreases at a fixed rate. If a greener is too close to the edge of the screen, the health decreases more rapidly. If a greener touches a green, it "eats" the green and its health goes up. When the health is zero, the greener dies.
Greeners can control their movement. They can adjust the direction in which they are pointing by any angle they wish. They can also accelerate in the direction they're pointing. The acceleration can be anything from minus infinity to plus infinity, and it's up to the greener to decide. There is a top speed limit though. If no acceleration is applied, the greener continues to move due to inertia. Greeners bounce off the edges of the screen. There is no angular inertia.
Greeners can sense very few things about their surroundings. The artificial intelligence gets the following information as inputs: ship's absolute speed, direction of motion relative to where the ship is pointing, relative distance to the nearest green, and an angle to that green relative to where the ship is pointing. That's it. Thus the greeners have no way of seeing the walls, each other, or greens other than the closest one.
I suppose this limits the behaviour they can learn to pretty much one single thing: eat the greens. However there is still scope for variation: they can learn to eat greens in different ways, better than others, or maybe not learn at all.
Each greener has a small neural network which gets the inputs described above. The network outputs the desired acceleration and change in angle. The weights and offsets in the network are represented as an array of floating point numbers. This array is the genome of a greener.
Reproduction and evolution
When two greeners are within a certain distance of each other (they must overlap by a few pixels) they may or may not reproduce. If they satisfy all conditions below, they will reproduce:
- Both are old enough (2 seconds)
- Both have at least 50% health
- Neither has reproduced in the last second
These conditions are in place to prevent exponential growth followed by a quick dying out of the entire population.
If greeners reproduce, three new ships appear. The parents' health is split among them (some extra health is thrown in to prevent them all dying too quickly after reproducing). The genomes of the children are spliced from the parents' genomes by taking x% of one parent's genome and 100-x% of the other one, where x is random. Also 10% of genes in the children's genomes are mutated by a small amount. This speeds up evolution immensely.
A greener can also reproduce by dividing into two. The greeners do this randomly, and the new greener inherits the genome of its parent with small random mutations.
The rest is done by natural selection. The greeners that are better at hunting greens tend to survive longer, so their genome spreads. There is also a bit of dynamic learning available, more on this in the A.I. section.