How dimizorgon/tetris_rl works
This repository is a playable Tetris game with a DQN-based training workflow and an ONNX inference mode. The human workflow runs through the menu and game loop; the AI workflow generates candidate placements, evaluates them, and applies the chosen move in the same game environment. Training saves model checkpoints and episode metrics, which can be plotted separately. Source excerpts support the main calls and data flows; the README is empty, so no additional capabilities are documented.
Main entry points: env.py Tetris Environment · play_npu.py ONNX Player · agent.py DQN Agent · game.py Game State
Components 14
Tetris Gameplay
- Game Loop
main.py - Game State
game.py - Tetrominoes
tetromino.py - Game Settings
settings.py
AI Environment
- Tetris Environment
env.py - Placement Features
env.py
Training
- DQN Agent
agent.py - Model Checkpoints
tetris_ai_model_BEST.pth - Training Log
training_log.csv
ONNX Inference
- ONNX Player
play_npu.py - ONNX Model
tetris_agent_optimized.onnx - ONNX Runtime
Metrics
- Metric Plots
plot_metrics.py
Other components
- Player
Connections 19
- Player → Game Loop: controls
main.py - Game Loop → Game State: updates
main.py - Game Loop → Tetrominoes: draws ghost
main.py - Game State → Tetrominoes: creates pieces
game.py - Game State → Game Settings: uses settings
game.py - Tetris Environment → Game State: steps game
env.py - Tetris Environment → Tetrominoes: enumerates shapes
env.py - Tetris Environment → Game Settings: uses dimensions
env.py - Tetris Environment → Placement Features: extracts features
env.py - DQN Agent → Tetris Environment: trains in
agent.py - DQN Agent → Model Checkpoints: saves weights
agent.py - DQN Agent → Training Log: appends metrics
agent.py - ONNX Player → Tetris Environment: plays through
play_npu.py - ONNX Player → DQN Agent: imports DQN
play_npu.py - ONNX Player → Model Checkpoints: converts weights
play_npu.py - ONNX Player → ONNX Model: exports model
play_npu.py - ONNX Player → ONNX Runtime: runs inference
play_npu.py - ONNX Runtime → ONNX Model: loads model
- Metric Plots → Training Log: reads metrics
plot_metrics.py