My final project for Nature of Code; a landscape of food and danger inhabited by different species of artificial creatures.
I was really fascinated by the examples of artificial agents we worked through in the Nature of Code class; there is just something incredibly fun about being able to create pseudo-lifelike behaviour in software.
My goal for this project was to improve my understanding of Reynolds' steering behaviours and genetic algorithms by designing a “landscape” inhabited by different species of creatures. In this landscape the creatures seek food, feed, flee from danger, reproduce, age and die. (The full proposal for the project is over here).
Food-sources are indicated by green circles, and as the creatures deplete these food sources they shrink, disappear and then regrow slowly.
Threats are indicated by smaller red circles. Unlike food sources, these threats never deplete. If a creature comes too close, they are injured - proximity to the threat reduces the amount of energy that a creature has.
The creatures retain a memory of food sources and threats; these are indicated by the green and red icons that are displayed next to each creature. (This visual indication of creatures' memory was one of the most useful things I made for the project - much more useful and immediate than print-line statements.)
- Energy/Life: The creatures are created with a finite amount of energy that is depleted when they move and over time. To replenish their energy supplies they must consume food.
- Seeking: The creatures will wander around the landscape at random until they find an object that interests them; at which point they will move towards that object.
- Vision: When the creatures are within a short distance of an object they can tell if it is food or a threat.
- Fleeing: The creature can move quickly away from threats.
- Feeding: The creature can arrive at a food source and consume it; the food source is depleted and the creature's energy level increases.
- Reproduction: If the creature has sufficient energy and is close to another creature of its species, it has a chance of reproducing.
- Memory: Each creature can remember the food sources and threats it encounters in the landscape.
All of these behaviours are triggered depending on scenario the creature finds itself in; if it's near an object, it will move towards it to examine it more closely and then feed/flee depending on what that object is. If the creature is near a potential mate, then a fitness algorithm will decide whether or not a new creature should be created etc.
This video shows the version of the project I presented in class, with a couple of small tweaks. In the video you'll see three species searching for food and encountering threats. From time to time two creatures of the same species will encounter one another and a new creature will be produced. To make the new creatures easier to see a grey circle is drawn around them for the first 10 seconds of their life. A higher resolution version of the video can be downloaded from Vimeo.
There are lots of ways in which this project could be improved upon. I will definitely improve the genetic algorithm that is used when new creatures are created. At the moment there is no mutation, so the results are predictable and the fitness of the creatures doesn't improve across generations.
As I said in my original proposal, I think it would also be great to tie some aspects of the landscape to information from the real world. Creatures could behave differently depending on the time of day, or they could respond to weather conditions. Food sources could regrow more quickly depending on weather etc.
All of the code from the project is available on github; just clone it to your computer and then open the sketch in Processing. The code is reasonably well commented. Screenshots are available on Flickr and there are several work-in-progress videos on Vimeo.