How cs10101/snake_ai_game works
AI Snake is a Deep Q-Learning application: its training loop observes the Snake environment, chooses and applies actions, learns from rewards and replayed experience, and tracks performance. The README also documents checkpoint resume/save and finite or indefinite training. The excerpts establish the main calls and model/plot logic, but omit parts of agent.py; uncertain internal wiring is not shown.
Main entry points: agent.py CLI and loop · game.py Game step · model.py Q trainer · helper.py Training plots
Components 12
Training runtime
- CLI and loop
agent.py - State encoding
agent.py - Action policy
agent.py
Snake environment
- Game step
game.py - Game state and rules
game.py
Q-learning
- Replay memory
agent.py - Q network
model.py - Q trainer
model.py
Persistence and results
- Model checkpoints
- Training plots
helper.py - Final graph
Other components
- Trainer
Connections 17
- Trainer → CLI and loop: starts training
- CLI and loop → State encoding: requests observation
- State encoding → Game state and rules: reads game state
- State encoding → Game state and rules: checks collision
- CLI and loop → Action policy: requests action
- Action policy → Q network: predicts Q-values
- CLI and loop → Game step: applies action
- Game step → Game state and rules: updates state
- Game step → CLI and loop: returns reward and score
- CLI and loop → Replay memory: stores experience
- CLI and loop → Q trainer: trains on step
- CLI and loop → Replay memory: samples batches
- CLI and loop → Q trainer: trains batches
- Q trainer → Q network: updates weights
- CLI and loop → Model checkpoints: loads and saves model
- CLI and loop → Training plots: plots scores
- CLI and loop → Final graph: saves final graph