A draughts library for Python with move generation, PDN reading and writing, engine communication and balloted openings
Project description
pydraughts
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()
- Run tournaments
from draughts.tournament import RoundRobin
player1 = (["scan.exe", "hub"], "hub", {})
player2 = ("kr_hub.exe", "hub", {})
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()
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
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 Distribution
File details
Details for the file pydraughts-0.6.4.tar.gz
.
File metadata
- Download URL: pydraughts-0.6.4.tar.gz
- Upload date:
- Size: 179.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38c3d7e0338d39381909346058511d67b61a182a46df319dac98a67db96faca8 |
|
MD5 | a70ee7369db763102fead8da80cdcc24 |
|
BLAKE2b-256 | a69d1611b39e0ee7b8a4e7cd7160c91c73d3f7817b8f91801a2f70c217198f06 |
File details
Details for the file pydraughts-0.6.4-py3-none-any.whl
.
File metadata
- Download URL: pydraughts-0.6.4-py3-none-any.whl
- Upload date:
- Size: 193.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70b58c4f74f8800c137f3a82bb4f4406437dbe51e20be9fff4f372456d243716 |
|
MD5 | b0fe2e9eb0336bf1d8a4f1b2c9383c7c |
|
BLAKE2b-256 | ab208af1b60e0f4d113abd478292ad0953da2d7e3196de4e2c2cb8c5ccd47530 |