MiniHex
An OpenAI gym environment that allows an agent to play the game of Hex. The aim for this environment is to be lean and have fast rollouts, as well as, variable board size. With random actions it currently achieves ~340 games per second in a 11x11 grid (original size) on a single CPU (Intel Xenon E3-1230 @3.3GHz).
Hex is a two player game and needs to be converted into a "single agent
environment" to fit into the gym framework. We achieve this by requiring a
opponent_policy at creation time. Each move of the agent will be immediately
followed by a move of the opponent. This is a function that takes as input a
board state and outputs an action.
Installation
pip install minihex
Editable installation (if you wish to tweak the environment):
git clone https://github.com/FirefoxMetzger/minihex.git
pip install -e minihex/
Minimal Working Example
import gym
import minihex
env = gym.make("hex-v0",
opponent_policy=minihex.random_policy,
board_size=11)
state, info = env.reset()
done = False
while not done:
board, player = state
action = minihex.random_policy(board, player, info)
state, reward, done, info = env.step(action)
env.render()
if reward == -1:
print("Player (Black) Lost")
elif reward == 1:
print("Player (Black) Won")
else:
print("Draw")
Debug Mode
If the environment is instantiated with debug=True each step will check if a
valid action is provided, and an IndexError will be raised if an invalid one
is provided. This is very useful while writing agents, e.g., if the agent
maintains it's own belief over the environment and may request invalid actions.
When evaluating/running at scale, however, this check can cause significant
slowdown. Hence, it is only performed if explicitly requested.
Limitations
Currently the enviornment is missing the following features to go to version 1.0
- The swap action that is used to mitigate the disadvantage of playing second.
- RGB rendering mode
- add environment to pypi
- no surrender action
Bugs and Contributing
If you encounter problems, check the GitHub issue page or open a new issue there.
Metadata
Release files for minihex 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| minihex-1.0.1.tar.gz | 4.8 kB | Without provenance | Details for minihex-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| minihex-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for minihex-1.0.1-py3-none-any.whl |
Total release size: 10.6 kB
Release files / minihex-1.0.1.tar.gz
| Download URL | minihex-1.0.1.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be0f3fb98260e80b80a3b773d5b72eab29b009061b5214faa40e3cd9256f84a3
|
|
BLAKE2b-256 checksum How to use checksums |
d13f0fc8b958bca58a69643865afa81f92efb518bd554789ea9a25876f8fa08d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0
|
Release files / minihex-1.0.1-py3-none-any.whl
| Download URL | minihex-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4249c0d049445abaf0e1893acd6077bd2de8ca74393899bad241691972e90ebe
|
|
BLAKE2b-256 checksum How to use checksums |
ab1708225b23600ff23e9797031e20ad4dd975cdc2d03199dfa5bea80e19b254
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0
|
Security for minihex 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.