Teaching a neural net to clear lines, one block at a time
A minimal PyTorch implementation of Deep Q-learning that learns to play Tetris from raw pixel input.

What it does
This repo trains a Deep Q-Network to play Tetris using PyTorch. You run train.py to teach the agent from scratch, then test.py to watch it stack blocks. The author provides a pre-trained checkpoint in trained_models/tetris if you’d rather skip the GPU hours.
The interesting bit
It’s deliberately basic — the README calls it “a very basic example of Reinforcement Learning’s application” — which makes it a decent sandbox for understanding DQN without wading through a full RL framework. The agent learns from raw game frames (via OpenCV) rather than hand-engineered board features, which is the harder and more instructive path.
Key highlights
- Pure PyTorch, no RL library abstraction layers
- Learns from pixel input using
cv2for frame processing - Includes pre-trained model and YouTube demo for quick validation
- ~500 stars suggests it has served as a reference implementation for others
- Clean separation:
train.pyandtest.py, nothing clever in the structure
Caveats
- README is sparse: no mention of reward shaping, network architecture, or training duration
- Requires Python 3.6 specifically, which is end-of-life
- No performance metrics, convergence graphs, or comparison to random play — you can’t tell if the agent is actually good or just lucky
Verdict
Grab this if you want a minimal, hackable DQN example for Tetris. Skip it if you need a production RL pipeline, modern Python support, or any theoretical depth — this is glue code between PyTorch and a Tetris environment, and it knows it.