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.2.tar.gz (177.2 kB view details)

Uploaded Source

Built Distribution

pydraughts-0.6.2-py3-none-any.whl (190.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydraughts-0.6.2.tar.gz
Algorithm Hash digest
SHA256 c3aa4769148b8a194e860f03dd34a6d0cc507f2ca67fc35cf7f3e0881411233b
MD5 6027f5fa3ff7ba6d648a09b62ef5ae8d
BLAKE2b-256 f57854184e65b9d2257f6fdb874182d0066a38a2ec4b0f6ca873f69c0408a34d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pydraughts-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4190b73e4783330238dce9a5cc925516578b8c6662aeb8e428f338edc920dfc7
MD5 91a6d5546a1a57ed5f138d2532d7728a
BLAKE2b-256 de5f41e38a0af8937a4fa13a63df80968fc7f7e5b6865a7e57a827e4771432a4

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