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
SnakeGameclass features astepfunction that returns a tuple of (state, done, reward, score), 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
resetandstate_dimensionsmethods 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
Example 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)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snake_environment-0.3.0.tar.gz.
File metadata
- Download URL: snake_environment-0.3.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df2a98d1e40bab4c4ceec6d88603fbf78164bf0831eba3c158b4a1ad351f4057
|
|
| MD5 |
f0a5dac8d981848ab89abeef2d910ef3
|
|
| BLAKE2b-256 |
f4caf4826c6ec4261f5e01379dbf0f2e447183e12de1f91bc2f0dc941a0fda2c
|
File details
Details for the file snake_environment-0.3.0-py3-none-any.whl.
File metadata
- Download URL: snake_environment-0.3.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94c9e7aa12e51675be8fa350c74e260af61cd46d73cb6c5903355b605ed3e5e7
|
|
| MD5 |
118e345d6170e4fa171d302697d30fb2
|
|
| BLAKE2b-256 |
624b556fb0e310af690ddaca17b2c07dc6e61f88034f29a87e9fd82fba173de0
|