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
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.
>>> 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("37-32")
>>> board.pop() # undo last move
Move: 37->32
- detects draws and wins
>>> board.game_over
False
>>> board.is_threefold_repetition
False
- Validate and generate moves
>>> board.push_uci("10x42")
Move: 37->32 is correct, but not legal in given position.
Legal moves are: [Move: 28->37, Move: 31->22]
>>> list(board.legal_moves)
[Move: 28->37, Move: 31->22]
- 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
- Allows to play against AI.
- Allows to play vs another player. (on the same computer)
- Allows to test and find bugs in your engine.
python -m draughts.server
Use for testing your engine.
Example with simplest possible engine.
>>> 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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py-draughts-1.1.5.tar.gz.
File metadata
- Download URL: py-draughts-1.1.5.tar.gz
- Upload date:
- Size: 34.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b149cc18b900033d2a4fa10ace8ceb7404ae8846eb8e0343802ad14f3d716ccf
|
|
| MD5 |
46973207a32f3baf43d944531ca0f2cf
|
|
| BLAKE2b-256 |
c36a59068316ad34557aaf300ccc97628783d9bad360f520a2d979dca660b2dc
|
File details
Details for the file py_draughts-1.1.5-py3-none-any.whl.
File metadata
- Download URL: py_draughts-1.1.5-py3-none-any.whl
- Upload date:
- Size: 35.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52b141a18045bc498d996216823caf8b0888392d1d97af9e34351d872e9e4479
|
|
| MD5 |
f0fe2f71ac02e7e48402e52d1e29fa5c
|
|
| BLAKE2b-256 |
97cec7263dc29a14bbc5d7b3b76b78e9e02ff1b18f538fe304e800198791489f
|