Chrome Dino AI Pilot
Artificial Intelligence capable of piloting the Chrome dinosaur completely autonomously, avoiding obstacles in real time via a neural network.
Solution
Problem
- ♦Critical class imbalance: continuous running (95%) vs obstacle jumping (5%).
- ♦Lazy model tendency to never jump to maximize its global accuracy.
- ♦Reducing real-time decision latency below the critical 1ms mark per prediction.
- ♦Reliable avoidance of various obstacles (single, multiple cacti and high altitude pterodactyls).
Architecture & Workflow
Real-time AI control architecture: Game state sensory inputs are extracted each frame, passed to an oversampled Multi-Layer Perceptron (MLP) neural classifier, and converted into sub-millisecond action commands inside the Pygame main loop.
Architecture & Workflow DiagramSensory Feature Extraction
Extracting distance, height, and game speed from current Pygame screen frame.
Oversampled Model Training
Training MLPClassifier neural network on rebalanced dataset to learn jump timing.
Sub-1ms Pygame Inference
Running serialized model inside game loop for real-time obstacle avoidance.
Evaluation & Performance Shift
Tracking confusion matrices, jump accuracy (85%), and dynamic speed feature weights.
1. Game State Sensing
Extracting 3 core input features from Pygame frame buffer: Distance to next obstacle, Obstacle height, and current Game speed.
2. Data Preprocessing & Oversampling
Rebalancing training dataset ratio (from 95:5 to balanced 50:50) using Random Oversampling on manual play recordings.
3. Neural Network Classifier (MLP)
Scikit-Learn MLPClassifier neural network trained to predict optimal action class (0: Run, 1: Jump).
4. Real-Time Inference Loop
Serialized .pkl model executing predictions in < 1ms per frame to trigger instant Pygame jump events.
Results / impact
- ♦Jump accuracy increased from 40% to 85% thanks to oversampling.
- ♦87% overall prediction accuracy across all obstacles.
- ♦Minimal inference latency below 1ms per decision.
- ♦Complete autonomous survival of the dinosaur on extended play sessions.
Avant Oversampling (Précision 66%)
Course
Saut
FN (Crash)
Saut OK
Le modèle "préfère" courir car c'est l'action ultra-majoritaire.
Après Oversampling (Précision 87%)
Course
Saut
FN
Saut OK
La diagonale est équilibrée : le modèle a appris l'importance vitale du saut.
Stratégie Qualité des Données : Optimisation par Oversampling
Description du Défi Technique
Lors des premières itérations, le modèle souffrait d'un déséquilibre majeur de classes : les phases de course représentaient plus de 95% du dataset. L'IA a donc développé une stratégie paresseuse en préférant ne jamais sauter pour maximiser statistiquement sa précision globale, au détriment de la survie (60% de collisions non évitées).
Analyse de la Matrice de Confusion
Un taux critique de Faux Négatifs (FN) est observé. Le modèle prédit "Course" lorsqu'un obstacle apparaît car il n'a pas appris la priorité absolue du saut.
En appliquant une technique d'Oversampling, j'ai rééquilibré le poids de la classe minoritaire ("Saut").
Résultat : La diagonale de la matrice est désormais équilibrée. Le taux de succès des sauts est passé de 40% à 85%, prouvant que le modèle donne la priorité à l'évitement d'obstacle.
Feature Importance: Evolution of Decision Making
The AI's brain does not process information the same way depending on game intensity. This Radar Chart illustrates how the model adapts its priorities to survive at high speed.
"The AI places 40% more importance on speed past 1000 points. At the start of the game, the model focuses almost exclusively on obstacle distance. However, as the game speeds up, the MLP shifts its attention to game speed: jump timing becomes more critical than the simple presence of the object."
Tools used
What I learned
- ♦Mastery of handling imbalanced datasets using Oversampling to rebalance the minority class ("Jump").
- ♦Optimization of real-time inference under the critical 1ms mark in Pygame.
- ♦Concrete use of the confusion matrix to analyze AI model performance.
What I would improve next
- ♦Training with Deep Reinforcement Learning (DQN) instead of the MLP Classifier.
- ♦Optimization of the model to adapt to faster dynamic speed changes.
Visual references
