Skip to main content

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


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.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

snake_gym_grid-0.3.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file snake_gym_grid-0.3.0.tar.gz.

File metadata

  • Download URL: snake_gym_grid-0.3.0.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

Hashes for snake_gym_grid-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9a98d4645a23d0becc86527e854e6748ec31d23618dfe8c956f81b29470c0ae1
MD5 c31af29756b703ef8069ae116cd969c4
BLAKE2b-256 017110e3cb83ce5b8e5423e6242c430a6bd39769e3735f98c46f67c14b48ff5e

See more details on using hashes here.

File details

Details for the file snake_gym_grid-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for snake_gym_grid-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b02edd7dbb0cd16d12cd13457b5a0a6a21a1bdf68a41cf744ded96232ccf70d
MD5 4114d7459844ab5a783594aa966a1f3d
BLAKE2b-256 31f4f951ffe9b8248e9f4d8e0a35c9796d94c7b67c5dedd88acf2f5f5a874d82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page