A draughts library for Python, with move generation and validation, PDN parsing and writing. Supprots 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
Usage
Initialize board
>>> from draughts.standard import Board
>>> board = Board()
Board initialized with shape (10, 10). (base.py:108)
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")
Shows simple ascii board
>>> print(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 | |
American checkers
>>> from draughts.american import Board
>>> board = Board()
Board initialized with shape (8, 8). (base.py:108)
>>> print(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([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 "16")
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
py-draughts-0.9.0.tar.gz
(30.8 kB
view hashes)
Built Distribution
Close
Hashes for py_draughts-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff287d629a2b1d5c774f466e22fb31818b34a901bcaba91dea8961e55d6e2628 |
|
MD5 | ec5f70a4054f589624f26703f2429be6 |
|
BLAKE2b-256 | fee08f1c5097adbc41fe62f0f6d766c2da75f0844fcaf2a25eb5cc0a65c9d047 |