https://github.com/blagojeblagojevic/ecosystem
This C program simulates an evolutionary ecosystem using SDL2 graphics library
https://github.com/blagojeblagojevic/ecosystem
c genetic-algorithm sdl2
Last synced: 10 months ago
JSON representation
This C program simulates an evolutionary ecosystem using SDL2 graphics library
- Host: GitHub
- URL: https://github.com/blagojeblagojevic/ecosystem
- Owner: BlagojeBlagojevic
- Created: 2023-10-22T17:17:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-08T16:42:35.000Z (over 2 years ago)
- Last Synced: 2025-02-14T06:36:42.763Z (over 1 year ago)
- Topics: c, genetic-algorithm, sdl2
- Language: C
- Homepage:
- Size: 1.56 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Evolutionary Simulation with SDL2
This C program simulates an evolutionary ecosystem using SDL2 graphics library. Prey creatures move and reproduce based on their genetic traits. Over time, the population evolves as individuals with advantageous traits survive and reproduce. The simulation shows the evolution of prey creatures with different genetic characteristics (speed, energy, reproduction speed) and colors (white, red, green, blue, yellow) in a dynamic environment.
## Requirements
* SDL2 library installed on your system.
## How to Build and Run
1. Make sure you have SDL2 installed. You can download it from SDL2 official website or install it using a package manager.
2. Compile the program using a C compiler. For example, using gcc:
> gcc -o main main.c -lSDL2 -lm -fopenmp
Note: The -fopenmp flag is used to enable OpenMP parallelization for better performance. Make sure your compiler supports OpenMP.
## Simulation Rules
* Prey creatures (colored squares) move around the environment.
* Prey creatures gain and lose energy as they move.
* Prey creatures can reproduce if their energy level is high enough.
* Offspring inherit genetic traits from their parents with a chance of mutation.
* The simulation runs for a specified number of rounds.
## Simulation Results
After the simulation ends, the program outputs the average genetic traits of the population
and the number of individuals with each color.
## Parameters (in the code)
* 'Nprey': Number of initial prey creatures.
* 'Nfood': Number of food particles in the environment.
* 'MutationChance': Chance of genetic mutation during reproduction.
* 'Nround': Number of simulation rounds.
Feel free to modify these parameters in the code to observe different evolutionary outcomes.

