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", new_step_api=True, render_mode="human")
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.6.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: snake_gym_grid-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 62369fe142dc6c95d90696be4c0cee866b86e0f2dcdcd485dcdea9209870f247
MD5 501cb6527d8ada5a48e09b8623efa8a8
BLAKE2b-256 2afbc812c2bf8881a8aa843a480162eea178b9adbbf121147992097fbe022b44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for snake_gym_grid-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c68c93d7e135a478f77471e8bb1fab3b9090ef7018e94d593572e73ebf345646
MD5 82ee5fc4defc05fbd2f499a06958c5ec
BLAKE2b-256 65bd5cba31a5106d3c395e5d301fb78d9d0c9dc608f96eca9d2879bf596258ac

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