Skip to main content

A simple snake environment with 18 states and 4 actions

Project description

Snake Environment

The Snake Environment is a Python package designed for training machine learning models using reinforcement learning techniques. This environment mimics the OpenAI Gym interface, providing a familiar setup for those who are accustomed to using Gym for developing and testing AI models.

Features

  • Game Environment: Built using Pygame, this environment allows for on-screen rendering of the snake game, which is useful for visual feedback while training models.
  • Compatibility with AI Training Workflows: The SnakeGame class features a step function that returns a tuple of (done, reward, score, state), similar to environments found in OpenAI Gym.
  • State Representation: The state is represented as a numpy array with 18 dimensions, providing comprehensive information about the game environment at any given step.
  • Utility Methods: Includes reset and state_dimensions methods for resetting the game state and retrieving the dimensions of the state space, respectively.

Installation

To install the Snake Environment, you can use pip:

pip install snake_environment

Usage

from snake_environment import SnakeGame

# Initialize the environment
env = SnakeGame(render=True)  # Set render=False if you do not need to visualize the training process

# Start a new episode
state = env.reset()

# Loop until the episode is finished
done = False
while not done:
    action = model.predict(state)  # Replace this with your model's prediction method
    next_state, done, reward, score = env.step(action)
    state = next_state

# Get the dimensions of the state for input layer configuration or debugging
state_dim = env.state_dimensions
print("State dimensions:", state_dim)

Contributions

Contributions are welcome! If you'd like to improve the Snake Environment, please fork this repository and submit a pull request with your proposed changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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_environment-0.2.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snake_environment-0.2.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file snake_environment-0.2.2.tar.gz.

File metadata

  • Download URL: snake_environment-0.2.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for snake_environment-0.2.2.tar.gz
Algorithm Hash digest
SHA256 8ad547bf6bd3c79aabf8c0f8a87d5854f40b8d13e6e754ea4afdd4531fac268f
MD5 a38d70fad5c1402445020242a59fb7af
BLAKE2b-256 d750767cff8197761e25102f3884a4eecfcbccf47e865fabdcb1f54b1ccdd107

See more details on using hashes here.

File details

Details for the file snake_environment-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for snake_environment-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d89e2e5aa8db65cec020a2c2cee1385ce0dfe6726e93cea37c6dbbfc81840bd7
MD5 85a753fea2f9592befccd606cbbbafd4
BLAKE2b-256 f053543c2a9ab1a88f2c17159a1037d4b0bdb23c09bfc0edf01b9b269fcd29c9

See more details on using hashes here.

Supported by

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