API Reference#

chess_agent.py#

This module defines a ChessAgent class that uses the minimax algorithm with alpha-beta pruning to play chess.

Classes:

ChessAgent: A class that represents the board and the agent that plays chess.

Dependencies:

chess (formerly python-chess): A chess library for Python, which provides move generation, validation, and more.

class applechess.chess_agent.ChessAgent(board: Board | str | None = None)#

Class that represents the board and the agent that plays chess.

class GamePhase(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)#

Enum class to represent the game phase. Opening is defined as the first 6 moves. Midgame is defined as the phase between the opening and the endgame. Endgame is defined as the phase when there are less than 11 pieces on the board.

agent_gen_push_move(depth: int) Move#

Generate the best move for the agent and push it. :param depth: depth of the search tree.

get_best_move(depth: int, parallelize: bool = False) Move#

Agent that plays a move based on the alpha/beta-minimax algorithm. :param depth: depth of the search tree. :param parallelize: whether to parallelize the search. :return: the best move to play.

Get the legal moves of a board, ordered by the agent’s preference for faster pruning. This function utilizes the MVV-LVA heuristic. :param board: the board to get the legal moves of. :return: the ordered legal moves.

static get_value(piece: Piece) int#

Get the value of a piece based on the piece type. If an unknown piece is passed, 0 is returned. :param piece: the piece to get the value of. :return: the value of the piece.

interactive_terminal(color: bool = True, depth: int = 3) None#

Play an interactive game in the terminal against the agent. :param depth: depth of the search tree. :param color: color to play as.

static play_move(board: Board, move: Move) Board#

Play a move on a board and return the new board. :param board: the board to play the move on. :param move: the move to play. :return: a new board with the move played.

pprint() None#

Pretty print the board.

push_move(move: str) None#

Push a move in SAN/UCI format. :param move: string of the move.