cshogi.gym_shogi.envs package

Submodules

cshogi.gym_shogi.envs.shogi_env module

class cshogi.gym_shogi.envs.shogi_env.ShogiEnv

Bases: Env

A Shogi environment that simulates the game of Shogi.

This environment conforms to the OpenAI Gym interface.

metadata: Dict[str, Any] = {'render.modes': ['human', 'svg', 'ansi', 'sfen']}
render(mode='human')

Render the current game state in the specified mode.

Parameters:

mode (str) – The rendering mode (‘human’, ‘svg’, ‘ansi’, or ‘sfen’). Default is ‘human’.

Returns:

An instance of Board if rendering in ‘human’ mode, an SVG if rendering in ‘svg’ mode, otherwise a string.

Return type:

Board or SvgWrapper or str

reset(sfen=None, hcp=None)

Reset the game environment to an initial state, or a state specified by SFEN or HCP.

Parameters:
  • sfen (str, optional) – An SFEN string representing the desired initial board state. Optional.

  • hcp (np.ndarray, optional) – A HCP representing the desired initial board state. Optional.

Returns:

The reset board.

Return type:

cshogi.Board

step(move)

Advance the game by making the specified move.

Parameters:

move (int) – The move to be made.

Returns:

A tuple containing the reward (float), done flag (bool), and draw status (bool or None).

Return type:

tuple

cshogi.gym_shogi.envs.shogi_vec_env module

class cshogi.gym_shogi.envs.shogi_vec_env.ShogiVecEnv(num_envs)

Bases: object

A vectorized Shogi environment that can manage multiple instances of Shogi games simultaneously.

Parameters:

num_envs (int) – The number of environments to manage.

metadata = {'render.modes': ['sfen']}
render(mode='sfen')

Render the current game state in the specified mode for all environments.

Parameters:

mode (str) – The rendering mode (‘sfen’). Default is ‘sfen’.

Returns:

A list of string representations of the environments.

Return type:

list of str

reset()

Reset all the environments to their initial state.

step(moves)

Advance the games by making the specified moves in all environments.

Parameters:

moves (list of int) – A list of moves to be made, one for each environment.

Returns:

A tuple containing lists of rewards, done flags, and draw statuses for each environment.

Return type:

tuple of (list of float, list of bool, list of bool or None)

Module contents

class cshogi.gym_shogi.envs.ShogiEnv

Bases: Env

A Shogi environment that simulates the game of Shogi.

This environment conforms to the OpenAI Gym interface.

action_space: spaces.Space[ActType]
metadata: Dict[str, Any] = {'render.modes': ['human', 'svg', 'ansi', 'sfen']}
observation_space: spaces.Space[ObsType]
render(mode='human')

Render the current game state in the specified mode.

Parameters:

mode (str) – The rendering mode (‘human’, ‘svg’, ‘ansi’, or ‘sfen’). Default is ‘human’.

Returns:

An instance of Board if rendering in ‘human’ mode, an SVG if rendering in ‘svg’ mode, otherwise a string.

Return type:

Board or SvgWrapper or str

reset(sfen=None, hcp=None)

Reset the game environment to an initial state, or a state specified by SFEN or HCP.

Parameters:
  • sfen (str, optional) – An SFEN string representing the desired initial board state. Optional.

  • hcp (np.ndarray, optional) – A HCP representing the desired initial board state. Optional.

Returns:

The reset board.

Return type:

cshogi.Board

step(move)

Advance the game by making the specified move.

Parameters:

move (int) – The move to be made.

Returns:

A tuple containing the reward (float), done flag (bool), and draw status (bool or None).

Return type:

tuple

class cshogi.gym_shogi.envs.ShogiVecEnv(num_envs)

Bases: object

A vectorized Shogi environment that can manage multiple instances of Shogi games simultaneously.

Parameters:

num_envs (int) – The number of environments to manage.

metadata = {'render.modes': ['sfen']}
render(mode='sfen')

Render the current game state in the specified mode for all environments.

Parameters:

mode (str) – The rendering mode (‘sfen’). Default is ‘sfen’.

Returns:

A list of string representations of the environments.

Return type:

list of str

reset()

Reset all the environments to their initial state.

step(moves)

Advance the games by making the specified moves in all environments.

Parameters:

moves (list of int) – A list of moves to be made, one for each environment.

Returns:

A tuple containing lists of rewards, done flags, and draw statuses for each environment.

Return type:

tuple of (list of float, list of bool, list of bool or None)