Beta

ChessGameState

Attribute Type Description
ChessGameState.tick int The tick number starting at 0. Each new state is 1 more than the last. -1 on a board from make_pseudo_move.
ChessGameState.board ChessBoard An object representing the state of the board at this point in the chess game.
ChessGameState.turn str The player to move. 'w' if it is white's turn to move and 'b' when it is black's turn to move.
ChessGameState.turn_num int The number of executed moves.
ChessGameState.last_move str The last move made in this game, in UCI. None at the start of the game.
ChessGameState.moves list[str] A list of every move made in this game, oldest first, in UCI. Empty at the start of the game.
ChessGameState.time_left numpy.ndarray Seconds left on each chess clock. ChessGameState.time_left[0] is yours and ChessGameState.time_left[1] is your opponent's. Only the clock of the player to move runs, and it is measured each time you read it, going negative once it runs out. Is None on a board from make_pseudo_move.
ChessGameState.all_valid_moves list[str] A list of strings for every valid move for the current game state, each written in UCI.
ChessGameState.fen str The Forsyth-Edwards Notation (FEN) string representation of the game state.
ChessGameState.gameover bool True if this position ends the game, otherwise False. Only a board from make_pseudo_move can be True
ChessGameState.in_check bool True if the active color is in check, otherwise False.
ChessGameState.winner str 'w' if white has won, 'b' if black has won, or 'draw' if the game ended in a draw, otherwise None. Only a board from make_pseudo_move can be not None
ChessGameState.endgame_type str 'checkmate', 'stalemate', 'insufficient_material', 'fifty_move_rule' or 'repetition' if the game is over, otherwise None. Only a board from make_pseudo_move can be not None

ChessBoard

An object representing the board of a chess game. Index-able with a square’s name, like ‘e4’, or matrix indices. If a cell does not have a piece on it, None will be returned.

Attribute Type Description
ChessBoard.array numpy.ndarray The board as a numpy array.
ChessBoard.pieces ChessPieces A ChessPieces object containing the pieces on the board.

ChessPieces

An iterable of ChessPiece objects with useful helper methods. Can be indexed by a lowercase 'w' or 'b' to get all pieces of the indexed color, or by uppercase letters corresponding to piece type.

Operation Returns Description
ChessPieces + ChessPieces ChessPieces Concatenates both sets of chess pieces into a new ChessPieces object.
Method Returns Description
ChessPieces.get_color(color) ChessPieces Returns a new ChessPieces object containing all pieces of the specified color. (Equivalent to indexing with 'w' or 'b')
ChessPieces.get_piece_type(piece_type) ChessPieces Returns a new ChessPieces object containing all pieces of the specified type. Valid piece types are 'R','N','B','P','Q', and 'K'. (Equivalent to indexing with uppercase letter)
ChessPieces.get_valid_moves() list[str] A list of all the possible moves using the pieces contained in the object, in UCI.
ChessPieces.get_numpy_bitboard() numpy.ndarray A 64 element numpy array of 1's and 0's describing the locations of the pieces on a flattened 8x8 chess board.

ChessPiece

A simple object representing a chess piece.

Attribute Type Description
ChessPiece.type str An uppercase letter for the piece type: 'R', 'N', 'B', 'P', 'Q' or 'K'.
ChessPiece.color str 'w' if the piece is white, 'b' if the piece is black.
ChessPiece.valid_moves list[str] A list of the valid moves for this piece, in UCI.
ChessPiece.pos str The name of the square the piece is on, like 'e4'.

Examples

Rendered State

{
	"fen": "r1bqkbnr/pppp1ppp/2n5/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 2 3",
	"clocks": [299.9995828, 299.9995727]
}

Values in Code

def on_my_turn(state):
	ChessInterface.log(state.turn)
	# > w

	ChessInterface.log(state.turn_num)
	# > 4

	ChessInterface.log(state.last_move)
	# > b8c6

	ChessInterface.log(state.moves)
	# > ['e2e4', 'e7e5', 'g1f3', 'b8c6']

	ChessInterface.log(state.time_left)
	# > [299.9995828 299.9995727]

	ChessInterface.log(state.all_valid_moves)
	# > ['f3h4', 'f3d4', 'f3g5', 'f3g1', 'f3e5', 'a2a3', 'a2a4', 'b2b3', 'b2b4', 'c2c3', 'c2c4', 'd2d3', 'd2d4', 'g2g3', 'g2g4', 'h2h3', 'h2h4', 'b1c3', 'b1a3', 'd1e2', 'e1e2', 'f1e2', 'f1d3', 'f1c4', 'f1b5', 'f1a6', 'h1g1']

	# Use a square's name or matrix indexing to get the black rook
	ChessInterface.log(state.board[0,0]) # or state.board['a8']
	# > ChessPiece('r', 'a8')

	# None if no piece at indexed location
	ChessInterface.log(state.board['b6'])
	# > None

	# Slice with square names or matrix notation
	ChessInterface.log(state.board['a8':'c6']) # or state.board[0:3, 0:3]
	# >    ---------
	#   8 │ r  ·  b │
	#   7 │ p  p  p │
	#   6 │ ·  ·  n │
	#      ---------
	#       a  b  c

	# Get the pieces from a board
	ChessInterface.log(state.board['a1':'a8'].pieces['P'])
	# > [ChessPiece('p', 'a7'), ChessPiece('P', 'a2')]