https://github.com/xffxff/snake-gym
Snake game as a gym environment
https://github.com/xffxff/snake-gym
gym multiplayer snake snake-game
Last synced: about 2 months ago
JSON representation
Snake game as a gym environment
- Host: GitHub
- URL: https://github.com/xffxff/snake-gym
- Owner: xffxff
- License: apache-2.0
- Created: 2019-01-10T01:22:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-10T08:33:42.000Z (over 7 years ago)
- Last Synced: 2025-03-22T23:27:55.667Z (over 1 year ago)
- Topics: gym, multiplayer, snake, snake-game
- Language: Python
- Homepage:
- Size: 43 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Snake game as a Gym environment
## Installation
```
git clone https://github.com/XFFXFF/snake-gym
cd snake-gym
pip install -e .
```
## How to use it
### Running the classic snake game with random policy
```python
import gym
import snake_gym
env = gym.make('Snake-rgb-v0')
obs = env.reset()
while True:
act = env.action_space.sample()
obs, rew, done, info = env.step(act)
env.render()
if done:
env.reset()
```
### Running multiple snakes with random policy.
```python
import gym
import snake_gym
env = gym.make('MultiSnake-v0')
env.set_snakes(2) #set the number of snakes
env.set_foods(3) #set the number of random foods
obs = env.reset()
while True:
act = env.action_space.sample()
obs, rew, done, info = env.step(act)
env.render()
if info.get('game_over'):
env.reset()
```