{"id":28059561,"url":"https://github.com/karthikeya-akhandam/snake-gama-using-deep-q---learning","last_synced_at":"2026-05-02T06:31:48.139Z","repository":{"id":291787614,"uuid":"978782150","full_name":"Karthikeya-Akhandam/Snake-Gama-Using-Deep-Q---Learning","owner":"Karthikeya-Akhandam","description":"Using Deep Q - Learning to implement reinforcement learning in classic Snake game ","archived":false,"fork":false,"pushed_at":"2025-05-06T14:04:20.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-12T08:07:02.304Z","etag":null,"topics":["dee","pygame","pyth","pytorch","reenforcementlearning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Karthikeya-Akhandam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-06T13:56:20.000Z","updated_at":"2025-05-06T14:04:23.000Z","dependencies_parsed_at":"2025-05-06T15:06:09.022Z","dependency_job_id":"7d34ea4d-d2a4-4f27-93f9-167626c7ff3f","html_url":"https://github.com/Karthikeya-Akhandam/Snake-Gama-Using-Deep-Q---Learning","commit_stats":null,"previous_names":["karthikeya-akhandam/snake-gama-using-deep-q---learning"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karthikeya-Akhandam%2FSnake-Gama-Using-Deep-Q---Learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karthikeya-Akhandam%2FSnake-Gama-Using-Deep-Q---Learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karthikeya-Akhandam%2FSnake-Gama-Using-Deep-Q---Learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Karthikeya-Akhandam%2FSnake-Gama-Using-Deep-Q---Learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Karthikeya-Akhandam","download_url":"https://codeload.github.com/Karthikeya-Akhandam/Snake-Gama-Using-Deep-Q---Learning/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253700616,"owners_count":21949694,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dee","pygame","pyth","pytorch","reenforcementlearning"],"created_at":"2025-05-12T08:07:07.915Z","updated_at":"2026-05-02T06:31:48.095Z","avatar_url":"https://github.com/Karthikeya-Akhandam.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🐍 Snake AI using Deep Q-Learning\n\nThis project implements an AI agent to play the classic Snake game using Deep Q-Learning (DQN), a reinforcement learning algorithm. The game environment is built using PyGame, and the AI is trained using PyTorch.\n\n---\n\n## 📌 Problem Statement\n\nCan an AI agent learn to play and master the classic Snake game using reinforcement learning techniques?\n\nThis project explores how Deep Q-Learning can be used to teach an AI agent to:\n- Navigate the game grid\n- Eat food to increase score\n- Avoid collisions with walls and its own body\n- Maximize performance through training\n\n---\n\n## 🎮 Game Overview\n\n- Snake moves in a grid environment.\n- Eats food to grow and increase score.\n- Dies on collision with wall or itself.\n- The agent must learn efficient and safe navigation.\n\n---\n\n## 🧠 Deep Q-Learning (DQN)\n\n- DQN is a value-based reinforcement learning algorithm.\n- The agent uses a neural network to approximate Q-values.\n- Key components:\n  - State: 11-dimensional binary vector representing current game state\n  - Action: [straight, right, left]\n  - Reward:\n    - +10 for eating food\n    - -10 for dying\n    - -0 per step (to encourage faster solutions)\n  - Experience Replay: Stores past experiences and trains on batches\n  - Target Network: Helps stabilize learning\n\n---\n\n## 🎲 Epsilon-Greedy Strategy\n\n- Balances exploration vs exploitation.\n- Starts with high ε (exploration), gradually decays over time.\n- Random action with probability ε.\n- Best-known action with probability 1 - ε.\n- Ensures the agent explores enough early on and exploits learned knowledge later.\n\n---\n\n## 🔧 Technologies Used\n\n| Technology | Purpose |\n|------------|---------|\n| Python     | Programming language |\n| PyTorch    | Neural network and deep learning |\n| PyGame     | Game development and environment |\n| NumPy      | Numerical operations |\n| Matplotlib | Plotting training graphs |\n\n---\n\n## 🏗️ Architecture Diagram (8 Steps)\n\n1. Game Environment (PyGame)\n2. State Representation (11 features)\n3. Neural Network Model (PyTorch)\n4. Experience Replay Buffer\n5. Epsilon-Greedy Policy for action selection\n6. Q-value Calculation using Bellman Equation\n7. Network Optimization (Backpropagation)\n8. Performance Visualization (Matplotlib)\n\n---\n\n## 🛠️ Implementation Steps (6 Steps)\n\n1. Create the Snake game using PyGame.\n2. Represent the game state using an 11-dimensional binary vector.\n3. Build the Deep Q-Network using PyTorch.\n4. Use Epsilon-Greedy strategy for exploration.\n5. Implement Experience Replay and train with Q-learning updates.\n6. Plot training performance to visualize learning.\n\n---\n\n## 📁 Project Structure\n\n```plaintext\n.\n├── agent.py         # Contains DQNAgent class for decision-making\n├── model.py         # Neural network definition using PyTorch\n├── game.py          # Snake game environment using PyGame\n├── train.py         # Training loop and performance tracking\n├── utils.py         # Helper functions (optional)\n├── screenshots/     # Graphs and game visuals\n├── requirements.txt # List of dependencies\n└── README.md        # Project documentation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarthikeya-akhandam%2Fsnake-gama-using-deep-q---learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarthikeya-akhandam%2Fsnake-gama-using-deep-q---learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarthikeya-akhandam%2Fsnake-gama-using-deep-q---learning/lists"}