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
env = gym.make("snake-gym-10x20-normal-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
Env registration
snake-gym-grid-10x20-normal-v0
: Snake game with 10 x 20 board and 500 x 900 observationsnake-gym-grid-10x20-tiny-v0
: Snake game with 10 x 20 board and 80 x 80 observationsnake-gym-grid-10x20-1d-v0
: Snake game with 10 x 20 board and summarized observation. Observation in this case is vector[dangerRight, dangerLeft, dangerBelow, dangerAbove, foodBelow, foodAbove, foodRight, foodLeft]
.
Note:
-
danger<Direction>
= neighbor block of snake head in the<Direction>
is occupied by a snake body or is out of game board. -
food<Direction>
= is the food in the<Direction>
of the snake head? -
For any other environment, observation is the raw image from the game view. For tiny, the size is 80 x 80 and for normal, it's 500 x 900.
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.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
Built Distribution
File details
Details for the file snake_gym_grid-0.5.0.tar.gz
.
File metadata
- Download URL: snake_gym_grid-0.5.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91d09a4ff7b6c6e6bd027176d9701b34608a8dea1f15300319d8619013a21bc3 |
|
MD5 | 978f087b24fe0a479ccf87b9be008db2 |
|
BLAKE2b-256 | a6ceb65b2a05e07f8ee1360304e46ec68e0a44d04b32c165a9595b93c6a42f15 |
File details
Details for the file snake_gym_grid-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: snake_gym_grid-0.5.0-py3-none-any.whl
- Upload date:
- Size: 7.5 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 | 467ceb50011955e45dbe54ac440d0920e46776e0e03a389e0fca20feef104e22 |
|
MD5 | 3dbf6b7a16e178d0fc88679179452463 |
|
BLAKE2b-256 | e9ff7c1621791fb5d5e25f8fd3d8f534b2c47d3a5c1a839ad8bea8fdcd31b59b |