A high-performance Turkish Draughts (Dama) engine
Project description
kish
A high-performance Turkish Draughts (Dama) engine with Python bindings.
Built with Rust and PyO3 for maximum speed. Designed for both UI applications (simple API with algebraic notation) and machine learning (fast bitboard access).
Installation
pip install kish
Or build from source:
cd kish-py
pip install maturin
maturin develop --release
Quick Start
import kish
# Create a new game with standard starting position
board = kish.Board()
print(f"Turn: {board.turn}") # Turn: White
# Get all legal moves
actions = board.actions()
print(f"Legal moves: {len(actions)}") # Legal moves: 23
# Make a move (returns new board - immutable)
new_board = board.apply(actions[0])
print(f"Move: {actions[0].notation()}") # e.g., "a3-a4"
# Check game status
status = new_board.status()
if status.is_in_progress():
print("Game continues")
elif status.is_draw():
print("Draw!")
else:
print(f"Winner: {status.winner()}")
Game with History (Draw Detection)
Use Game for full game management with proper draw detection:
import kish
game = kish.Game()
# Play moves
while not game.status().is_over():
actions = game.actions()
if not actions:
break
# Make move (mutates game state)
game.make_move(actions[0])
# Draw detection
if game.is_threefold_repetition():
print("Draw by repetition!")
break
if game.halfmove_clock >= 50:
print("Draw by 50-move rule!")
break
# Undo moves
game.undo_move()
print(f"Moves played: {game.move_count}")
Custom Positions
import kish
# Create a custom position
board = kish.Board.from_squares(
turn=kish.Team.White,
white_squares=[kish.Square.D4, kish.Square.E3],
black_squares=[kish.Square.D5, kish.Square.F6],
king_squares=[kish.Square.D4], # D4 is a king
)
# Query pieces
print(f"White pieces: {[str(s) for s in board.white_pieces()]}")
print(f"Kings: {[str(s) for s in board.kings()]}")
Machine Learning
Bitboard Access
Fast access to raw bitboard representation for neural network input:
import kish
import numpy as np
board = kish.Board()
# Get individual bitboards (u64 integers)
white = board.white_bitboard()
black = board.black_bitboard()
kings = board.kings_bitboard()
# Get all at once (most efficient)
white, black, kings, turn = board.bitboards()
# As numpy array
arr = np.array(board.to_array(), dtype=np.uint64)
# arr = [white_pieces, black_pieces, kings, turn]
# Reconstruct from bitboards
board = kish.Board.from_bitboards(turn=0, white=white, black=black, kings=kings)
Bit Plane Conversion for CNNs
import numpy as np
def to_bit_planes(board):
"""Convert board to 4x8x8 tensor for CNN input."""
w, b, k, turn = board.bitboards()
planes = np.zeros((4, 8, 8), dtype=np.float32)
for i in range(64):
row, col = i // 8, i % 8
planes[0, row, col] = (w >> i) & 1 # white pieces
planes[1, row, col] = (b >> i) & 1 # black pieces
planes[2, row, col] = (k >> i) & 1 # kings
planes[3, :, :] = turn # turn plane
return planes
# Faster version using numpy
def to_bit_planes_fast(board):
"""Optimized bit plane conversion."""
w, b, k, turn = board.bitboards()
planes = np.zeros((4, 64), dtype=np.float32)
planes[0] = np.unpackbits(np.array([w], '>u8').view(np.uint8))[::-1]
planes[1] = np.unpackbits(np.array([b], '>u8').view(np.uint8))[::-1]
planes[2] = np.unpackbits(np.array([k], '>u8').view(np.uint8))[::-1]
planes[3] = turn
return planes.reshape(4, 8, 8)
Action Features for Policy Networks
# Get action features for ML
for action in board.actions():
# Source and destination
src = action.source()
dst = action.destination()
# Move properties
is_capture = action.is_capture()
is_promotion = action.is_promotion()
capture_count = action.capture_count()
# Captured pieces (for reward shaping)
captured = action.captured_pieces() # List[Square]
captured_bb = action.captured_bitboard() # u64
# Raw delta for applying moves (XOR with board state)
white_delta, black_delta, kings_delta = action.delta()
delta_arr = np.array(action.delta_array(), dtype=np.uint64)
Distance Heuristics
# Manhattan distance for evaluation functions
sq1 = kish.Square.D4
sq2 = kish.Square.H8
distance = sq1.manhattan(sq2) # 8
# Distance to promotion row
def distance_to_promotion(square, team):
"""Distance to back row for promotion."""
if team == kish.Team.White:
target_row = 7 # Row 8
else:
target_row = 0 # Row 1
return abs(square.row() - target_row)
Performance Testing
import kish
board = kish.Board()
# Count positions at depth (perft)
nodes = board.perft(6)
print(f"Positions at depth 6: {nodes}") # ~450 million nodes/sec
Examples
The examples/ directory contains runnable examples:
basic_game.py- Simple game loopcustom_position.py- Setting up custom board positionsml_features.py- Extracting features for machine learningperft.py- Performance testing with perftrandom_playout.py- Random game simulation
API Reference
Types
| Type | Description |
|---|---|
Team |
Enum: White, Black |
Square |
Enum: A1 through H8 (64 squares) |
GameStatus |
Game state with query methods |
Action |
Move with notation and bitboard access |
Board |
Immutable game board |
Game |
Mutable game with history tracking |
Board Methods
| Method | Description |
|---|---|
Board() |
Standard starting position |
Board.from_squares(...) |
Custom position from square lists |
Board.from_bitboards(...) |
Custom position from bitboards |
board.actions() |
Get legal moves |
board.apply(action) |
Make move (returns new board) |
board.status() |
Get game status |
board.perft(depth) |
Performance test |
Board Bitboard Methods (ML)
| Method | Description |
|---|---|
board.white_bitboard() |
White pieces as u64 |
board.black_bitboard() |
Black pieces as u64 |
board.kings_bitboard() |
Kings as u64 |
board.bitboards() |
Tuple: (white, black, kings, turn) |
board.to_array() |
Array: [white, black, kings, turn] |
Action Methods
| Method | Description |
|---|---|
action.source() |
Source square |
action.destination() |
Destination square |
action.notation() |
Algebraic notation (e.g., "d4xd6") |
action.is_capture() |
Is this a capture? |
action.is_promotion() |
Does piece promote? |
action.path() |
Full path of squares |
Action Bitboard Methods (ML)
| Method | Description |
|---|---|
action.captured_pieces() |
Captured squares as list |
action.captured_bitboard() |
Captured pieces as u64 |
action.delta() |
Tuple: (white_delta, black_delta, kings_delta) |
action.delta_array() |
Array: [white_delta, black_delta, kings_delta] |
Game Methods
| Method | Description |
|---|---|
Game() |
New game |
Game.from_board(board) |
From existing position |
game.make_move(action) |
Make move (mutates) |
game.undo_move() |
Undo last move |
game.is_threefold_repetition() |
Check repetition draw |
game.halfmove_clock |
Moves since last capture |
game.move_count |
Total moves made |
Square Methods
| Method | Description |
|---|---|
Square.from_notation("d4") |
Parse notation |
Square.from_row_col(row, col) |
From indices |
Square.from_mask(u64) |
From bitboard |
square.notation() |
To string (e.g., "D4") |
square.row() |
Row index (0-7) |
square.col() |
Column index (0-7) |
square.to_mask() |
To bitboard |
square.manhattan(other) |
Distance to other square |
Bitboard Layout
Bit index = row * 8 + col
A B C D E F G H
+---+---+---+---+---+---+---+---+
8 |56 |57 |58 |59 |60 |61 |62 |63 | <- White promotes here
+---+---+---+---+---+---+---+---+
7 |48 |49 |50 |51 |52 |53 |54 |55 |
+---+---+---+---+---+---+---+---+
6 |40 |41 |42 |43 |44 |45 |46 |47 |
+---+---+---+---+---+---+---+---+
5 |32 |33 |34 |35 |36 |37 |38 |39 |
+---+---+---+---+---+---+---+---+
4 |24 |25 |26 |27 |28 |29 |30 |31 |
+---+---+---+---+---+---+---+---+
3 |16 |17 |18 |19 |20 |21 |22 |23 |
+---+---+---+---+---+---+---+---+
2 | 8 | 9 |10 |11 |12 |13 |14 |15 |
+---+---+---+---+---+---+---+---+
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | <- Black promotes here
+---+---+---+---+---+---+---+---+
A B C D E F G H
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kish-1.1.7.tar.gz.
File metadata
- Download URL: kish-1.1.7.tar.gz
- Upload date:
- Size: 116.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78d36f31ddbd0ed38f7ff3d147a4d40d5e3d375be35032c09046247e48bd18e4
|
|
| MD5 |
8bbe60e47be74ed48e9a21fced8d20ad
|
|
| BLAKE2b-256 |
d08f42333709842c8820b94952663d69b202f19887713cf8a4b777f0bacc35d8
|
Provenance
The following attestation bundles were made for kish-1.1.7.tar.gz:
Publisher:
release.yml on Sanavesa/kish
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kish-1.1.7.tar.gz -
Subject digest:
78d36f31ddbd0ed38f7ff3d147a4d40d5e3d375be35032c09046247e48bd18e4 - Sigstore transparency entry: 1092847314
- Sigstore integration time:
-
Permalink:
Sanavesa/kish@10e431823a7256e95d83503cb5960129422abb58 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Sanavesa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10e431823a7256e95d83503cb5960129422abb58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kish-1.1.7-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: kish-1.1.7-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 282.3 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa7c01e77aba0971a908a3e92c8006ae3c8ce9dc7c16603ae17584a5d637fc0
|
|
| MD5 |
356c692a1f6510bf7c5fcd1a2fd7e6cd
|
|
| BLAKE2b-256 |
5300a48363b5be68bbcf987ab42d1b49defce900e2242598312a79ebbca38776
|
Provenance
The following attestation bundles were made for kish-1.1.7-cp314-cp314-macosx_11_0_arm64.whl:
Publisher:
release.yml on Sanavesa/kish
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kish-1.1.7-cp314-cp314-macosx_11_0_arm64.whl -
Subject digest:
3fa7c01e77aba0971a908a3e92c8006ae3c8ce9dc7c16603ae17584a5d637fc0 - Sigstore transparency entry: 1092847326
- Sigstore integration time:
-
Permalink:
Sanavesa/kish@10e431823a7256e95d83503cb5960129422abb58 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Sanavesa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10e431823a7256e95d83503cb5960129422abb58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kish-1.1.7-cp314-cp314-macosx_10_12_x86_64.whl.
File metadata
- Download URL: kish-1.1.7-cp314-cp314-macosx_10_12_x86_64.whl
- Upload date:
- Size: 294.7 kB
- Tags: CPython 3.14, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b13490742b7d79939114667e2f0d84580831ab915816affd8a6c64197252155
|
|
| MD5 |
5d50ee1f8b0605f4736731e3442615c8
|
|
| BLAKE2b-256 |
647e8a845fbef75fd6f6429103f74cc3df71bcb85624efb2e01ac8c22b82ff2c
|
Provenance
The following attestation bundles were made for kish-1.1.7-cp314-cp314-macosx_10_12_x86_64.whl:
Publisher:
release.yml on Sanavesa/kish
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kish-1.1.7-cp314-cp314-macosx_10_12_x86_64.whl -
Subject digest:
4b13490742b7d79939114667e2f0d84580831ab915816affd8a6c64197252155 - Sigstore transparency entry: 1092847323
- Sigstore integration time:
-
Permalink:
Sanavesa/kish@10e431823a7256e95d83503cb5960129422abb58 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Sanavesa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10e431823a7256e95d83503cb5960129422abb58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kish-1.1.7-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: kish-1.1.7-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 179.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ff6c12916e6d5fcb75410c7dad05df337c0ca4acc7b43bbccfdb44e0b928221
|
|
| MD5 |
9c885cca4c934824f560b72d1ce55a9c
|
|
| BLAKE2b-256 |
35cf39d0ab606a9a8eb9da8444a059d27e39fbccfc746389037592932e51c211
|
Provenance
The following attestation bundles were made for kish-1.1.7-cp312-cp312-win_amd64.whl:
Publisher:
release.yml on Sanavesa/kish
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kish-1.1.7-cp312-cp312-win_amd64.whl -
Subject digest:
2ff6c12916e6d5fcb75410c7dad05df337c0ca4acc7b43bbccfdb44e0b928221 - Sigstore transparency entry: 1092847325
- Sigstore integration time:
-
Permalink:
Sanavesa/kish@10e431823a7256e95d83503cb5960129422abb58 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Sanavesa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10e431823a7256e95d83503cb5960129422abb58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kish-1.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: kish-1.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 315.3 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2467a808e3ca794a766e84c1c713f392152f6f1d951b553f2cefe036521d196
|
|
| MD5 |
8256240df93d9fd4b73c1b4be32fc6fc
|
|
| BLAKE2b-256 |
411a3f1e5dee4b3061014d3acbb9e77c893407f8b3f7c357d0657bed94d6e473
|
Provenance
The following attestation bundles were made for kish-1.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on Sanavesa/kish
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kish-1.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
d2467a808e3ca794a766e84c1c713f392152f6f1d951b553f2cefe036521d196 - Sigstore transparency entry: 1092847331
- Sigstore integration time:
-
Permalink:
Sanavesa/kish@10e431823a7256e95d83503cb5960129422abb58 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Sanavesa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10e431823a7256e95d83503cb5960129422abb58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kish-1.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kish-1.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 308.8 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9db1ab93ef909d90a7d346ee01aa785ed9a36809792b3f347b4e8ad2dde1554
|
|
| MD5 |
198c5482d5adbfa60897ccabc8dfd71d
|
|
| BLAKE2b-256 |
636dd8bbe6e3bfc3e5f0f6f60ab5ab4bc8a3ef1b81d6530d44e978dedd351d5b
|
Provenance
The following attestation bundles were made for kish-1.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on Sanavesa/kish
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kish-1.1.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
a9db1ab93ef909d90a7d346ee01aa785ed9a36809792b3f347b4e8ad2dde1554 - Sigstore transparency entry: 1092847329
- Sigstore integration time:
-
Permalink:
Sanavesa/kish@10e431823a7256e95d83503cb5960129422abb58 -
Branch / Tag:
refs/tags/v1.1.7 - Owner: https://github.com/Sanavesa
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@10e431823a7256e95d83503cb5960129422abb58 -
Trigger Event:
push
-
Statement type: