API Reference¶
Board and moves¶
dame.Board ¶
A draughts board: the start position plus the moves played from it.
Squares are numbered 1 to 50; White starts on 31-50 and moves first. The board enforces the rules: captures are mandatory, the maximum capture must be taken, and games end by the FMJD rules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fen
|
str | None
|
The start position in FEN notation, e.g. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> board = Board()
>>> board.push("32-28")
Move('32-28')
>>> board.push("19-23")
Move('19-23')
>>> board.legal_moves
[Move('28x19x23')]
parse_move ¶
Matches move text against the legal moves.
Accepts 32-28, 28x19, Hub notation listing the captured squares
(28x19x23) and PDN capture paths (28x19x10).
Raises:
| Type | Description |
|---|---|
IllegalMoveError
|
If no single legal move matches. |
piece_at ¶
The piece on square (1 to 50), if any.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
pop ¶
Takes back the last move and returns it.
Raises:
| Type | Description |
|---|---|
IndexError
|
If no move has been played. |
push ¶
Plays a move given as a Move or as text and returns it.
Raises:
| Type | Description |
|---|---|
IllegalMoveError
|
If the move is illegal. |
dame.Move ¶
A legal move: origin, destination and the captured squares.
Moves are obtained from Board.legal_moves, Board.parse_move or a search.
str(move) gives standard notation (32-28, 28x19); move.hub() also
lists the captured squares (28x19x23), which is unambiguous.
dame.Piece ¶
dame.Color ¶
Bases: Enum
A side. White moves first.
Game results¶
dame.Outcome ¶
dame.Termination ¶
Bases: Enum
Why a game ended.
FIVE_MOVES
class-attribute
instance-attribute
¶
A lone king against at most two pieces including a king, for 5 moves each.
NO_MOVES
class-attribute
instance-attribute
¶
The side to move has no legal move and loses.
REPETITION
class-attribute
instance-attribute
¶
The same position occurred three times.
SIXTEEN_MOVES
class-attribute
instance-attribute
¶
A lone king against three pieces including a king, for 16 moves each.
TWENTY_FIVE_MOVES
class-attribute
instance-attribute
¶
25 moves by each side with only kings moved and nothing captured.
Engine¶
dame.Engine ¶
A search engine. Reusing one engine across moves keeps its hash table.
The search runs without holding the GIL, so other Python threads keep
running; KeyboardInterrupt stops it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hash_mb
|
int
|
Transposition table size in MiB. |
64
|
book
|
OpeningBook | None
|
An opening book to play from before searching. |
None
|
Examples:
>>> engine = Engine(hash_mb=16)
>>> result = engine.search(Board("W:WK46:B10"), depth=4)
>>> result.best_move, result.mate
(Move('46x5x10'), 1)
search ¶
search(board: Board, *, depth: int | None = None, nodes: int | None = None, time: float | None = None, info: Callable[[SearchInfo], object] | None = None) -> SearchResult
Searches the current position of board.
The search stops at the first limit reached. Without limits it runs
until stop() is called from another thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
board
|
Board
|
The position to search, with its history for repetitions. |
required |
depth
|
int | None
|
Maximum depth in plies. |
None
|
nodes
|
int | None
|
Maximum number of nodes. |
None
|
time
|
float | None
|
Maximum time in seconds. |
None
|
info
|
Callable[[SearchInfo], object] | None
|
Called with a |
None
|
Returns:
| Type | Description |
|---|---|
SearchResult
|
The best move with its score and principal variation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a limit is invalid. |
dame.SearchResult ¶
The outcome of a search.
mate
property
¶
Moves until mate for a forced win (positive) or loss (negative), else None.
dame.SearchInfo ¶
Progress reported after each completed search iteration.
seldepth
property
¶
The deepest ply reached, including captures resolved at the leaves.
dame.OpeningBook ¶
An opening book: weighted moves by position.
A book is built from games in PDN: the first moves of each game are added from the starting position, and moves shared by several games gain weight.
Examples:
>>> book = OpeningBook.from_pdn("1. 32-28 18-23 *\n1. 32-28 17-21 *\n1. 33-28 *")
>>> book.moves(Board())
[(Move('32-28'), 2), (Move('33-28'), 1)]
from_file
staticmethod
¶
Builds a book from the first plies moves of each game in the PDN file at path.
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be read. |
ValueError
|
If a game contains an illegal move. |
from_pdn
staticmethod
¶
Builds a book from the first plies moves of each game in PDN text.
Games of other variants (a GameType other than 20) and games that
start from another position (a FEN tag) are skipped.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a game contains an illegal move. |
moves ¶
The book moves for the current position with their weights, heaviest first.
Utilities¶
dame.perft
builtin
¶
Counts the leaf nodes of the legal move tree at depth plies.
dame.IllegalMoveError ¶
Bases: ValueError
Raised when a move is illegal or cannot be parsed.