Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rsgoksel/snake-game_ppo-solution
Snake game environment integrated with OpenAI Gym. Proximal Policy Optimization (PPO) implementation for training. Visualization of training progress and agent performance. Easy to understand code.
https://github.com/rsgoksel/snake-game_ppo-solution
a2c actor-critic gym ppo ppo-agent proximal-policy-optimization pygame python reinforcement-learning-agent snake-game stable-baselines stable-baselines3
Last synced: 9 days ago
JSON representation
Snake game environment integrated with OpenAI Gym. Proximal Policy Optimization (PPO) implementation for training. Visualization of training progress and agent performance. Easy to understand code.
- Host: GitHub
- URL: https://github.com/rsgoksel/snake-game_ppo-solution
- Owner: RsGoksel
- License: apache-2.0
- Created: 2023-10-14T11:43:24.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-09T15:15:47.000Z (6 months ago)
- Last Synced: 2024-05-09T16:35:55.364Z (6 months ago)
- Topics: a2c, actor-critic, gym, ppo, ppo-agent, proximal-policy-optimization, pygame, python, reinforcement-learning-agent, snake-game, stable-baselines, stable-baselines3
- Language: Jupyter Notebook
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Snake-Game_PPO-Solution
Snake game environment integrated with OpenAI Gym. Proximal Policy Optimization (PPO) implementation for training. Visualization of training progress and agent performance. Easy to understand code.# What is PPO?
PPO stands for Proximal Policy Optimization. PPO uses a "proximal" objective function to ensure stable policy updates.
It uses a clipping mechanism to prevent large policy updates, which makes training more stable.
![image](https://github.com/RsGoksel/Snake-Game_PPO-Solution/assets/80707238/732e1a20-d920-48f9-b6cd-a045cf1c00e8)# Problem
The classic snake game was discussed for the PPO solution example as problem.
* _**Reward:** Reward was the distance between the apple and agent. The closer get to the apple, the more rewards get._
* _**Observation Space:** Observation array was "Snake_X, Snake_Y, Apple_X, Apple_Y, Euclid_Distance_Apple_to_Snake"._
* _**Action Space:** Action space was discrete. Because the screen of game was tiled, and we have 4 directions for move."._# Usage
```
$ pip install -r requirements.txt
```
* test.py : Testing for the environment. You can display how game screen is.
* train.py : Trains the Agent for learning the game.
* Agent.py : Snake agent's class.
* env_PPO.py: Main game source code. You can alter the game if you want add some hardness to game.
* Snake_PPO.ipynb : Comprehensive file that involves whole code and attributes.For testing,
```
$ python test.py
```For training,
```
$ python train.py
```Also, you can alter the constant variables from Constants.py file Especially PPO hyperparameters.
# AgentPlay
![Agent](https://github.com/RsGoksel/Snake-Game_PPO-Solution/assets/80707238/429fb406-f7fb-45a6-bf85-f9bea9606df2)