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
Key features
- Provides beautiful web interface for testing your engine/playing against AI.
- Supports multiple variants of the game (with different board size).
standard
,american
etc. - Follows international draughts standards. like
fen
pdn
etc. - Allows to easily create new variants of the game. by extending the
Board
class. - Accurate documentation generated from code.
Documentation
Usage
Displays simple ascii board
>>> from draughts import get_board
>>> board = get_board("standard")
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 =get_board('standard', "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 import get_board
>>> board = get_board("american")
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
- Allows to play against AI.
- Allows to play vs another player. (on the same computer)
- Allows to test and find bugs in your engine.
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!
testing best moves finding methods:
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-1.1.0.tar.gz
(33.3 kB
view hashes)
Built Distribution
Close
Hashes for py_draughts-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54a6628614faed6d830086e8bc5d3eac1bff177090d98a27b77d632b287c8ed0 |
|
MD5 | 6e0bc8ff8f16292e8bf1d8863a4148f4 |
|
BLAKE2b-256 | c53d4e5dfee44628f5019958ebc94bc02eea28a181e220df6581cce6a5307795 |