Base Board

class draughts.boards.base.BaseBoard(starting_position: ndarray = None, turn: Color = None)[source]

Abstact class for all draughts variants.

Important

All boards contain all methods from this class.

Class is designed to support draughts boards of any size. By specifying the starting position, the user can create a board of any size.

To create new variants of draughts, inherit from this class and:

  • override the legal_moves property

  • (optional) override the SQUARES list to match the new board size if you want to use UCI notation: [A1, B1, C1, ...]

  • override the STARTING_POSITION to specify the starting position

  • override the STARTING_COLOR to specify the starting color

Constraints: - There are only two colors:

  • Color.WHITE

  • Color.BLACK

  • There are only two types of pieces:
    • PieceType.MAN

    • PieceType.KING

  • Board should always be square.

Note

For generating legal moves use

halfmove_clock: int = 0

The number of half-moves since the last capture or pawn move.

GAME_TYPE = 23

PDN game type. See PDN specification.

ROW_IDX = {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1, 8: 2, 9: 2, 10: 2, 11: 2, 12: 3, 13: 3, 14: 3, 15: 3, 16: 4, 17: 4, 18: 4, 19: 4, 20: 5, 21: 5, 22: 5, 23: 5, 24: 6, 25: 6, 26: 6, 27: 6, 28: 7, 29: 7, 30: 7, 31: 7}

Dictionary of row indexes for every square. Generated only on module import. Used to calculate legal moves.

COL_IDX = {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 0, 9: 1, 10: 2, 11: 3, 12: 4, 13: 5, 14: 6, 15: 7, 16: 0, 17: 1, 18: 2, 19: 3, 20: 4, 21: 5, 22: 6, 23: 7, 24: 0, 25: 1, 26: 2, 27: 3, 28: 4, 29: 5, 30: 6, 31: 7}

Same as ROW_IDX but for columns.

STARTING_COLOR = -1

Starting color. Color.WHITE or Color.BLACK.

DIAGONAL_LONG_MOVES = Ellipsis

Dictionary of pseudo-legal moves for king pieces. Generated only on module import. This dictionary contains all possible moves for king piece (as if there were no other pieces on the board).

Structure: [(right-up moves), (left-up moves), (right-down moves), (left-down moves)]

DIAGONAL_SHORT_MOVES = Ellipsis

Same as DIAGONAL_LONG_MOVES but contains only first 2 squares of the move. (one for move and one for capture)

property position: ndarray

Returns board position.

property game_over: bool

Returns True if the game is over.

push(move: Move, is_finished: bool = True) None[source]

Pushes a move to the board. Automatically promotes a piece if it reaches the last row.

If is_finished is set to True, the turn is switched. This parameter is used only for generating legal moves.

pop(is_finished=True) None[source]

Pops a move from the board.

If is_finished is set to True, the turn is switched. This parameter is used only for generating legal moves.

push_uci(str_move: str) None[source]

Allows to push a move from a string.

  • Converts string to Move object

  • calls BaseBoard.push method

property fen

Returns a FEN string of the board position.

[FEN "[Turn]:[Color 1][K][Square number][,]...]:[Color 2][K][Square number][,]...]"]

Fen examples:

  • [FEN "B:W18,24,27,28,K10,K15:B12,16,20,K22,K25,K29"]

  • [FEN "B:W18,19,21,23,24,26,29,30,31,32:B1,2,3,4,6,7,9,10,11,12"]

classmethod from_fen(fen: str) BaseBoard[source]

Creates a board from a FEN string by using regular expressions.

property result: Literal['1/2-1/2', '1-0', '0-1', '-']

Returns a result of the game.

property friendly_form: ndarray

Returns a board position in a friendly form. Makes board with size n x n from a board with size n x n/2

property pdn: str

Returns a PDN string that represents the game. pdn - Portable Draughts Notation Example:

` [GameType "20"] [Variant "Standard (international) checkers"] [Result "-"] 1. 34-29 17-21 2. 33-28 12-17 3. 38-33 21-26 4. 29-24 20x27 5. 31x22 18x27 `

static is_capture(move: Move) bool[source]

Checks if a move is a capture.