Skip to main content

py-draughts

GitHub Actions PyPI version

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

Key features

  1. Provides beautiful web interface for testing your engine/playing against AI.
  2. Supports multiple variants of the game (with different board size). standard, american etc.
  3. Follows international draughts standards. like fen pdn etc.
  4. Allows to easily create new variants of the game. by extending the Board class.
  5. Accurate documentation generated from code.

Documentation

Usage

Displays simple ascii board

>>> from draughts.standard import Board
>>> board = Board()
Board initialized with shape (10, 10). (base.py:108)
>>> board
 . 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 .

Make and undo moves

>>> board.push_from_str("37-32")
>>> board.push_from_str("14-19")
>>> board.push_from_str("32-28")
>>> board.push_from_str("19-23")
>>> board.pop() # undo last move
>>> board.push_from_str("19-23")
>>> board.push_from_str("28x19")
>>> board
 . 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 .

Generate legal moves and validate moves

>>> board.push_from_str("10x42")
Move: 10->42 is correct, but not legal in given position.
 Legal moves are: [Move: 36->31, Move: 37->32, Move: 37->31, Move: 38->33, Move: 38->32, Move: 39->34, Move: 39->33, Move: 40->35, Move: 40->34]

>>> list(board.legal_moves)
[Move: 36->31, Move: 37->32, Move: 37->31, Move: 38->33, Move: 38->32, Move: 39->34, Move: 39->33, Move: 40->35, Move: 40->34]

Generate fen string and load board from fen string

>>> board =Board.from_fen("W:W4,11,28,31,K33,K34,38,40,K41,43,K44,45,K46,47:BK3,21,27,32")
Board initialized with shape (10, 10). (base.py:109)
>>> board.push_from_str("28-37")
>>> board.fen
'[FEN "B:W4,11,31,K33,K34,37,38,40,K41,43,K44,45,K46,47:BK3,21,27"]'

American checkers

>>> from draughts.american import Board
>>> board = Board()
Board initialized with shape (8, 8). (base.py:108)
>>> 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 .

UI

from draughts.server import Server
Server().run()

Use for testing your engine.

Example with simplest possible engine.

>>> server = Server(get_best_move_method=lambda board: np.random.choice(list(board.legal_moves)))
>>> 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!

Legal moves for selected square (on image "11")

testing best moves finding methods:

Example

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)

Metadata

Release files for py-draughts 1.0.0

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

Source distribution (sdist)

Source distribution for py-draughts 1.0.0
File Size Uploaded
py-draughts-1.0.0.tar.gz 32.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-draughts 1.0.0
File Interpreter ABI Platform
py_draughts-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 65.6 kB

Release files / py-draughts-1.0.0.tar.gz

Download URL py-draughts-1.0.0.tar.gz
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1ceae7174697a2403434101be267a8c0e438379fe40dec0cbda8ae273591abc1
BLAKE2b-256 checksum
How to use checksums
b6176dbba45cddb8ba037c8cfbd0e8a01466bbc39ef48d48148ecd6124589f1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / py_draughts-1.0.0-py3-none-any.whl

Download URL py_draughts-1.0.0-py3-none-any.whl
Size 33.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7897b8a2292a881ea1f28fb88f32809898def411c56a3aa189d3b2a36b21e2c
BLAKE2b-256 checksum
How to use checksums
384f14f24ba734e9b099d105a9fda78a7dd8a728560d4ebf276d8ddbf4d44dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

1.9.1

2 release files

1.9.0

2 release files

1.8.4

2 release files

1.8.3

2 release files

1.8.1

2 release files

1.7.1

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.8

2 release files

1.5.5

2 release files

1.5.2

2 release files

1.5.0

2 release files

1.4.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

This release

1.0.0 This release

2 release files

0.9.9

2 release files

0.9.0

2 release files

0.3.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