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", new_step_api=True, render_mode=True)
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()
    # I just use truncate because it's recommended by Gym
    # However, you may not need it
    # It signifies whether the game is running for more than 100000 steps
    observation, reward, done, truncate, 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

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

Uploaded Source

Built Distribution

snake_gym_grid-0.0.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snake_gym_grid-0.0.2.tar.gz
  • Upload date:
  • Size: 4.4 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.0.2.tar.gz
Algorithm Hash digest
SHA256 ff05418c3a8ace7392fac6fb9fc7c7743148e62ab5819d326d3d5329ab5d4230
MD5 45b8ffa9af737f7140e7938faaed6fc1
BLAKE2b-256 19173bca831b42ac564e044d242f4cd84d5a26adbfc7fc134a83a9e10e34d449

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for snake_gym_grid-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 676826246e17cda7292f11d38bcf757a96b08269df3b29770b6ce94a196102fc
MD5 d8fdf92fc51ec5008438ffe71b312f31
BLAKE2b-256 a3234af626e761a8d493020e8aab97abf2c82fe540e9a0e30d7534394dbd47ee

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