ChessGameState
Attribute |
Description |
ChessGameState.board |
A ChessBoard object representing the board of a chess game. |
ChessGameState.turn |
A string with value 'w' if it is white's turn to move and 'b' when it is black's turn to move. |
ChessGameState.clocks |
A numpy array of two floats where where the first is the time left for your algo at the start of the turn (in ms) and the second is how much time your opponent finished their turn with. |
ChessGameState.all_valid_moves |
A list of strings for every valid move in SAN for the current game state. |
ChessGameState.fen |
The Forsyth-Edwards Notation (FEN) string representation of the game state. |
ChessGameState.pgn |
The Portable Game Notation (PGN) string representation of the game state. Unlike FEN, this holds information about repetition. |
ChessGameState.gameover |
True if the game is over, otherwise False . |
ChessGameState.in_check |
True if the active color is in check, otherwise False . |
ChessGameState.winner |
A string with value 'w' if white has won, 'b' if black has won, or 'draw' if the game ended in a draw. Is None if the game is not over. |
ChessGameState.endgame_type |
A string indicating how the game ended. Possible values are 'checkmate' , 'stalemate' , 'insufficient_material' , 'fifty_move_rule' , 'repetition' , and None if the game is not over. |
ChessBoard
An object representing the board of a chess game. Index-able with SAN or matrix indices. If a cell does not have a piece on it, None
will be returned.
Attribute |
Description |
ChessBoard.array |
The board as a numpy array. |
ChessBoard.pieces |
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 |
Description |
ChessPieces + ChessPieces |
Concatenates both sets of chess pieces into a new ChessPieces object. Analogous to adding list objects. |
Method |
Description |
ChessPieces.get_color(color) |
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) |
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() |
A list of all the possible moves using the pieces contained in the object in SAN. |
ChessPieces.get_numpy_bitboard() |
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 |
Description |
ChessPiece.type |
An uppercase letter representing the piece type in SAN. |
ChessPiece.color |
'w' if the piece is white, 'b' if the piece is black. |
ChessPiece.valid_moves |
A list of the valid moves in SAN for this piece. |
ChessPiece.pos |
A string of the piece's position in SAN. |
Examples
class Algo:
def take_turn(
self,
state: ChessGameState,
interface: ChessInterface
) -> str:
# Assume the match just started
# Use SAN or matrix indexing to get the black rook
interface.log(state.board[0,0]) # or state.board['a8']
# > ChessPiece('r', 'a8')
# None if no piece at indexed location
interface.log(state.board['b6'])
# > None
# Slice with SAN or matrix notation
interface.log(state.board['a8':'c6']) # or state.board[0:3, 0:3]
# > ---------
# 8 │ r n b |
# 7 │ p p p │
# 6 │ · · · │
# ---------
# a b c
# Get the pieces from a board
interface.log(state.board['a1':'a8'].pieces['P'])
# > [ChessPiece('p', 'a7'), ChessPiece('P', 'a2')]