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.
![Build Status](https://travis-ci.org/ImparaAI/checkers.png?branch=master)
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 checkers.game import Game
game = Game()
See whose turn it is:
game.whose_turn()
Get the possible moves:
game.get_possible_moves()
Make a move:
game.move([9, 13])
Check if the game is over:
game.is_over()
Find out who won:
game.get_winner()
Review the move history:
game.moves
Change the consecutive noncapture move limit (default 40
according to the rules):
game.consecutive_noncapture_move_limit = 20
game.move_limit_reached()
Review the pieces on the board:
for piece in game.board.pieces:
piece.player
piece.other_player
piece.king
piece.captured
piece.position
piece.get_possible_capture_moves()
piece.get_possible_positional_moves()
Testing
Run python3 -m unittest discover
from the root.