A neuroevolution simulation where predators and prey co-evolve neural-network-driven eyes and brains through genetic algorithms, powered by TinyML.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Eye Evolution is a real-time simulation that demonstrates the co-evolution of predator and prey organisms. Each organism is controlled by a neural network (powered by TinyML) whose weights and eye configurations evolve over generations via a genetic algorithm with roulette wheel selection and single-point crossover.
Key features:
- Neural-network-driven behavior -- each organism's brain is an
ML::Modelfrom TinyML that maps eye inputs to movement outputs - Evolving eye positions -- eye placement around the body is encoded in the genome alongside network weights
- Raycasting vision -- organisms cast rays to detect predators, prey, and food in their environment
- Food foraging -- prey must balance escaping predators with collecting food to maximize fitness
- Cross-platform -- builds on macOS, Linux, and Windows via CMake with automatic dependency fetching
- A C++17-compatible compiler (GCC 7+, Clang 5+, MSVC 2017+)
- CMake 3.16 or newer
- Git
On macOS:
brew install cmakeOn Ubuntu/Debian:
sudo apt install cmake build-essential libgl-dev libx11-dev libxrandr-dev libfreetype-dev libudev-devOn Windows, install Visual Studio with the C++ workload, or use MSYS2.
-
Clone the repo
git clone https://github.com/godofecht/Eye-Evolution.git cd Eye-Evolution -
Configure and build (CMake automatically fetches SFML and TinyML)
cmake -B build -DCMAKE_BUILD_TYPE=Release cmake --build build --target EyeEvolution -j$(nproc) -
Run
./build/bin/EyeEvolution
Tip: If you have tinyML cloned as a sibling directory (
../tinyml-repo/), CMake will use it directly instead of fetching from GitHub.
Launch the simulation and watch the organisms evolve in real time. Green circles are prey, red circles are predators, and yellow diamonds are food. White rays show vision; red rays indicate a detected object.
The iteration counter (top-left) shows the current generation. Each generation runs for a fixed duration, after which the genetic algorithm selects the fittest organisms to breed the next generation.
┌─────────────┐ ┌──────────────┐ ┌───────────────┐
│ Eye Inputs │────>│ ML::Model │────>│ Movement Vec │
│ (raycasts) │ │ (TinyML NN) │ │ (fwd + rot) │
└─────────────┘ └──────────────┘ └───────────────┘
^ │
│ ┌──────────────┐ │
└───────────│ Environment │<─────────────┘
│ (SFML loop) │
└──────┬───────┘
│ end of generation
v
┌──────────────┐
│ Genetic │
│ Algorithm │
│ (crossover) │
└──────────────┘
- Perception -- Each organism casts rays from its evolved eye positions and detects nearby entities
- Decision -- Ray hit/miss values are fed into a TinyML neural network which outputs movement commands
- Action -- The organism moves forward and rotates based on network outputs
- Selection -- After a fixed time, organisms are ranked by fitness and selected via roulette wheel
- Reproduction -- Selected parents undergo single-point crossover on both weights and eye positions
- Repeat -- New weights are injected into the population and the next generation begins
- Cross-platform CMake build system
- TinyML integration for neural networks
- Configurable simulation parameters via config file or CLI flags
- Data logging and fitness plots across generations
- Save/load evolved populations to disk
- Multiple environment topologies (walls, obstacles)
See the open issues for a full list of proposed features and known issues.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Abhishek Shivakumar - abhishek.shivakumar@gmail.com
Project Link: https://github.com/godofecht/Eye-Evolution
- TinyML -- Lightweight C++ machine learning library
- SFML -- Simple and Fast Multimedia Library
- Best-README-Template