A Reinforcement Learning agent that masters the classic Snake game using Deep Q-Learning (DQN).
Key Differentiator: This project does not use ML frameworks like PyTorch or TensorFlow. The Neural Network (backpropagation, optimization, and dense layers) is implemented entirely from scratch using NumPy math in nn.py.
- Custom ML Engine: A raw implementation of Feed Forward networks and Gradient Descent.
- Deep Q-Learning: Using the custom engine to approximate Q-values.
- Experience Replay: Storing past game states to train the custom network in mini-batches.
Clone the repo and set up the environment:
git clone https://github.com/Alireza2317/snake_rl_agent
cd Snake_RL
# Create virtual env (Optional)
python -m venv env
source env/bin/activate # Windows: env\Scripts\activate
# Install dependencies (Mainly Pygame & NumPy)
pip install -r requirements.txtRun the main application. The agent will start with random moves and progressively learn from the custom neural net.
python app.pyCheck configs in app.py to tweak hyperparameters like learning rate or epsilon decay.
.
├── app.py # Entry point: Orchestrates training loop and game rendering
├── agent.py # The DQN Agent logic
├── snake.py # The Game Environment (Pygame logic)
├── nn.py # ⚠️ CUSTOM ENGINE: Neural Net implementation from scratch
- Language: Python
- Math Backend: NumPy (Matrix operations)
- Game Engine: Pygame
