An implementation on Snake game with grid display
Project description
snake-gym
This package is my own implementation on Snake game with Gym integration.
Usage
import gym
import snake_gym_grid.snake_gym_grid
env = gym.make("snake-gym-10x20-v0")
env.reset()
done = False # whether the snake dies
"""
action ranges from 0 to 3.
0 - LEFT
1 - RIGHT
2 - UP
3 - DOWN
"""
action = ...
observation = env.reset()
while not done:
env.render()
observation, reward, done, info = env.step(action)
env.close()
Output at each time step
- observation: Pixel image of the game
- reward: 1.0 when a food is eaten, -1.0 if snake dies, 0.0 otherwise
- done: whether the snake dies
- truncate: whether the game is running for more than 100000 time steps
- info: an empty dictionary for now
Customize environment
Instead of using registered environment, one can utilize the built-in SnakeGymGrid
class.
# this import is kinda ugly but I have no choice but to follow the gym standard
from snake_gym_grid.snake_gym_grid.envs.snake_gym_grid import SnakeGymGrid
env = SnakeGymGrid(width=..., height=..., n_rows=..., n_cols=...)
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
snake_gym_grid-0.3.1.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file snake_gym_grid-0.3.1.tar.gz
.
File metadata
- Download URL: snake_gym_grid-0.3.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec66d44727fd0db86915e9c07df0ac2f379d079962fd405340855950fccd85ea |
|
MD5 | 2a268f3dbc99242dd14eca190c34a8b3 |
|
BLAKE2b-256 | 390953189c0bfc7057c014e293304894ccef576afcbe466797539e379cad269b |
File details
Details for the file snake_gym_grid-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: snake_gym_grid-0.3.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 893f8f2626911ff9e7d188386ab25d212b96071c0d17ebf63bfeef6ebba615c6 |
|
MD5 | 6246bb574eefbc4012968f1553472677 |
|
BLAKE2b-256 | 9ae6292807dd7eb9dbb3a732ed3f6ce752871418abdfbf29876b62db0c113ff0 |