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

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

Uploaded Source

Built Distribution

snake_gym_grid-0.4.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snake_gym_grid-0.4.0.tar.gz
  • Upload date:
  • Size: 6.6 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.4.0.tar.gz
Algorithm Hash digest
SHA256 7c61e22a2479dfb1c819252dcfbf04a33aa74081524f9db5661e5001b0cf53e6
MD5 c7b69d3a16bfcfc447d89585e3e00276
BLAKE2b-256 85c4a041182cb74c44d43f264f98455ea8f787ba3484c3d5e843692d424ca142

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for snake_gym_grid-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a947dc8696c0c6c806cf732af85823ee8294d740defb121a0b7bfc346f95fad9
MD5 a2c656a21430969d3bab7eab1ca77eab
BLAKE2b-256 6a1d0c2c9920da56d89257a58b602cdbfc5588a6b744e3002a5dac878a6c5ae4

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