An attempt to automate the Chrome Dino game using Deep Reinforcement Learning. The main motivation? To finally beat my mobile high score—something I've struggled to replicate on my laptop for some reason.
This project trains a PPO (Proximal Policy Optimization) agent to play the T-Rex Run game using TorchRL and Playwright.
- Headless Training: Uses Playwright to run multiple browser instances in the background without opening visible windows.
- Parallel Environments: Trains on 4+ simultaneous game instances for faster convergence.
- TorchRL Stack: Built on the modern PyTorch RL library for modularity and speed.
- Direct Canvas Access: Captures game frames directly from the browser canvas (no unstable screen capture hacks).
-
Install Dependencies:
pip install -r requirements_torchrl.txt playwright install chromium
-
Train the Agent:
python train_torchrl.py
Training runs on CUDA if available. Check
models/for saved checkpoints. -
Watch it Play: To see the agent in action (visible browser mode):
python test_playwright.py --model models/dino_torchrl.pth --episodes 5
- Input: 4 stacked grayscale frames (84x84)
- Model: 3-layer CNN feature extractor + Actor/Critic heads
- Algorithm: PPO with GAE (Generalized Advantage Estimation)