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.2.tar.gz
(5.0 kB
view details)
Built Distribution
File details
Details for the file snake_gym_grid-0.3.2.tar.gz
.
File metadata
- Download URL: snake_gym_grid-0.3.2.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 | ca889a6114365665b4d1df8216256e2310ed0ab746259fab12785437f0329102 |
|
MD5 | 4e407a02c0f9dc1cfae0c99e68ac0079 |
|
BLAKE2b-256 | 0742152e64e17d500b1563b9e7da7ac6fdfdb91e024aa3e10a82b45688fa9d34 |
File details
Details for the file snake_gym_grid-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: snake_gym_grid-0.3.2-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 | 394299323dd215cddb834f6f96e9b1122c3fd0eb6398a46c9803186127c0083c |
|
MD5 | 1e069f2213802f8239e4ec0da4128667 |
|
BLAKE2b-256 | 67c5af9c66734e342213bc494621c0c5bae20ca8e19b357c23e1a39a5e0171c8 |