Course resources for the Introduction to Computer Science I by James Tam | Return to the course web page |
Due: 4 PM Friday December 9
Lists, file input and output, classes and objects
For this assignment you’ll be asked to implement a simplified version of the checkers game.
Checkers is a game that's played on a board with 64 squares (8 rows x 8 columns). There are two players: one controls 12 white pieces, while the other controls 12 red pieces. The game is run on a turn-by-turn basis during which each player can move one of his/her pieces or take an opposing piece. Player's alternate turns.
In this simplified version of checkers, there are only two possible types of moves for each player.
Pieces can move to an adjacent, empty square that is left, right, forward or backward (Figure 1). When a piece is moved, the previous square is empty and the destination will contain the piece that was moved.
|
Figure 1: For each piece there is a maximum of 4 valid destinations |
An opponent’s piece can be taken from the board (Figure 2). The following conditions must hold for this to be possible.
The player’s piece is adjacent (left, right, forward, or backwards) from an opponent’s piece.
The square after the opponent’s
piece (continuing in the same direction) is empty, the player can
take the opponent’s piece.
|
|
|
Figure 2A: Valid capture |
|
Figure 2B: Invalid capture (destination not empty) |
The game is over when all of one of the player's pieces has been removed from the game. (This player loses the game.)
Your program needs to be written using the three classes: Piece, Checkers and Board. Each of these classes should have methods and attributes that are appropriate for the class.
A partial solution [Link to the starting code] is provided if you wish to use it. This solution contains a complete implementation for the Piece and Checkers classes and a partial solution for the Board class. The methods that are required in the Board class are clearly indicated.
If you wish you can write your own code for class Piece and class Checkers but it is isn't recommended because it will add a fair amount of work and you won't get credit for the code in these classes.
Similar to previous assignments your program will be marked both for functionality and quality of design and code.
In order to get full credit for the assignment you are to follow the rules stated in this assignment description rather than any other outside sources. Your program will be played by two human players, there is no computer-controlled opponent.
When the game is started, the user must be presented with option of continuing a saved game. If the user does not wish to start with a saved game, the first player to take a turn should be white and board should be set up as follows:
If the user does want to continue a saved game, then ask the user for the name of the file the game was saved in and read the board configuration and the player whose turn it is from the file. The next section contains a description of the format that the game should be saved in.
After the starting positions of the pieces have been determined the game will proceed in the following fashion:
1 Whenever a new game starts the white player gets the first move. If the game has been saved and reloaded from file then the game will resume where it left off (during the red or the white player's turn as appropriate). The above cycle repeats until either a player quits or the game has been won. The game can end during either player's turn.
During a single player’s turn
|
||
After each player has moved, the game should determine if the game has been won and if so the game should immediately end with an appropriate and correct congratulatory message (e.g., red player wins) and display the board one last time. (It should not proceed to the next player's turn because that person will have no pieces to move). Remember that the game can also end whenever either player selects 'q' at the main menu. |
||
|
Assignments must be completed individually, collaboration or group work is not permitted
Assignments must be electronically submitted using the UNIX submit program.