Write a module to manage a game of checkers.

Write a module to manage a game of checkers.

Update: The original assignment description wasn’t as clear as it could’ve been. Some clarifications:

  1. The row and column in the (row, column) tuples are integers in the range [0,7] (inclusive).

  2. The starting positions for checkers are:

    Dark

    (0, 1), (0, 3), (0, 5), (0, 7)
    (1, 0), (1, 2), (1, 4), (1, 6)
    (2, 1), (2, 3), (2, 5), (2, 7)

    Light

    (5, 0), (5, 2), (5, 4), (5, 6)
    (6, 1), (6, 3), (6, 5), (6, 7)
    (7, 0), (7, 2), (7, 4), (7, 6)

Background

One of the most popular versions of draughts/checkers is English draughts/American checkers. In this game, played on an 8×8 checkerboard, two players (dark and light) alternate moving their checkers along diagonals to capture each other’s pieces (and do other things that are beyond the scope of this assignment).

Draughts
Figure 1. Initial positions of light and dark checkers on a checkerboard

Checkers can be moved diagonally one space to an empty square, but only in a forwards direction, i.e., toward the other player’s back row. Checkers can also be moved by jumping over an opponent’s checker to an empty square behind. This move captures the opponent’s checker, causing it to be removed from the board. As shown in Figure 2, “A dark checker capturing two light checkers”, multiple captures are possible in one move.

meerslag1
Figure 2. A dark checker capturing two light checkers

For this assignment, we will ignore additional rules like kings and mandatory jumping. If you read about those, don’t worry about them.

Objective

Write a Python module called checkers that implements three functions:

new_game

Creates a checkerboard with pieces set to their starting positions. You can use whatever data structure you like to represent the board, as long as your other functions can use it to do their jobs.

pieces

Counts the pieces of a particular colour on the board. Based on arguments passed to this function, it should either count the number of light or dark pieces on a checkerboard (using the data type created by new_game).

move

Move a piece from one square to another, returning a result code to indicate whether the move captures another piece or is invalid.

Details

The three functions that you need to implement should conform to the following specifications:

def new_game():
    """Create a checkerboard with pieces set to their starting positions."""

You can use whatever data structure you like to represent the board, as long as your other functions can use it to do their jobs. Once the board has been created, it should have a set of checkers located at the following starting positions:

Dark

(0, 1), (0, 3), (0, 5), (0, 7)
(1, 0), (1, 2), (1, 4), (1, 6)
(2, 1), (2, 3), (2, 5), (2, 7)

Light

(5, 0), (5, 2), (5, 4), (5, 6)
(6, 1), (6, 3), (6, 5), (6, 7)
(7, 0), (7, 2), (7, 4), (7, 6)

def pieces(board, light):
    """How many pieces of a particular colour remain on the board?

    Parameters:
      board:        a board object, as created by the new_game() function
      light:        True for light checkers, False for dark checkers
    """
def move(board, origin, destination):
    """Move a piece on a board from one square to another.

    Parameters:
      board:        a board object, as created by the new_game() function
      origin:       a (row, column) tuple
      destination:  a (row, column) tuple

    Returns:
      A tuple of (result code, updated board)

      Result codes:
        'Cap' if the move captures a piece
        'OK' if the move is valid but does not capture anything
        'Win' if the move wins the game by capturing the opponent's last checker
        'Err' if the move is invalid
    """

The row and column in the (row, column) tuples are integers in the range [0,7] (inclusive).

Submit your work to Gradescope in a Python module entitled checkers. Remember, assignments are individual work: you must complete the assignment yourself.