{"id":21831043,"url":"https://github.com/anroshka/snake-ai","last_synced_at":"2026-02-24T04:02:22.011Z","repository":{"id":264259497,"uuid":"892832694","full_name":"Anroshka/snake-ai","owner":"Anroshka","description":"🐍 A Snake game AI that learns to play through Deep Q-Learning. Built with PyTorch and Pygame, featuring CUDA acceleration and real-time visualization of the learning process.","archived":false,"fork":false,"pushed_at":"2025-06-10T03:37:46.000Z","size":172,"stargazers_count":17,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-20T16:27:56.559Z","etag":null,"topics":["artificial-intelligence","collaborate","collaboration","cuda","deep-learning","deep-q-learning","dqn","game-ai","gpu-acceleration","machine-learning","neural-network","pygame","python","pytorch","q-learning","reinforcement-learning","snake-game"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Anroshka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-22T21:39:35.000Z","updated_at":"2025-05-27T15:40:33.000Z","dependencies_parsed_at":"2024-12-11T02:31:55.813Z","dependency_job_id":"d8aa60cf-e218-4c98-bb87-bf0fea77d63d","html_url":"https://github.com/Anroshka/snake-ai","commit_stats":null,"previous_names":["anroshka/snake-ai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Anroshka/snake-ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anroshka%2Fsnake-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anroshka%2Fsnake-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anroshka%2Fsnake-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anroshka%2Fsnake-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anroshka","download_url":"https://codeload.github.com/Anroshka/snake-ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anroshka%2Fsnake-ai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29771041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T04:01:02.180Z","status":"ssl_error","status_checked_at":"2026-02-24T03:59:49.901Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","collaborate","collaboration","cuda","deep-learning","deep-q-learning","dqn","game-ai","gpu-acceleration","machine-learning","neural-network","pygame","python","pytorch","q-learning","reinforcement-learning","snake-game"],"created_at":"2024-11-27T19:08:05.211Z","updated_at":"2026-02-24T04:02:21.996Z","avatar_url":"https://github.com/Anroshka.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Snake AI with Deep Q-Learning 🐍\n\nAn advanced implementation of a Snake game AI that learns through Deep Q-Learning, featuring real-time visualization, multi-agent support, and performance optimizations.\n\n## 📚 Table of Contents\n\n1. [🚀 Key Features](#-key-features)\n2. [🛠️ Technical Specifications](#️-technical-specifications)\n3. [📊 Real-time Visualization](#-real-time-visualization)\n4. [🚀 Installation](#-installation)\n5. [💻 Usage](#-usage)\n6. [⚙️ Performance Features](#-performance-features)\n7. [🔄 Automatic Saving](#-automatic-saving)\n8. [🎮 Controls](#-controls)\n9. [📈 Training Graphs](#-training-graphs)\n10. [🎯 Latest Improvements](#-latest-improvements)\n11. [🚀 Next Steps](#-next-steps)\n12. [📝 Requirements](#-requirements)\n13. [🔧 Configuration](#-configuration)\n14. [📚 Project Structure](#-project-structure)\n15. [🤝 Contributing](#-contributing)\n16. [📄 License](#-license)\n17. [🛡️ Security](#-security)\n18. [📜 Code of Conduct](#-code-of-conduct)\n\n## 🚀 Key Features\n\n- 🧠 Deep Q-Network with Priority Experience Replay (PER)\n- 🎮 Real-time game visualization with informative HUD\n- 🐍 Multi-agent support (2-6 snakes training simultaneously)\n- 📊 Live training statistics and performance graphs\n- 🔄 Automatic checkpointing and model saving\n- ⚡ CUDA-accelerated training with AMP\n- 📈 Adaptive learning parameters\n- 🎯 Enhanced exploration/exploitation balance\n- 🤖 Interactive agent count configuration\n\n## 🛠️ Technical Specifications\n\n| Feature          | Description                                      |\n|------------------|--------------------------------------------------|\n| **Framework**    | PyTorch with CUDA support                        |\n| **Visualization**| Pygame, Matplotlib                               |\n| **Neural Network**| Input Layer: 17 neurons (enhanced state)        |\n|                  | Hidden Layer: 512 neurons                        |\n|                  | Output Layer: 4 actions (movement directions)    |\n| **Training Parameters**| Learning Rate: 0.0005                      |\n|                  | Gamma: 0.99                                      |\n|                  | Initial Epsilon: 1.0                             |\n|                  | Epsilon Decay: 0.997                             |\n|                  | Memory Size: 100,000                             |\n|                  | Batch Size: 64                                   |\n\n## 📊 Real-time Visualization\n\n- Individual scores for each snake\n- Best score achieved\n- Rolling average (last 100 games)\n- Exploration rate (Epsilon)\n- Samples collected\n- Training performance (FPS)\n- Loss function evolution\n- Score distribution histogram\n- Multi-agent interaction visualization\n\n## 🚀 Installation\n\n1. Clone the repository\n```bash\ngit clone https://github.com/Anroshka/snake-ai.git\ncd snake-ai\n```\n\n2. Install dependencies:\n```bash\npip install -r requirements.txt\n```\n\nFor CUDA support (recommended):\n```bash\npip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121\n```\n\n## 💻 Usage\n\nStart training:\n```bash\npython train_multi.py\n```\n\nYou'll be prompted to enter the number of snakes (2-6 recommended) for training.\n\n## ⚙️ Performance Features\n\n- Multi-agent learning environment\n- Multi-threaded processing\n- Automatic device selection (GPU/CPU)\n- Optimized rendering with FPS control\n- Gradient clipping for stability\n- Automatic Mixed Precision (AMP)\n- Priority Experience Replay\n- Efficient memory management\n- Advanced reward system\n\n## 🔄 Automatic Saving\n\n- Best model preservation\n- Checkpoints every 10 episodes\n- Training statistics graphs\n- Performance metrics tracking\n- Individual agent models saving\n\n## 🎮 Controls\n\n- ESC: Exit training\n- Automatic gameplay during training\n- Visualization every 10 episodes\n- Training stats display\n- Interactive agent count selection\n\n## 📈 Training Graphs\n\n- Multi-agent learning progress\n- Loss function\n- Epsilon decay\n- Score distribution\n- Moving averages\n- Agent interaction patterns\n\n## 🎯 Latest Improvements\n\n- Added multi-agent support (2-6 snakes)\n- Enhanced visualization with semi-transparent HUD\n- Stabilized FPS for better visualization\n- Minimum samples threshold for training start\n- Improved error handling and stability\n- Better memory management\n- Adaptive learning parameters\n- Interactive configuration system\n\n## 🚀 Next Steps\n\n- [ ] Add competitive and cooperative training modes\n- [ ] Implement agent specialization\n- [ ] Optimize multi-agent interactions\n- [ ] Develop adaptive learning rate scheduling\n- [ ] Explore different state representations\n- [ ] Add agent personality traits\n\n## 📝 Requirements\n\n- Python 3.10+\n- CUDA-capable GPU (recommended)\n- PyTorch 2.0+\n- Pygame 2.4.0\n- Matplotlib for visualization\n\n## 🔧 Configuration\n\nAll training parameters can be adjusted in `train_multi.py`:\n- Number of agents (2-6)\n- Episode count\n- Memory size\n- Batch size\n- Learning rate\n- Epsilon decay\n- Visualization frequency\n- Reward system parameters\n\n## 📚 Project Structure\n\n- `game.py`: Snake game environment with multi-agent support\n- `model.py`: DQN implementation with PER\n- `train_multi.py`: Multi-agent training loop and visualization\n- `models/`: Saved models and checkpoints\n\n## 🤝 Contributing\n\nWe welcome contributions to Snake AI! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details on how to submit pull requests, report issues, and contribute to the project.\n\nBefore contributing, please read our [Code of Conduct](CODE_OF_CONDUCT.md).\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## 🛡️ Security\n\nFor details about our security policy and how to report security vulnerabilities, please see our [Security Policy](SECURITY.md).\n\n## 📜 Code of Conduct\n\nThis project and everyone participating in it is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code.\n\n## 🙏 Acknowledgments\n\n- Thanks to all contributors who have helped shape Snake AI\n- Special thanks to the PyTorch and Pygame communities\n- Inspired by various reinforcement learning implementations\n\n## 📞 Contact\n\nFor questions and support, please:\n1. Check existing [Issues](https://github.com/Anroshka/snake-ai/issues)\n2. Create a new issue if needed\n3. Follow our [Security Policy](SECURITY.md) for reporting vulnerabilities\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanroshka%2Fsnake-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanroshka%2Fsnake-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanroshka%2Fsnake-ai/lists"}