Skip to main content

A draughts library with advenced (customizable) WEB UI move generation and validation, PDN parsing and writing. Supports multiple variants of game.

Project description

py-draughts

GitHub Actions PyPI version Downloads

Efficient modern and flexible implementation of the draughts game with a beautiful web interface. Supports multiple variants of the game and allows playing against AI.

Installation

pip install py-draughts

Documentation

Key features

  • Displays simple ascii board for different variants of the game.
>>> from draughts import get_board
>>> board = get_board('standard', "W:W4,11,28,31,K33,K34,38,40,K41,43,K44,45,K46,47:BK3,21,27,32")
>>> board
 . . . . . B . w . .
 . . . . . . . . . .
 . w . . . . . . . .
 . . . . . . . . . .
 . b . . . . . . . .
 . . b . w . . . . .
 . w . b . W . W . .
 . . . . w . . . w .
 . W . . . w . W . w
 W . w . . . . . . .

>>> board = get_board("american")
>>> board
 . b . b . b . b
 b . b . b . b .
 . b . b . b . b
 . . . . . . . .
 . . . . . . . .
 w . w . w . w .
 . w . w . w . w
 w . w . w . w .
  • Make and undo moves
>>> board.push_uci("31-27")
>>> board.pop() # undo last move
Move: 31->27
>>> board.turn
Color.WHITE
  • detects draws and wins
>>> board.game_over
False
>>> board.is_threefold_repetition
False
>>> board.is_5_moves_rule
False
>>> board.is_16_moves_rule
False
>>> board.is_25_moves_rule
False
>>> board.is_draw
False

Each variant has it's own specyfic rules.

  • Validate and generate moves
>>> board.push_uci("31-22")
ValueError: 31-22 is correct, but not legal in given position.
Legal moves are: ['31-27', '31-26', '32-28', '32-27', '33-29', '33-28', '34-30', '34-29', '35-30']

>>> list(board.legal_moves)
['31-27', '31-26', '32-28', '32-27', '33-29', '33-28', '34-30', '34-29', '35-30']
  • Reads and writes fen strings
>>> board = get_board('standard', "W:W4,11,28,31,K33,K34,38,40,K41,43,K44,45,K46,47:BK3,21,27,32")
>>> board.fen
'[FEN "W:W4,11,28,31,K33,K34,38,40,K41,43,K44,45,K46,47:BK3,21,27,32"]'
  • Has simple engine
>>> from draughts.engine import AlphaBetaEngine
>>> engine = AlphaBetaEngine(depth=5)
>>> engine.get_best_move(board, with_evaluation=True)
Move: 28->37, 3.0

UI

  1. Allows to play against AI.
  2. Allows to play vs another player. (on the same computer)
  3. Allows to test and find bugs in your engine.
python -m draughts.server.server

Use for testing your engine.

Example with simplest possible engine.

>>> from draughts.server import Server
>>> import numpy as np
>>> get_best_mv = lambda board: np.random.choice(list(board.legal_moves))
>>> server = Server(get_best_move_method=get_best_mv)
>>> server.run()
INFO:     Started server process [1617]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

It is as simple as that!

Contributing

Contributions to this project are welcome. If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the project repository.

Bibliography

  1. Notation
  2. Rules and variants
  3. List of PDNs
  4. Draughts online
  5. Additional 1 (Checkers online)
  6. Additional 2 (Chinook)

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

py-draughts-1.2.9.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

py_draughts-1.2.9-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file py-draughts-1.2.9.tar.gz.

File metadata

  • Download URL: py-draughts-1.2.9.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for py-draughts-1.2.9.tar.gz
Algorithm Hash digest
SHA256 04768435dd74126c118c2f5895adcd0960ab50ef9cf7a607252c94fec3bf3c8a
MD5 cc95d3edd62dcf57cab3728d9c8e3dde
BLAKE2b-256 c2db1cf15b1a535b3cee818f3f8366dc01c6e63b4b902dc4cd60669a1f220b2b

See more details on using hashes here.

Provenance

File details

Details for the file py_draughts-1.2.9-py3-none-any.whl.

File metadata

  • Download URL: py_draughts-1.2.9-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for py_draughts-1.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 c0758f46e0d3ee66fb8bbb6cb4861b89efd1e748ac95d886828f2f579b6162e9
MD5 8c8dafb32e507c0c0e3a9fc4fa40a8d6
BLAKE2b-256 130296a7e706d518b2e3540e9cd4887338cada8142654fe7ec7bc77064cf5d64

See more details on using hashes here.

Provenance

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