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.
![](https://private-user-images.githubusercontent.com/77834536/255870721-11e6be5e-0cfc-412c-ac0b-2b8e87a4f450.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5Mzg2NzEsIm5iZiI6MTcyNTkzODM3MSwicGF0aCI6Ii83NzgzNDUzNi8yNTU4NzA3MjEtMTFlNmJlNWUtMGNmYy00MTJjLWFjMGItMmI4ZTg3YTRmNDUwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDAzMTkzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJmMzE3YTIyN2NhZTY1ZDkzZGFkOTI5MjY5NGQ3Mjc2MmExOWYxOTY2MGM2NGUxNmFlOTc0MTExMmE4Nzc5ZWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.OmoRxYqbkrVdUJOcam1ojM2l2ENekQSNLLRG8iEXpP8)
pip install py-draughts
- 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
Important
Those methods are variant specific. Each variant has different set of them.
>>> 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
- 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
-
Writes PDN strings
>>> board.push_uci("31-27")
>>> board.push_uci("32-28")
>>> board.push_uci("27-23")
>>> board.push_uci("28-24")
>>> board.pdn
'[GameType "20"]
[Variant "Standard (international) checkers"]
[Result "-"]
1. 31-27 32-28 2. 27-23 28-24'
>>> 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
- 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.server
Example with simplest possible engine.
>>> from draughts 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!
Warning
Server will not start when using google colab
![](https://private-user-images.githubusercontent.com/77834536/255210303-11e4b7ea-4b47-4ab2-80b8-6d6cf1052869.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU5Mzg2NzEsIm5iZiI6MTcyNTkzODM3MSwicGF0aCI6Ii83NzgzNDUzNi8yNTUyMTAzMDMtMTFlNGI3ZWEtNGI0Ny00YWIyLTgwYjgtNmQ2Y2YxMDUyODY5LmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEwVDAzMTkzMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTI2NWMwZDkxMDM5NmVhZDMwMzNiOWJlYTZjZTU1NWMxYzAyZmQxODg4ODEwZWZlZGU3N2M5NTFkZDlmODkwNjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.lokc00CZgmt6cWfe3HYpYKxOJdpqt4MtbWtGzzydAy8)
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.