A Python implementation of the Chrome Dinosaur Game with NEAT (NeuroEvolution of Augmenting Topologies) algorithm that learns to play through population evolution.
This project recreates the Chrome browser's dinosaur game and implements a neural network-based AI that learns to play the game through genetic evolution. The dinosaurs learn to jump over cacti and duck under birds to achieve higher scores.
main.py
: Primary game application with visual interface showing dinosaurs learning in real-timetrain.py
: Headless version of the game for faster training without renderingsettings.py
: Game configuration and parametersrequirements.txt
: Project dependencies
game/dinosaur.py
: Dinosaur class with movement and collision detectiongame/dinosaur_controller.py
: Interface between the neural network and dinosaur actionsgame/entities.py
: Game entities (obstacles, backgrounds, etc.)game/population_controller.py
: Manages dinosaur population and evolution process
neat/ffn.py
: Feed-forward neural network implementationneat/genome.py
: Genome class for storing network structure and weightsneat/evolutionary_operators.py
: Mutation and crossover operationsneat/activations.py
: Neural network activation functionsneat/edge.py
,neat/node.py
,neat/counter.py
: Supporting classes for network structure
utils/serialization.py
: Functions for saving and loading trained populationsutils/network_visualizer.py
: Tools for visualizing neural networks
assets/
: Contains game sprites and images
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
To run the game with visual interface showing the dinosaurs learning in real-time:
python main.py
For faster training without graphical rendering:
python train.py
This headless mode saves training progress to TensorBoard logs and periodically saves the population to population.json
.
To monitor training metrics with TensorBoard:
tensorboard --logdir=logs