Skip to content

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

 
 
 

Contributors

Languages