Skip to main content

pydraughts

PyPI version Tests Build CodeQL codecov

pydraughts is a draughts (checkers) library for Python with move generation, SVG visualizations, PDN reading and writing, engine communication and balloted openings. It is based on ImparaAI/checkers.

Installing

Download and install the latest release:

pip install pydraughts

Features

Variants:

  • Standard (International)
  • Frisian
  • frysk!
  • Antidraughts
  • Breakthrough
  • Russian
  • Brazilian
  • English/American
  • Italian
  • Turkish

Engine protocols:

  • Hub
  • DXP
  • CheckerBoard

PDN Reading and Writing

  • Import pydraughts
from draughts import Board, Move, WHITE, BLACK
  • Create a game
board = Board(variant="standard", fen="startpos")
  • Make a move
move = Move(board, steps_move=[34, 30])
board.push(move)

# Multi-capture
board2 = Board(fen="W:WK40:B19,29")
board2.push(Move(board2, pdn_move='40x14'))
  • Get a visual representation of the board as SVG
from draughts import svg
svg.create_svg(Board(fen="B:W16,19,33,34,47,K4:B17,25,26"))

SVG Board

  • Get a visual representation of the board in the terminal
print(board)

"""
   | b |   | b |   | b |   | b |   | b 
---------------------------------------
 b |   | b |   | b |   | b |   | b |   
---------------------------------------
   | b |   | b |   | b |   | b |   | b 
---------------------------------------
 b |   | b |   | b |   | b |   | b |   
---------------------------------------
   |   |   |   |   |   |   |   |   |   
---------------------------------------
   |   |   |   |   |   |   |   | w |   
---------------------------------------
   | w |   | w |   | w |   |   |   | w 
---------------------------------------
 w |   | w |   | w |   | w |   | w |   
---------------------------------------
   | w |   | w |   | w |   | w |   | w 
---------------------------------------
 w |   | w |   | w |   | w |   | w |   
"""
  • Get legal moves
moves = board.legal_moves()
  • Detect wins and draws
has_white_won = board.winner() == WHITE
is_draw = board.winner() == 0
winnner = board.winner()
is_game_over = board.is_over()
  • Convert move to other types
move = Move(board, board_move=moves[0].board_move).pdn_move
  • Get fen
fen = game.fen
  • Communicate with engines
from draughts.engine import HubEngine, Limit
engine = HubEngine(["scan.exe", "hub"])
engine.init()
limit = Limit(time=10)
engine_move = engine.play(board, limit, ponder=False)
  • Read PDN games
from draughts.PDN import PDNReader
games = PDNReader(filename=filepath)
game = games.games[0]
moves = game.moves
  • Write PDN games
from draughts.PDN import PDNWriter
games = PDNWriter(filename=filepath, board=board)
  • Get a ballot
from draughts.ballots import Ballots
ballots = Ballots('english')
ballot1 = ballots.get_ballot()
ballot2 = ballots.get_ballot()
  • Run tournaments
from draughts.tournament import RoundRobin
player1 = (["scan.exe", "hub"], "hub", {}, None)
player2 = ("kr_hub.exe", "hub", {}, None)
players = [player1, player2]
tournament = RoundRobin("tournament.pdn", players, start_time=20, increment=0.2, games_per_pair=4)
scores = tournament.play()
print(scores)
tournament.print_standings()

Example Engines

Some engines that can be used with pydraughts.

Engine Protocol
Kingsrow (international) Hub & DXP
Scan Hub & DXP
Moby Dam DXP
Kingsrow (english) CheckerBoard
Kingsrow (italian) CheckerBoard
Cake CheckerBoard
Kallisto CheckerBoard

Selected Projects

If you like, share your interesting project that uses pydraughts.

Projects
Checkers Reinforcement Learning — https://github.com/d3da/checkers-rl

Acknowledgements

Thanks to fishnet which was modified to add support for Hub engines. Thanks to akalverboer for their DXC100_draughts_client which was modified to add support for DXP engines.

License

pydraughts is licensed under The MIT License. Check out LICENSE for the full text. The licenses of the other projects that pydraughts uses are in the other_licenses folder.

Release files for pydraughts 0.6.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydraughts 0.6.7
File Size Uploaded
pydraughts-0.6.7.tar.gz 183.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydraughts 0.6.7
File Interpreter ABI Platform
pydraughts-0.6.7-py3-none-any.whl Python 3 none any Details

Total release size: 378.6 kB

Release files / pydraughts-0.6.7.tar.gz

Download URL pydraughts-0.6.7.tar.gz
Size 183.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cbbaf4cbf3ddadf7c641e83b7155b02bb28310b5ea35963c76523add88c3c671
BLAKE2b-256 checksum
How to use checksums
3b7dd0fa619725e5771a102fac88f04feea2dc24c3f0118ac04c61b7fa9c7005
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / pydraughts-0.6.7-py3-none-any.whl

Download URL pydraughts-0.6.7-py3-none-any.whl
Size 195.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60ac89bbd00642ecf19dd981e9ccd4f86d3c0036f9c8d655213c4b7e1f8e7087
BLAKE2b-256 checksum
How to use checksums
a643249a34530f590dd041c3825fb2b4e67345c1821f93bfdb60652340b59408
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.6.7 This release

2 release files

0.6.6

2 release files

0.6.5

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.10

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page