Game Environments¶
-
class
AlphaZero.env.go.
GameState
(size=19, komi=7.5, enforce_superko=False, history_length=8)¶ State of a game of Go and some basic functions to interact with it
-
get_group
(position)¶ Get the group of connected same-color stones to the given position.
Parameters: - position – a tuple of (x, y), x being the column index of the starting position of the search,
- being the row index of the starting position of the search (y) –
Returns: a set of tuples consist of (x, y)s which are the same-color cluster, which contains the input single position. len(group) is size of the cluster, can be large.
Return type: set
-
get_groups_around
(position)¶ returns a list of the unique groups adjacent to position ‘unique’ means that, for example in this position:
. . . . . . B W . . . W W . . . . . . . . . . . .
only the one white group would be returned on get_groups_around((1,1))
Parameters: position – a tuple of (x, y) Returns: a list of the unique groups adjacent to position. Return type: list
-
copy
()¶ Gets a copy of this Game state
Returns: a copy of this Game state Return type: AlphaZero.env.go.GameState
-
is_suicide
(action)¶ Parameters: action – a tuple of (x, y) Returns: return true if having current_player play at <action> would be suicide Return type: bool
-
is_positional_superko
(action)¶ Find all actions that the current_player has done in the past, taking into account the fact that history starts with BLACK when there are no handicaps or with WHITE when there are. :param action: a tuple of (x, y)
Returns: if the move is positional superko. Return type: bool
-
is_legal
(action)¶ Determines if the given action (x,y) is a legal move :param action: a tuple of (x, y)
Returns: if the move is legal. Return type: bool
-
is_eyeish
(position, owner)¶ Parameters: - position – a tuple of (x, y)
- owner – the color
Returns: whether the position is empty and is surrounded by all stones of ‘owner’
Return type: bool
-
is_eye
(position, owner, stack=[])¶ returns whether the position is a true eye of ‘owner’ Requires a recursive call; empty spaces diagonal to ‘position’ are fine as long as they themselves are eyes
-
get_legal_moves
(include_eyes=True)¶ Parameters: include_eyes – whether to include eyes in legal moves Returns: a list of tuples. Return type: list
-
get_winner
()¶ Calculate score of board state and return player ID (1, -1, or 0 for tie) corresponding to winner. Uses ‘Area scoring’.
Returns: the color of the winner. Return type: int
-
place_handicaps
(actions)¶ Place handicap stones of black. :param actions: a list of tuples of (x, y)
Returns: None
-
place_handicap_stone
(action, color=1)¶ Place a handicap stone of the specified color. :param action: a tuple of (x, y) :param color: the color of the move
Returns: None
-
get_current_player
()¶ Returns: the color of the player who will make the next move. Return type: int
-
do_move
(action, color=None)¶ Play stone at action=(x,y). If color is not specified, current_player is used If it is a legal move, current_player switches to the opposite color If not, an IllegalMove exception is raised
Parameters: - action – a tuple of (x, y)
- color – the color of the move
Returns: if it is the end of game.
Return type: bool
-
transform
(transform_id)¶ - Transform the current board and the history boards according to D(4).
- Caution: self.history (action history) is not modified, thus this function should ONLY be used for state evaluation.
Parameters: transform_id – integer in range [0, 7] Returns: None
-
-
exception
AlphaZero.env.go.
IllegalMove
¶
-
class
AlphaZero.env.mnk.
GameState
(history_length=8)¶ Game state of mnk Game.
-
copy
()¶ Gets a copy of this Game state
Returns: a copy of this Game state Return type: AlphaZero.env.mnk.GameState
-
is_legal
(action)¶ Determines if the given action (x,y) is a legal move :param action: a tuple of (x, y)
Returns: if the move is legal. Return type: bool
-
get_legal_moves
()¶ Returns: a list of legal moves. Return type: list
-
get_winner
()¶ Returns: The winner, None if the game is not ended yet
-
do_move
(action, color=None)¶ Play stone at action=(x,y). If color is not specified, current_player is used If it is a legal move, current_player switches to the opposite color If not, an IllegalMove exception is raised
Parameters: - action – a tuple of (x, y)
- color – the color of the move
Returns: if it is the end of game.
Return type: bool
-
transform
(transform_id)¶ - Transform the current board and the history boards according to D(4).
- Caution: self.history (action history) is not modified, thus this function should ONLY be used for state evaluation.
Parameters: transform_id – integer in range [0, 7] Returns: None
-
-
exception
AlphaZero.env.mnk.
IllegalMove
¶
-
class
AlphaZero.env.reversi.
GameState
(size=8, history_length=8)¶ Game state of Reversi Game.
-
copy
()¶ Gets a copy of this Game state
Returns: a copy of this Game state Return type: AlphaZero.env.reversi.GameState
-
is_legal
(action)¶ Determines if the given action (x,y) is a legal move :param action: a tuple of (x, y)
Returns: if the move is legal. Return type: bool
-
get_legal_moves
()¶ - This function is infrequently used, therefore not optimized.
- Checks all non-pass moves
Returns: a list of legal moves Return type: list
-
get_winner
()¶ Counts the stones on the board, assumes the game is ended
Returns: The winner, None if the game is not ended yet Return type: int
-
do_move
(action, color=None)¶ Play stone at action=(x,y). If color is not specified, current_player is used If it is a legal move, current_player switches to the opposite color If not, an IllegalMove exception is raised
Parameters: - action – a tuple of (x, y)
- color – the color of the move
Returns: if it is the end of game.
Return type: bool
-
transform
(transform_id)¶ - Transform the current board and the history boards according to D(4).
- Caution: self.history (action history) is not modified, thus this function should ONLY be used for state evaluation.
Parameters: transform_id – integer in range [0, 7] Returns: None
-
-
exception
AlphaZero.env.reversi.
IllegalMove
¶