2-player zero-sum board game extension for OpenAI Gym.
Project description
boardgame2
boardgame2 is an extension of OpenAI Gym that implements multiple two-player zero-sum 2-dimension board games, such as TicTacToe, Gomuko, and Reversi.
Environments
Reversi-v0KInARow-v0, as well asGomuku-v0andTicTacToe-v0Go-v0(Experimental)
Install
pip install --upgrade boardgame2
Usage
Create a Game
import gym
import boardgame2
env = gym.make('TicTacToe-v0')
env = gym.make('Gomuku-v0')
env = gym.make('KInARow-v0', board_shape=5, target_length=4)
env = gym.make('KInARow-v0', board_shape=(3, 5), target_length=4)
env = gym.make('Reversi-v0')
env = gym.make('Reversi-v0', board_shape=6)
env = gym.make('Go-v0')
Play a Game
import gym
import boardgame2
env = gym.make('TicTacToe-v0')
print('observation space = {}'.format(env.observation_space))
print('action space = {}'.format(env.action_space))
observation = env.reset()
while True:
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
break
env.close()
API
Constants
boardgame2.BLACK
The 1st player.
boardgame2.WHITE
The 2nd player.
boardgame2.EMPTY
Neither of the two players.
Functions
boardgame2.strfboard
strfboard(board:np.array, render_characters:str='+ox', end:str='\n') -> str
Format a board as a string
boardgame2.is_index
is_index(board:np.array, location:np.array) -> bool
Check whether a location is a valid index for the board
boardgame2.extend_board
extend_board(board:np.array)
Get the rotations of the board. Only valid for square board.
Classes
boardgame2.BoardGameEnv
The base class of all board game environment.
__init__(board_shape, illegal_action_mode:str='resign', render_characters:str='+ox', allow_pass:bool=True) -> boardgame2.BoardGameEnv
Constructor.
board_shape can be either an int or (int, int).
seed(seed=None) -> NoneType
See gym.Env.seed().
reset() -> tuple
See gym.Env.reset().
observation is in the form of (np.array, int).
step(action:np.array) -> tuple, float, bool, dict
See gym.Env.step().
render(mode:str='human')
See gym.Env.render().
is_valid(state:tuple, action:np.array) -> bool
Check whether the action is valid for current state.
get_valid(state:tuple) -> np.array
Get all valid locations for the current state.
has_valid(state:tuple) -> bool
Check whether there are valid locations for current state.
get_winner(state:tuple)
Check whether the game has ended. If so, who is the winner.
get_next_state(state:tuple, action:np.array) -> tuple
Get the next state.
next_step(state:tuple, action:np.array) -> tuple, float, bool, dict
Get the next observation, reward, done, and info. Similar to gym.Env.step().
PASS
Intend to skip, as a predefined constant action.
RESIGN
Intend to resign, as a predefined constant action.
boardgame2.KInARowEnv (registered as KInARow-v0, as well as Gomuku-v0 and TicTacToe-v0)
__init__(board_shape, target_length:int=3, illegal_action_mode:str='pass', render_characters:str='+ox') -> boardgame2.KInARowEnv
boardgame2.ReversiEnv (registered as Reversi-v0)
__init__(board_shape, render_characters:str='+ox') -> boardgame2.ReversiEnv
boardgame2.GoEnv (registered as Go-v0, Not fully implemented)
__init__(board_shape, komi:float=0., allow_suicide:bool=False, illegal_action_mode:str='pass', render_characters:str='+ox') -> boardgame2.GoEnv
Project details
Release history Release notifications | RSS feed
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 boardgame2-0.0.5.tar.gz.
File metadata
- Download URL: boardgame2-0.0.5.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
510fd108fd46994ae8fdd10d4d89e6a4136a9205e3a117c8597ef369f1f8c62d
|
|
| MD5 |
fd7f6b2b62e8c53babf0f0e828d1d122
|
|
| BLAKE2b-256 |
2376d11288e665f2f6aeb56b592b30540c9c8cf857c9db77e708d08d47e0b354
|
File details
Details for the file boardgame2-0.0.5-py3-none-any.whl.
File metadata
- Download URL: boardgame2-0.0.5-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12de35518ac6c51617e06296052b477d5bbfe46529e63536283d90af6f2aebb3
|
|
| MD5 |
bb9a897c9bbb16281e13ed8642fa528a
|
|
| BLAKE2b-256 |
2b067b1b31862412989bf68b9554bb5ea85f36e865180442865fc0422642c805
|