Skip to content

A dynamic ecosystem simulation built with Python and Pygame.

Notifications You must be signed in to change notification settings

Sfabi28/ecosystem_simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ EcoSim: Predator vs Prey Simulation

A dynamic ecosystem simulation built with Python and Pygame. Watch an autonomous world evolve where Preys hunt for food while escaping Predators, creating a natural life cycle of growth, extinction, and balance.

๐ŸŽฎ Features

  • Autonomous Agents: Entities use vector mathematics to calculate distances, flee from threats, and chase targets.
  • Metabolism System: Every movement costs energy. Agents must eat to survive; otherwise, they starve.
  • Reproduction: Agents that gather enough energy replicate, passing their traits to the next generation.
  • Dynamic Environment: Food (grass) grows naturally over time, but can be depleted by overpopulation.
  • Real-time Interaction: Add new predators dynamically with a mouse click to disrupt the balance.

๐Ÿง  How it Works

The simulation follows three main rules of nature:

  1. ๐ŸŸข Prey (Green):

    • Wanders randomly when safe.
    • Senses predators nearby and flees in the opposite direction.
    • Seeks food (White dots) when hungry.
    • Reproduces when energy is high.
  2. ๐Ÿ”ด Predators (Red):

    • Actively hunts the nearest Prey.
    • Consumes more energy than Preys (requires constant hunting).
    • Dies of starvation if the Prey population collapses.
  3. โšช Grass (White):

    • Grows randomly over time.
    • Sustains the Prey population.

๐Ÿ“‚ Project Structure

  • world.py: The main engine. Handles the game loop, drawing, collision detection, and population management.
  • prey.py: Defines the Prey class (fleeing and foraging logic).
  • predator.py: Defines the Predator class (hunting logic).

๐Ÿš€ Installation & Usage

1. Prerequisites

You need Python installed on your machine.

2. Set up the environment

It is recommended to use a virtual environment:

python3 -m venv venv
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

4. Run the simulation

python world.py

About

A dynamic ecosystem simulation built with Python and Pygame.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages