api module

class api.Move(type: int, piece, target: tuple, special_type=None)

Bases: object

Moves will be initiated when getting piece’s allowed moves, they can also be used as argument to move a piece There is different types of moves

FORBIDDEN_MOVE = 0
TO_EMPTY_MOVE = 1

A move to a empty case

KILL_MOVE = 2

A move that will kill an opponent’s piece

SPECIAL_MOVE = 3

Ex: for a castling move or a Pawn promoting move (in this case you should specify the wanted class as Pawn attribute, please refer to Pawn)

OVER_CHECK_MOVE = 4

Used to detect check situations (move where you’ll kill a Check piece)

LEADING_TO_CHECK_SITUATION_MOVE = 5

Used to detect check situations (move that will conduct to a Check of its own color, so it’s forbidden)

CASTLING_TYPE = 1

For SPECIAL_MOVE

EN_PASSANT_TYPE = 2

For SPECIAL_MOVE

TO_PROMOTE_TYPE = 3

special_type if it’s a Pawn promotion move. Be careful, the Move type won’t be SPECIAL_MOVE for promotions. To specify promotion, refer to Pawn

type

Move’s type (int)

piece

Move’s piece

target

Move’s position target (tuple)

special_type

Special type if type==SPECIAL_MOVE or if it’s a Pawn promotion move (value would be TO_PROMOTE_TYPE)

class api.Piece(color: int, pos: tuple, board)

Bases: object

Base class for pieces

color
pos
board
get_moves_allowed(skip_check_verification=False) list

To get every piece’s moves allowed with the current Board configuration (moves allowed this current turn)

case_allowed(case_pos: tuple, this_move_can_kill=True, skip_check_verification=False) Move

To test if this specific case is currently allowed for the piece

move(pos_or_move: tuple, skip_allowed_verif=False, call_new_turn=True) tuple

To move the piece to a position returns the target position if it worked, otherwise it returns None

class api.Rook(color, pos: tuple, board)

Bases: Piece

Class for Rooks, please refer to Piece

SCORE_VALUE = 5

Value for score evaluation

class api.Check(color, pos: tuple, board)

Bases: Piece

Class for Checks, please refer to Piece

in_check_situation(hypothesis=None) bool

Detects if this Check is “in check”

class api.Queen(color, pos: tuple, board)

Bases: Piece

Class for Queens, please refer to Piece

SCORE_VALUE = 10

Value for score evaluation

class api.Bishop(color, pos: tuple, board)

Bases: Piece

Class for Bishops, please refer to Piece

SCORE_VALUE = 3

Value for score evaluation

class api.Knight(color, pos: tuple, board)

Bases: Piece

Class for Knights, please refer to Piece

SCORE_VALUE = 3

Value for score evaluation

class api.Pawn(color, pos: tuple, board)

Bases: Piece

Class for Pawns, please refer to Piece

SCORE_VALUE = 1

Value for score evaluation

promote_class_wanted
This attribute stores the piece class that will be used if the Pawn promotes
It can be changed whenever in the game, if no value is given we’ll warn it and use a Queen to promote the Pawn
class api.Board(pieces_by_pos=None, move_history=[], cur_color_turn=0, verbose=1)

Bases: object

Represents the whole game board, containing pieces and data about current and past turns

move_history
cur_color_turn
cur_color_turn_in_check

If the current playing color is in check

game_ended
winner
pieces_by_color

2-dimensional list representing pieces by color (self.pieces_by_color[0] for white pieces and self.pieces_by_color[0] for black pieces)

pieces_by_pos

Dict representing pieces, keys are positions (tuple) and values are pieces (Piece)

score_evaluation() dict

Returns the current score evaluation for each color | (basic calculation with a static value for each piece type)

move_piece(piece, pos_or_move: tuple, skip_allowed_verif=False, call_new_turn=True) tuple

Enables you to move a piece instead of doing it with the Piece obj, returns None if the move isn’t allowed

create_hypothesis_board(pieces_with_pos_to_change={})
Allows you to create hypothesis boards, an independent copy of the current Board
Returns another Board obj