reconchess API¶
Types¶
-
class
reconchess.
Square
¶ A type alias for an integer.
See
chess.A1
,chess.B1
, …, andchess.H8
for specifying specific squares.See
chess.SQUARES
for referencing all squares.
-
class
reconchess.
Color
¶ A type alias for a boolean.
See
chess.WHITE
andchess.BLACK
.chess.WHITE
= Truechess.BLACK
= False
-
class
reconchess.
PieceType
¶ A type alias for an integer.
See
chess.PAWN
,chess.KNIGHT
,chess.BISHOP
,chess.ROOK
,chess.QUEEN
,chess.KING
for specifying specific piece typesSee
chess.PIECE_TYPES
for referencing all piece types.
-
class
reconchess.
WinReason
¶ The reason the game ended
-
KING_CAPTURE
= 1¶ The game ended because one player captured the other’s king.
-
TIMEOUT
= 2¶ The game ended because one player ran out of time.
-
RESIGN
= 3¶ The game ended because one player resigned.
-
TURN_LIMIT
= 4¶ The game ended because it exceeded the full turn limit.
-
MOVE_LIMIT
= 5¶ The game ended because it exceeded the reversible move limit.
-
Player¶
-
class
reconchess.
Player
¶ Base class of a player of Recon Chess. Implementation of a player is done by sub classing this class, and implementing each of the methods detailed below. For examples see examples.
The order in which each of the methods are called looks roughly like this:
handle_game_start()
handle_opponent_move_result()
choose_sense()
handle_sense_result()
choose_move()
handle_move_result()
handle_game_end()
Note that the
handle_game_start()
andhandle_game_end()
methods are only called at the start and the end of the game respectively. The rest are called repeatedly for each of your turns.-
handle_game_start
(color: bool, board: chess.Board, opponent_name: str)¶ Provides a place to initialize game wide structures like boards, and initialize data that depends on what color you are playing as.
Called when the game starts.
The board is provided to allow starting a game from different board positions.
Parameters: - color – The color that you are playing as. Either
chess.WHITE
orchess.BLACK
. - board – The initial board of the game. See
chess.Board
. - opponent_name – The name of your opponent.
- color – The color that you are playing as. Either
-
handle_opponent_move_result
(captured_my_piece: bool, capture_square: Optional[int])¶ Provides information about what happened on the opponents turn.
Called at the start of your turn.
Example implementation:
def handle_opponent_move_result(self, captured_my_piece: bool, capture_square: Optional[Square]): if captured_my_piece: self.board.remove_piece_at(capture_square)
Parameters: - captured_my_piece – If the opponent captured one of your pieces, then True, otherwise False.
- capture_square – If a capture occurred, then the
Square
your piece was captured on, otherwise None.
-
choose_sense
(sense_actions: List[int], move_actions: List[chess.Move], seconds_left: float) → Optional[int]¶ The method to implement your sensing strategy. The chosen sensing action should be returned from this function. I.e. the value returned is the square at the center of the 3x3 sensing area you want to sense. The returned square must be one of the squares in the sense_actions parameter.
You can pass instead of sensing by returning None from this function.
Move actions are provided through move_actions in case you want to sense based on a potential move.
Called after
handle_opponent_move_result()
.Example implementation:
def choose_sense(self, sense_actions: List[Square], move_actions: List[chess.Move], seconds_left: float) -> Square: return random.choice(sense_actions)
Parameters: - sense_actions – A
list
containing the valid squares to sense over. - move_actions – A
list
containing the valid moves that can be returned inchoose_move()
. - seconds_left – The time in seconds you have left to use in the game.
Returns: a
Square
that is the center of the 3x3 sensing area you want to get information about.- sense_actions – A
-
handle_sense_result
(sense_result: List[Tuple[int, Optional[chess.Piece]]])¶ Provides the result of the sensing action. Each element in sense_result is a square and the corresponding
chess.Piece
found on that square. If there is no piece on the square, then the piece will be None.Called after
choose_sense()
.Example implementation:
def handle_sense_result(self, sense_result: List[Tuple[Square, Optional[chess.Piece]]]): for square, piece in sense_result: if piece is None: self.board.remove_piece_at(square) else: self.board.set_piece_at(square, piece)
Parameters: sense_result – The result of the sense. A list of Square
and an optionalchess.Piece
.
-
choose_move
(move_actions: List[chess.Move], seconds_left: float) → Optional[chess.Move]¶ The method to implement your movement strategy. The chosen movement action should be returned from this function. I.e. the value returned is the move to make. The returned move must be one of the moves in the move_actions parameter.
The pass move is legal, and is executed by returning None from this method.
Called after
handle_sense_result()
.Example implementation:
def choose_move(self, move_actions: List[chess.Move], seconds_left: float) -> Optional[chess.Move]: return random.choice(move_actions)
Parameters: - move_actions – A list containing the valid
chess.Move
you can choose. - seconds_left – The time in seconds you have left to use in the game.
Returns: The
chess.Move
to make.- move_actions – A list containing the valid
-
handle_move_result
(requested_move: Optional[chess.Move], taken_move: Optional[chess.Move], captured_opponent_piece: bool, capture_square: Optional[int])¶ Provides the result of the movement action. The requested_move is the move returned from
choose_move()
, and is provided for ease of use. taken_move is the move that was actually performed. Note that taken_move, can be different from requested_move, due to the uncertainty aspect.Called after
choose_move()
.Example implementation:
def handle_move_result(self, requested_move: chess.Move, taken_move: chess.Move, captured_opponent_piece: bool, capture_square: Optional[Square]): if taken_move is not None: self.board.push(taken_move)
Note: In the case of playing games on a server, this method is invoked during your opponents turn. This means in most cases this method will not use your play time. However if the opponent finishes their turn before this method completes, then time will be counted against you.
Parameters: - requested_move – The
chess.Move
you requested inchoose_move()
. - taken_move – The
chess.Move
that was actually applied by the game if it was a valid move, otherwise None. - captured_opponent_piece – If taken_move resulted in a capture, then True, otherwise False.
- capture_square – If a capture occurred, then the
Square
that the opponent piece was taken on, otherwise None.
- requested_move – The
-
handle_game_end
(winner_color: Optional[bool], win_reason: Optional[reconchess.types.WinReason], game_history: reconchess.history.GameHistory)¶ Provides the results of the game when it ends. You can use this for post processing the results of the game.
Parameters: - winner_color – If the game was a draw, then None, otherwise, the color of the player who won the game.
- win_reason – If the game was a draw, then None, otherwise the reason the game ended specified as
WinReason
- game_history –
GameHistory
object for the game, from which you can get the actions each side has taken over the course of the game.
-
reconchess.
load_player
(source_path: str) → Tuple[str, Type[reconchess.player.Player]]¶ Loads a subclass of the Player class that is contained in a python source file or python module. There should only be 1 such subclass in the file or module. If there are more than 1 subclasses, then you have to define a function named get_player in the same module that returns the subclass to use.
Example of single class definition:
# this will import fine class MyBot(Player): ...
Example of multiple class definition:
class MyBot1(Player): ... class MyBot2(Player): ... # need to define this function! def get_player(): return MyBot1
Example of another situation where you may need to define get_player:
from my_helper_module import MyPlayerBaseClass class MyBot1(MyPlayerBaseClass): ... # you need to define this because both MyBot1 and MyPlayerBaseClass are subclasses of Player def get_player(): return MyBot1
Example usage:
name, cls = load_player('my_player.py') player = cls() name, cls = load_player('reconchess.bots.random_bot') player = cls()
Parameters: source_path – the path to the source file to load Returns: Tuple where the first element is the name of the loaded class, and the second element is the class type
Game¶
-
class
reconchess.
Game
¶ Abstract class that represents an instantiation of a Reconnaissance Chess Game. See
LocalGame
andRemoteGame
for implementations.-
move_actions
() → List[chess.Move]¶ Returns: List of chess.Move
that the player can choose for move phase.
-
get_seconds_left
() → float¶ Returns: float indicating the seconds the player has left to play.
-
start
()¶ Starts the game and the timers for each player.
-
opponent_move_results
() → Optional[int]¶ Returns: Square
where opponent captured a piece last turn if they did, otherwise None.
-
sense
(square: Optional[int]) → List[Tuple[int, Optional[chess.Piece]]]¶ Execute a sense action and get the sense result.
An example result returned from sensing B7 at the beginning of the game:
[ (A8, Piece(ROOK, BLACK)), (B8, Piece(KNIGHT, BLACK)), (C8, Piece(BISHOP, BLACK)), (A7, Piece(PAWN, BLACK)), (B7, Piece(PAWN, BLACK)), (C7, Piece(PAWN, BLACK)), (A6, None), (B6, None), (C8, None) ]
Parameters: square – The Square
to sense.Returns: A list of tuples, where each tuple contains a Square
in the sense, and if there was a piece on the square, then the correspondingchess.Piece
, otherwise None.
-
move
(requested_move: Optional[chess.Move]) → Tuple[Optional[chess.Move], Optional[chess.Move], Optional[int]]¶ Execute a move action and get the result.
Parameters: requested_move – The chess.Move
to execute.Returns: A tuple containing the requested chess.Move
, the takenchess.Move
, and theSquare
that a capture occurred on if one occurred.
-
end_turn
()¶ End the current player’s turn.
-
is_over
() → bool¶ The game is over if either player has run out of time, or if either player’s King has been captured.
This will always return True after
end()
has been called.Returns: Returns True if the game is over, otherwise False.
-
get_winner_color
() → Optional[bool]¶ Returns the color of the player who won the game. If the game is not over, or is over but does not have a winner (i.e.
end()
has been called), then this will return None.Returns: Color
of the winner if the game has ended and has a winner, otherwise None.
-
get_win_reason
() → Optional[reconchess.types.WinReason]¶ Returns the reason the player who won won the game. If the game is not over, or is over but does not have a winner (i.e.
end()
has been called), then this will return None.Returns: WinReason
of the winner if the game has ended and has a winner, otherwise None.
-
get_game_history
() → Optional[reconchess.history.GameHistory]¶ Get the history of the game.
Returns: GameHistory
if the game is over, otherwise None.
-
-
class
reconchess.
LocalGame
(seconds_per_player: Optional[float] = 900, seconds_increment: Optional[float] = 5, reversible_moves_limit: Optional[int] = 100, full_turn_limit: Optional[int] = None)¶ The local implementation of
Game
. Used to run games locally instead of remotely via a server.-
__init__
(seconds_per_player: Optional[float] = 900, seconds_increment: Optional[float] = 5, reversible_moves_limit: Optional[int] = 100, full_turn_limit: Optional[int] = None)¶ Constructs the Game object
Parameters: - seconds_per_player – Initial clock limit for each player in seconds. Use None for unlimited. Default is 900.
- seconds_increment – Seconds added to a player’s clock limit on each turn. Will treat None as 0. Default is 5.
- reversible_moves_limit – Maximum number of moves without pawn moves or captures before game is a draw. Use None for unlimited. Default is 100 (a non-optional version of the “50-move rule”).
- full_turn_limit – Maximum number of full turns (both players move) before game is a draw. Use None for unlimited. Default is None.
-
GameHistory¶
-
class
reconchess.
Turn
(color: bool, turn_number: int)¶ The representation of a single turn in a game. Contains the color of the player who played this turn, as well as the number of turns the player has taken so far.
-
previous
¶ Returns: The :class: Turn that happens immediately before this, which is the other player’s previous turn.
-
-
class
reconchess.
GameHistory
¶ Implements method for processing and querying a Game.
Here are some example uses:
Extracting data to train a sensing policy to sense opponent:
opponent_moves = history.collect(history.taken_move, history.turns(not self.color)) target_senses = [move.to_square for move in opponent_moves]
Extracting data to train a movement policy:
for turn in history.turns(self.color): if history.has_move(turn): move = history.requested_move(turn) board = history.truth_board_before_move(turn) # do something with move and board...
Randomly sampling from the turns instead of using them in sequential order:
for turn in random.sample(history.turns(self.color), N): ...
Giving rewards based on validity of the move:
for turn in history.turns(self.color): if history.has_move(turn): if history.requested_move(turn) != history.taken_move(turn): reward = -1 else: reward = 1
Giving rewards for moving out of check:
for turn in history.turns(self.color): if history.has_move(turn): board_before = history.truth_board_before_move(turn) board_after = history.truth_board_after_move(turn) if board_before.is_check() and not board_after.is_check() reward = 1 else: reward = -1
-
save
(filename)¶ Save the game history to a json file.
Parameters: filename – The file to save to.
-
classmethod
from_file
(filename)¶ Parameters: filename – The json file to load the GameHistory
object from.Returns: The GameHistory
object that was originally saved to the file usingsave()
.
-
get_white_player_name
() → str¶ Get the name of white. :return: str
-
get_black_player_name
() → str¶ Get the name of black. :return: str
-
is_empty
() → bool¶ Get whether or not the game had any turns in it.
- Examples:
>>> history.is_empty() False
Returns: True if there are no turns to query in this object, False otherwise.
-
num_turns
(color: bool = None) → int¶ Get the number of turns taken in the game. Optionally specify the color of the player to get the number of turns for.
- Examples:
>>> history.num_turns() 9
>>> history.num_turns(WHITE) 5
>>> history.num_turns(BLACK) 4
Parameters: color – Optional player color indicating which player’s number of turns to return. Returns: The number of turns saved in this object. If color is specified, get the number of turns for that player.
-
turns
(color: bool = None, start=0, stop=inf) → Iterable[reconchess.history.Turn]¶ Get all the turns that happened in the game in order. Optionally specify a single player to get only that player’s turns.
- Examples:
>>> list(history.turns()) [Turn(WHITE, 0), Turn(BLACK, 0), Turn(WHITE, 1), ..., Turn(BLACK, 23)]
>>> list(history.turns(WHITE)) [Turn(WHITE, 0), Turn(WHITE, 1), ..., Turn(WHITE, 22)]
>>> list(history.turns(BLACK)) [Turn(BLACK, 0), Turn(BLACK, 1), ..., Turn(BLACK, 23)]
>>> list(history.turns(start=1)) [Turn(WHITE, 1), Turn(BLACK, 1), Turn(WHITE, 2), ..., Turn(BLACK, 23)]
>>> list(history.turns(stop=2)) [Turn(WHITE, 0), Turn(BLACK, 0), Turn(WHITE, 1), Turn(BLACK, 1)]
>>> list(history.turns(WHITE, stop=2)) [Turn(WHITE, 0), Turn(WHITE, 1)]
>>> list(history.turns(start=1, stop=2)) [Turn(WHITE, 1), Turn(BLACK, 1)]
Parameters: - color – Optional player color indicating which player’s turns to return.
- start – Optional starting turn number.
- stop – Optional stopping turn number.
Returns: An iterable of
Turn
objects that are in the same order as they occurred in the game. If color is specified, gets the turns only for that player.
-
is_first_turn
(turn: reconchess.history.Turn)¶ Checks whether turn is the first turn of the game.
- Examples:
>>> history.is_first_turn(Turn(BLACK, 0)) False
>>> history.is_first_turn(Turn(WHITE, 0)) True
Parameters: turn – the Turn
in question.Returns: True if turn is the first turn in the game, False otherwise.
-
first_turn
(color: bool = None) → reconchess.history.Turn¶ Gets the first turn of the game.
- Examples:
>>> history.first_turn() Turn(WHITE, 0)
>>> history.first_turn(WHITE) Turn(WHITE, 0)
>>> history.first_turn(BLACK) Turn(BLACK, 0)
Parameters: color – Optional color indicating which player’s first turn to return. Returns: The Turn
that is the first turn in the game.
-
is_last_turn
(turn: reconchess.history.Turn)¶ Checks whether turn is the last turn of the game.
- Examples:
>>> history.is_last_turn(Turn(BLACK, 23)) False
>>> history.is_last_turn(Turn(WHITE, 24)) True
Parameters: turn – the Turn
in question.Returns: True if turn is the last turn in the game, False otherwise.
-
last_turn
(color: bool = None) → reconchess.history.Turn¶ Gets the last turn of the game.
- Examples:
>>> history.last_turn() Turn(WHITE, 24)
>>> history.first_turn(WHITE) Turn(WHITE, 24)
>>> history.first_turn(BLACK) Turn(BLACK, 23)
Parameters: color – Optional color indicating which player’s last turn to return. Returns: The Turn
that is the last turn in the game.
-
get_winner_color
() → Optional[bool]¶ - Returns the color of the player who won the game. If the game is not over, or is over but does not have a winner
- then this will return None.
Returns: Color
of the winner if the game has ended and has a winner, otherwise None.
-
get_win_reason
() → Optional[reconchess.types.WinReason]¶ Returns the reason the player who won won the game. If the game is not over, or is over but does not have a winner, then this will return None.
Returns: WinReason
of the winner if the game has ended and has a winner, otherwise None.
-
has_sense
(turn: reconchess.history.Turn) → bool¶ Checks to see if the game has a sense action for the specified turn. The game may not if it ended because of timeout.
This intended use is to call this before calling
sense()
andsense_result()
, to verify that there is a sense before querying for it.- Examples:
>>> history.has_sense(Turn(WHITE, 0)) True
>>> history.has_sense(Turn(WHITE, 432)) False
Parameters: turn – The Turn
in question.Returns: True if there is a sense action, False otherwise.
-
sense
(turn: reconchess.history.Turn) → Optional[int]¶ Get the sense action on the given turn.
- Examples:
>>> history.sense(Turn(WHITE, 0)) E7
>>> history.sense(Turn(BLACK, 0)) E2
>>> history.sense(Turn(WHITE, 1)) None
Parameters: turn – The Turn
in question.Returns: The executed sense action as a Square
.
-
sense_result
(turn: reconchess.history.Turn) → List[Tuple[int, Optional[chess.Piece]]]¶ Get the result of the sense action on the given turn.
- Examples:
>>> history.sense(Turn(WHITE, 0)) B7 >>> history.sense_result(Turn(WHITE, 0)) [ (A8, Piece(ROOK, BLACK)), (B8, Piece(KNIGHT, BLACK)), (C8, Piece(BISHOP, BLACK)), (A7, Piece(PAWN, BLACK)), (B7, Piece(PAWN, BLACK)), (C7, Piece(PAWN, BLACK)), (A6, None), (B6, None), (C8, None) ] >>> history.sense(Turn(BLACK, 0)) None >>> history.sense_result(Turn(BLACK, 0)) []
Parameters: turn – The Turn
in question.Returns: The result of the executed sense action.
-
has_move
(turn: reconchess.history.Turn) → bool¶ Checks to see if the game has a move action for the specified turn. The game may not if it ended because of timeout.
This intended use is to call this before calling
requested_move()
,taken_move()
,capture_square()
, andmove_result()
to verify that there is a move before querying for it.- Examples:
>>> history.has_move(Turn(WHITE, 0)) True
>>> history.has_move(Turn(WHITE, 432)) False
Parameters: turn – The Turn
in question.Returns: True if there is a move action, False otherwise.
-
requested_move
(turn: reconchess.history.Turn) → Optional[chess.Move]¶ Get the requested move action on the given turn.
- Examples:
>>> history.requested_move(Turn(WHITE, 0)) Move(E2, E4)
>>> history.requested_move(Turn(BLACK, 0)) Move(E7, E5)
>>> history.requested_move(Turn(WHITE, 1)) None
Parameters: turn – The Turn
in question.Returns: If the player requested to move, then the requested move action as a chess.Move
, otherwise None if the player requested to pass.
-
taken_move
(turn: reconchess.history.Turn) → Optional[chess.Move]¶ Get the executed move action on the given turn. This may be different than the requested move, as the requested move may not be legal.
- Examples:
>>> history.requested_move(Turn(WHITE, 0)) Move(E2, D3) >>> history.taken_move(Turn(WHITE, 0)) None
>>> history.requested_move(Turn(WHITE, 1)) Move(E2, E4) >>> history.taken_move(Turn(WHITE, 1)) Move(E2, E3)
Parameters: turn – The Turn
in question.Returns: None if the player requested to pass or made an illegal move, the executed move action as a chess.Move
otherwise.
-
capture_square
(turn: reconchess.history.Turn) → Optional[int]¶ Get the square of the opponent’s captured piece on the given turn. A capture may not have occurred, in which case None will be returned.
- Examples:
>>> history.capture_square(Turn(WHITE, 0)) None
>>> history.capture_square(Turn(WHITE, 4)) E4
Parameters: turn – The Turn
in question.Returns: If a capture occurred, then the Square
where it occurred, otherwise None.
-
move_result
(turn: reconchess.history.Turn) → Tuple[Optional[chess.Move], Optional[chess.Move], Optional[int]]¶ Get the full move result in one function. Calls
requested_move()
,taken_move()
, andcapture_square()
.- Examples:
>>> history.move_result(Turn(WHITE, 0)) (Move(E2, E4), Move(E2, E3), None)
Parameters: turn – The Turn
in question.Returns: The requested move, the executed move, and a capture square if there was one.
-
truth_fen_before_move
(turn: reconchess.history.Turn) → str¶ Get the truth state of the board as a fen string before the move was executed on the given turn. Use
truth_board_before_move()
if you want the truth board as achess.Board
object.- Examples:
>>> history.truth_fen_before_move(Turn(WHITE, 0)) "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -" >>> history.taken_move(Turn(WHITE, 0)) Move(E2, E4) >>> history.truth_fen_before_move(Turn(BLACK, 0)) "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -"
Parameters: turn – The Turn
in question.Returns: The fen of the truth board.
-
truth_board_before_move
(turn: reconchess.history.Turn) → chess.Board¶ Get the truth state of the board as a
chess.Board
before the move was executed on the given turn. Usetruth_fen_before_move()
if you want the truth board as a fen string.- Examples:
>>> history.truth_board_before_move(Turn(WHITE, 0)) Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -") >>> history.taken_move(Turn(WHITE, 0)) Move(E2, E4) >>> history.truth_fen_before_move(Turn(BLACK, 0)) Board("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -")
Parameters: turn – The Turn
in question.Returns: A chess.Board
object.
-
truth_fen_after_move
(turn: reconchess.history.Turn) → str¶ Get the truth state of the board as a fen string after the move was executed on the given turn. Use
truth_board_after_move()
if you want the truth board as achess.Board
object.- Examples:
>>> history.truth_fen_before_move(Turn(WHITE, 0)) "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -" >>> history.taken_move(Turn(WHITE, 0)) Move(E2, E4) >>> history.truth_fen_after_move(Turn(WHITE, 0)) "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -"
Parameters: turn – The Turn
in question.Returns: The fen of the truth board.
-
truth_board_after_move
(turn: reconchess.history.Turn) → chess.Board¶ Get the truth state of the board as a
chess.Board
after the move was executed on the given turn. Usetruth_fen_after_move()
if you want the truth board as a fen string.- Examples:
>>> history.truth_board_before_move(Turn(WHITE, 0)) Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -") >>> history.taken_move(Turn(WHITE, 0)) Move(E2, E4) >>> history.truth_fen_after_move(Turn(WHITE, 0)) Board("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq -")
Parameters: turn – The Turn
in question.Returns: A chess.Board
object.
-
collect
(get_turn_data_fn: Callable[[reconchess.history.Turn], T], turns: Iterable[reconchess.history.Turn]) → Iterable[T]¶ Collect data from multiple turns using any of
sense()
,sense_result()
,requested_move()
,taken_move()
,capture_square()
,move_result()
,truth_fen_before_move()
,truth_board_before_move()
,truth_fen_after_move()
, ortruth_board_after_move()
.- Examples:
>>> history.collect(history.sense, [Turn(WHITE, 0), Turn(BLACK, 0)]) [E7, E2]
>>> history.collect(history.requested_move, history.turns(WHITE)) [Move(E2, E4), Move(D1, H5), ...]
Parameters: - get_turn_data_fn – One of the getter functions of the history object.
- turns – The turns in question.
Returns: A list of the data, where each element is the value of the getter function on the corresponding turn.
-
Functions for playing games¶
-
reconchess.
play_local_game
(white_player: reconchess.player.Player, black_player: reconchess.player.Player, game: reconchess.game.LocalGame = None, seconds_per_player: float = 900) → Tuple[Optional[bool], Optional[reconchess.types.WinReason], reconchess.history.GameHistory]¶ Plays a game between the two players passed in. Uses
LocalGame
to run the game, and just callsplay_turn()
until the game is over:while not game.is_over(): play_turn(game, player)
Parameters: Returns: The results of the game, also passed to each player via
Player.handle_game_end()
.
-
reconchess.
play_remote_game
(server_url, game_id, auth, player: reconchess.player.Player)¶
-
reconchess.
play_turn
(game: reconchess.game.Game, player: reconchess.player.Player, end_turn_last=False)¶ Coordinates playing a turn for player in game. Does the following sequentially:
See
play_move()
for more info on end_turn_last.Parameters: - game – The
Game
that player is playing in. - player – The
Player
whose turn it is. - end_turn_last – Flag indicating whether to call
Game.end_turn()
before or afterPlayer.handle_move_result()
- game – The
-
reconchess.
notify_opponent_move_results
(game: reconchess.game.Game, player: reconchess.player.Player)¶ Passes the opponents move results to the player. Does the following sequentially:
- Get the results of the opponents move using
Game.opponent_move_results()
. - Give the results to the player using
Player.handle_opponent_move_result()
.
Parameters: - Get the results of the opponents move using
-
reconchess.
play_sense
(game: reconchess.game.Game, player: reconchess.player.Player, sense_actions: List[int], move_actions: List[chess.Move])¶ Runs the sense phase for player in game. Does the following sequentially:
- Get the sensing action using
Player.choose_sense()
. - Apply the sense action using
Game.sense()
. - Give the result of the sense action to player using
Player.handle_sense_result()
.
Parameters: - Get the sensing action using
-
reconchess.
play_move
(game: reconchess.game.Game, player: reconchess.player.Player, move_actions: List[chess.Move], end_turn_last=False)¶ Runs the move phase for player in game. Does the following sequentially:
- Get the moving action using
Player.choose_move()
. - Apply the moving action using
Game.move()
. - Ends the current player’s turn using
Game.end_turn()
. - Give the result of the moveaction to player using
Player.handle_move_result()
.
If end_turn_last is True, then
Game.end_turn()
is called last instead of beforePlayer.handle_move_result()
.Parameters: - game – The
Game
that player is playing in. - player – The
Player
whose turn it is. - move_actions – The possible move actions for player.
- end_turn_last – Flag indicating whether to call
Game.end_turn()
before or afterPlayer.handle_move_result()
- Get the moving action using