Skip to main content

Gym for the Snake Game

Project description

1. pysnakegym

The pysnakegym project provides a gym environment for developing reinforcement

learning algorithms for the game of snake.

2. Installation

To get started, you need to have Python 3.6+ installed. The pysnakegym package

can simply be installed with pip.

pip install pysnakegym

3. How to use

Below is an example of how to use the gym. The interface is an MDP object representing

a Markov Decision Process (MDP) of the game of snake.

from pysnakegym.mdp import mdp



state, reward, done = mdp.reset()



while not done:

    state_, reward, done = mdp.step(action=choose_action(state))

    state = state_

The reset method of the mdp returns a triplet consisting of the following:

  • state (numpy array): the start state of the MDP. Depending on the state representation

the shape and size will vary.

  • reward (float): the initial reward of the MDP.

  • done (bool): whether the game is finished or not. Always returns false for the reset

method.


The step method of the mdp takes an action and returns a triplet consisting of the following:

  • state (numpy array): the state of the MDP that was observed after the step

    was taken. Depending on the state representation the shape and size will vary.

  • reward (float): the reward observed after the step has been taken.

  • done (bool): whether the game is finished or not. Returns true if state is a

final state, false if it is not.

The step method is a representation of the agent-environment interaction that

constitutes an MDP. The agent chooses an action to be taken in the environment and in return observes

a new state and a reward.

4. State Representation

The state that the snake receives as input can be represented in many different ways. When choosing

a state representation, one must make a tradeoff between keeping the state lightweight so that

the neural network is not too complex and encoding enough information so that the snake is able

to make the right decisions for the right state. Abstracting away information means that

the set of possible states the snake can find itself in becomes smaller, however it also means

that some granularity is lost. Likewise, encoding unnecessary information blows up the set of

possible states that the snake will have to learn the correct output for.

4.1 Choosing Necessary Information

When selecting the information that should be included in the state representation it is helpful to think

how you as a human would play the game. Things you would want to know are the direction the snake

is currently moving in, where the obstacles are relative to the head of the snake, and where the

food is relative to the snake's head.

4.2 Available States

There are a number of state representations available to choose from:

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

pysnakegym-0.0.10.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

pysnakegym-0.0.10-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file pysnakegym-0.0.10.tar.gz.

File metadata

  • Download URL: pysnakegym-0.0.10.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.13

File hashes

Hashes for pysnakegym-0.0.10.tar.gz
Algorithm Hash digest
SHA256 f6500052b01a27d27f37c289c141b83efa8ec85e9e35723d813321c2d788ee9c
MD5 36dd4ed589dba3382a550b1a5a5666ec
BLAKE2b-256 abff37f00dd386b9b316245d6e6e9f2b28418c5ee6a4432d29c29d0f4594a146

See more details on using hashes here.

File details

Details for the file pysnakegym-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: pysnakegym-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.13

File hashes

Hashes for pysnakegym-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 568272d5facdce9bb595deb802d5e1aa006efbe76985488dbffd4355228cb0cc
MD5 cedaeb04c419b0147b3d0f1eeaaf8ef2
BLAKE2b-256 d3c9af2f6f8dd535fc53cdf8aaa75f2300250e30dd2286d2ad16bf66bd8a1bae

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