Library for playing a standard game of checkers/draughts
Project description
A Python3 library that you can use to play a game of checkers/draughts. This is just a set of classes that you can use in your code, it's not an interactive shell checkersgame.
#Note: This is a modified version of the Imparaai checkers library. Alongside the base module (which I forked from the repository at the above link), the Colorama and PrettyTable dependencies are also in use. The only addition I have made to this module is a graphical representation of the board.
Assumptions
The rules used are for competitive American checkers or English draughts. This means an 8x8 board with force captures and regular kings.
Each position on the board is numbered 1 to 32. Each move is represented as an array with two values: starting position and ending position. So if you're starting a new game, one of the available moves is [9, 13]
for player 1. If there's a capture move, the ending position is the position the capturing piece will land on (i.e. two rows from its original row), which might look like [13, 22]
.
Each piece movement is completely distinct, even if the move is part of a multiple capture series. In Portable Draughts Notation mutli-capture series are usually represented by a 5-32
(for a particularly long series of jumps), but in certain situations there could be multiple pathways to achieve that final position. This game requires an explicit spelling out of each distinct move in the multi-capture series.
Usage
Create a new game:
from BFHScheckers.game import Game
game = Game()
See whose turn it is:
game.whose_turn() #1 or 2
Get the possible moves:
game.get_possible_moves() #[[9, 13], [9, 14], [10, 14], [10, 15], [11, 15], [11, 16], [12, 16]]
Make a move:
game.move([9, 13])
Check if the game is over:
game.is_over() #True or False
Find out who won:
game.get_winner() #None or 1 or 2
Review the move history:
game.moves #[[int, int], [int, int], ...]
Change the consecutive noncapture move limit (default 40
according to the rules):
game.consecutive_noncapture_move_limit = 20
game.move_limit_reached() #True or False
Review the pieces on the board:
for piece in game.board.pieces:
piece.player #1 or 2
piece.other_player #1 or 2
piece.king #True or False
piece.captured #True or False
piece.position #1-32
piece.get_possible_capture_moves() #[[int, int], [int, int], ...]
piece.get_possible_positional_moves() #[[int, int], [int, int], ...]
Get a string representation of the pieces on the board:
str(game.board)
Output:
Testing
Run python3 -m unittest discover
from the root.
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
File details
Details for the file imparaai-BFHScheckers-for-BFHS-programming-1.4.2.4.tar.gz
.
File metadata
- Download URL: imparaai-BFHScheckers-for-BFHS-programming-1.4.2.4.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27cf20ee9a3822f61dd553b466cb7dc6a6f691d1ad534a60d8a3803c9df9924f |
|
MD5 | 3efbbcf559d70fbbffd91c3cf39c831a |
|
BLAKE2b-256 | 1c18ac62f5c610abff11b4bed78be924340fdcd297504d3bac5760377d7eae29 |
File details
Details for the file imparaai_BFHScheckers_for_BFHS_programming-1.4.2.4-py3-none-any.whl
.
File metadata
- Download URL: imparaai_BFHScheckers_for_BFHS_programming-1.4.2.4-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3be790c88f2a8406e6081d1475ee608c4039c3547f2d8612411629d3e1499eb |
|
MD5 | b176d42041e74c23ea7cfc0bca5a67b2 |
|
BLAKE2b-256 | 451c815dd696e2991490c8b85cf1c0fc29aae1f748468eede7468d9e32082948 |