OpenAI Gym environment for Chess, using the game engine of the python-chess module
Project description
Chess Gym
Gym Chess is an environment for reinforcement learning with the OpenAI gym module.
Installation
-
Install OpenAI Gym and its dependencies.
pip install gym -
Download and install
chess_gym:
git clone https://github.com/Ryan-Rudes/chess-gym.git
cd chess-gym
python setup.py install
Or, you can usepip(you may view the package here):
pip install chess-gym
Environments
Example
You can use the standard Chess-v0 environment as so:
import gym
import chess_gym
env = gym.make("Chess-v0")
env.reset()
terminal = False
while not terminal:
action = env.action_space.sample()
observation, reward, terminal, info = env.step(action)
env.render()
env.close()
There is also an environment for the Chess960 variant; its identifier is Chess960-v0
Further Info
This environment will return 0 reward until the game has reached a terminal state. In the case of a draw, it will still return 0 reward. Otherwise, the reward will be either 1 or -1, depending upon the winning player.
observation, reward, terminal, info = env.step(action)
Here, info will be a dictionary containing the following information pertaining to the board configuration and game state:
turn: The side to move (chess.WHITEorchess.BLACK).castling_rights: Bitmask of the rooks with castling rights.fullmove_number: Counts move pairs. Starts at 1 and is incremented after every move of the black side.halfmove_clock: The number of half-moves since the last capture or pawn move.promoted: A bitmask of pieces that have been promoted.ep_square: The potential en passant square on the third or sixth rank orNone.
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
File details
Details for the file chess_gym-0.0.5.tar.gz.
File metadata
- Download URL: chess_gym-0.0.5.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.11.4 pkginfo/1.8.2 requests/2.28.1 requests-toolbelt/0.9.1 tqdm/4.64.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aee5894ad72dd2a8e19759515e523e7e74ee0f02a96e4374bf85f935302e71d4
|
|
| MD5 |
cf42eb313dd08d996b002a8e99d7c521
|
|
| BLAKE2b-256 |
b4c57a1c69950d6201fc967fafa3c5b1bc7493feb49b79d468aa7befe7552600
|