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 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.2.0.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file snake_gym_grid-0.2.0.tar.gz
.
File metadata
- Download URL: snake_gym_grid-0.2.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2724ea5b74633c239e8c7aa0d014ca40b52343e2a29384bfeda80158a83c8b6a |
|
MD5 | ef7e6cd5052362a49d1975b26938143c |
|
BLAKE2b-256 | 0d84c5d233bd172383567ec93b4e0cdc81e0d57cfb719ccff25ea4efcb299e27 |
File details
Details for the file snake_gym_grid-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: snake_gym_grid-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.3 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 | 286b8400ae11662245baa6fafeca4a1d2d2517ba067c728ff8b579130e90aed3 |
|
MD5 | df1a86a87d939896d4c5c3a53edbc525 |
|
BLAKE2b-256 | 60bb5045a8f38c2d0b202b0e0a7481d8470e59d57b0ef4244be909439fc07773 |