eco

clean-up #5:

an ecosystem as described in Gary William Flake's book - "The Computational Beauty of Nature" (page 191). i started coding it 1,5 years ago but never finished it until today.

white = empty space
green = plant
red = herbivore
blue = carnivore.


* For every time step:
    * For every empty cell, e:
        * If e has three or more neighbors that are plants, then e will become a plant at the next time step (assuming it isn't trampled by a herbivore or carnivore).
    * For every herbivore, h (in random order):
        * Decrease energy reserves of h by a fixed amount.
        * If h has no more energy, then h dies and becomes an empty space.
        * Else, if there is a plant next to h, then h moves on top of the plant, eats it, and gains the plant's energy.
            * If h has sufficient energy reserves, then it will spawn a baby herbivore on the space that it just exited.
        * Else, h will move into a randomly selected empty space, if one exists, that is next to h's current location.
    * For every carnivore, c (in random order):
        * Decrease energy reserves of c by a fixed amount.
        * If c has no more energy, then c dies and becomes an empty space.
        * Else, if there is a herbivore next to c, then c moves on top of the herbivore, eats it, and gains the herbivore's energy.
            * If c has sufficient energy reserves, then it will spawn a baby carnivore on the space that it just exited.
        * Else, c will move into a randomly selected empty space that is next to c's current location. If there are no empty spaces, then c will move through plants.

the rules are fairly simple but the result is complex. carnivores feed on herbivores that in turn feed on plants. populations grow, get overpopulated and die out just like in nature. the sc code is a bit cryptic using a lot nested arrays for efficiency reasons but near the top there are user settings to play with.

here's also a version for processing...
eco

and a mac osx application written in cinder...
eco.app.zip (228k)
ecoApp.cpp (12k)

AttachmentSize
eco.rtf9.48 KB