Welcome to SnakeNN, where the classic Snake game gets a futuristic makeover with AI! This isn't just a snake chasing apples—it's a neural-network-powered genius learning to slither smarter with every bite.
SnakeNN is the classic Snake game enhanced with artificial intelligence. Using PyTorch, reinforcement learning, and a sprinkle of curiosity, SnakeNN evolves as it plays. It dodges walls, navigates mazes, and hunts food like a pro—all thanks to its dynamic neural network that grows and prunes itself on the fly.
- Python 3.7+ 🐍
- Git 🌿
- Optional: An NVIDIA GPU with CUDA support for faster AI training
-
Clone the Repository
git clone https://github.com/your-username/SnakeNN.git cd SnakeNN -
Install Dependencies
pip install pygame numpy torch
- Pygame: Renders the game environment
- NumPy: Handles numerical operations
- PyTorch: Powers the neural network
For GPU users: Install the CUDA version of PyTorch from the official website for better performance
-
Verify Installation
python -c "import pygame, numpy, torch; print('Ready to roll! 🐍')" -
Check GPU Availability (optional)
python -c "import torch; print('GPU Ready!' if torch.cuda.is_available() else 'No GPU, but we'll manage!')"
Run the game and control the snake yourself:
python SnakeRL.pyControls:
- Arrow Keys ⬆️⬇️⬅️➡️ – Move the snake
- ESC – Exit the game
- M – Increase speed
- N – Decrease speed
Let the neural network play and learn:
python SnakeNeuralAdvanced.py- Watch the snake learn and adapt its strategy
- Press ESC to exit
- Dynamic Neural Network: The network grows and shrinks as it learns
- Curiosity-Driven Exploration: The AI explores based on novelty and surprise
- Maze Navigation: Successfully handles simple and complex mazes
- Skill Transfer: Applies learned strategies to new challenges
- Progress Visualization: Optional graphs to monitor AI learning
- CPU Running Slow: Try smaller mazes or fewer episodes
- GPU Not Utilized: Verify CUDA setup with the test command above
- Missing Libraries: Run
pip install pygame numpy torchagain - Version Conflicts: Use a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install pygame numpy torch
- Ensure Python version is 3.7+ (
python --version) - Check terminal output for error messages
- Open issues or submit pull requests on GitHub
- Help make SnakeNN even smarter!
- Licensed under the MIT License
- Created by Javier Lora
- Powered by Pygame, NumPy, and PyTorch
- Inspired by the classic Snake game
Happy coding and snake charming! 🍎🐍