Skip to main content

A draughts library for Python with move generation, PDN reading and writing, engine communication and balloted openings

Project description

pydraughts

PyPI version Tests Build CodeQL codecov

pydraughts is a draughts library for Python with move generation, 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
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()

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydraughts-0.6.0.tar.gz (176.7 kB view details)

Uploaded Source

Built Distribution

pydraughts-0.6.0-py3-none-any.whl (189.9 kB view details)

Uploaded Python 3

File details

Details for the file pydraughts-0.6.0.tar.gz.

File metadata

  • Download URL: pydraughts-0.6.0.tar.gz
  • Upload date:
  • Size: 176.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pydraughts-0.6.0.tar.gz
Algorithm Hash digest
SHA256 13183a592aa76479aa194b0d577684b866c233bdd7a48c3159c82bdc2249d5f0
MD5 ff0925beffedd1bf2f1b682eebac5083
BLAKE2b-256 9ab05abaf5d881addcb907eaef9d59a9757dde6e3dab68106f8a4deb4ce5c174

See more details on using hashes here.

File details

Details for the file pydraughts-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: pydraughts-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 189.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for pydraughts-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5c3da069d94637da6c54a3b44cc4e00974a37a89d17589a0f164cd83335687b
MD5 380433929e4099ed375ac67ea8aa3ad4
BLAKE2b-256 10eef317a7918c3562d38dd01c69daea801e895c80b6499d36b9c875731decc9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page