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.1.tar.gz
(4.9 kB
view details)
Built Distribution
File details
Details for the file snake_gym_grid-0.2.1.tar.gz
.
File metadata
- Download URL: snake_gym_grid-0.2.1.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 | 2147a0b351aaf13edcd4ea1e40e16d6092cb8bc369b7319c03add635c1c8b7ce |
|
MD5 | 7c296681eddf09ff566439a02167dc98 |
|
BLAKE2b-256 | 0ae50fc10a55f70d0f5f34a175512d14ff495c5eaf736dfbf8b787a20287297e |
File details
Details for the file snake_gym_grid-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: snake_gym_grid-0.2.1-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 | 138bd838d408e19704fa483a7701d58e27c59474c76a5af835b6207f2daeb5ac |
|
MD5 | ae111f45ac2b77e40daec2c6ef6ceeba |
|
BLAKE2b-256 | 71b2b796b926340b483561baf8b938b7128ead35fe66429d0e9d0c0d9007d704 |