A simple forest simulator.
The forest is laid out as a grid. Plants and animals are distributed randomly throughout the grid.
Animals have properties:
food source
- This can beherbivore
,carnivore
, oromnivore
.hunger
- Can behungry
ornot hungry
.life
- Tracks the health of the animal.
All animals start with a random food preference, a hunger of not hungry
, and a full life.
Plants have properties:
life
- Tracks the health of the plant.
At every iteration of the simulation:
- For herbivorous animals:
- When hungry and next to a plant, the animal will eat from the plant, reducing the plant's life by the amount needed to restore full life to the animal.
- Does not eat animals.
- For carnivorous animals:
- When hungry and next to another animal, the animal will eat the other animal, reducing the other animal's life by the amount needed to restore full life to the animal.
- Does not eat plants.
- For omnivorous animals, herbivorous and carnivorous rules apply.
- For all animals:
- The animal will move one grid position in any of the 8 directions around it (N, S, E, W, NE, NW, SE, or SW).
- Life is reduced by one if it does not eat. If no life remains, the animal is considered dead.
- The animal is hungry if its life is not full.
- The animal will eat only if it is hungry and next to food.
- For plants:
- Life is unchanged if it is full.
- Life is reduced by one if it is less than half.
- Life is increased by one if is half or more.
Other requirements:
- Periodically, the forest must be culled of dead plants and animals.