CPSC 231: Assignment 5 (Due Friday Nov. 15)
Weighting = 6%
A link to last summer's assignment 5 (The Game of Life) that you may or may not find useful. You can also run the source code for the solution to this assignment by looking under the path: /home/231/assignments/assignment5/oldAssignment5.
White player's side |
![]() |
Red player's side |
Figure 1: The board |
The game of checkers has been in existence for several hundred years and during that time many different variations have been developed. However for most of these versions there exists a common set of rules:
Yes | No |
![]() |
![]() |
Figure 2: How checker pieces move |
Yes | No |
![]() |
![]() |
Figure 3: Pieces only move one diagonal at a time. |
Yes | No |
White player's side | White player's side |
![]() |
![]() |
Red player's side |
Red player's side |
Figure 4: Uncrowned pieces can only move forward |
Single jump | Combining single jumps |
![]() |
![]() |
Figure 5a: A single jump for a turn | Figure 5b: Combining multiple jumps for a turn |
Effect of single jump | Effect of multiple jumps |
![]() |
![]() |
Figure 6a: Single capture | Figure 6b: Multiple captures |
White player's side | White player's side |
|
|
Red player's side | Red player's side |
Figure 7a: White piece moves to the row furthest from the white player |
Figure 7b: This piece gets crowned and becomes a king (indicated with a star) |
|
Figure 8: Kings can move either forwards or backwards in a diagonal fashion one square at a time. |
In addition to these generic rules there are some rules that are specific to your assignment:
For this assignment you are to implement a non-graphical game of checkers. Checker pieces will be represented by alphabetic characters:
Red player | White player | |
Uncrowned piece | r | w |
Crowned piece (king) | R | W |
The board will be represented with the ASCII vertical bar "|" and the ASCII horizontal bar "-". Each row and column will be numbered from 1 to 8. The row nearest the top of the screen will be numbered "1" and successive rows below that will be numbered sequentially numbered from 2 to 8. The left most column will be numbered "1" and successive rows to the right of this column will be numbered sequentially from 2 to 8. Thus the grid representing the checker board with the pieces in the starting positions will look like the grid shown in Figure 9.
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ||||||||||
- | - | - | - | - | - | - | - | ||||||||||
1 | | | | | r | | | | | r | | | | | r | | | | | r | | | ||||
- | - | - | - | - | - | - | - | ||||||||||
2 | | | r | | | | | r | | | | | r | | | | | r | | | | | ||||
- | - | - | - | - | - | - | - | ||||||||||
3 | | | | | r | | | | | r | | | | | r | | | | | r | | | ||||
- | - | - | - | - | - | - | - | ||||||||||
4 | | | | | | | | | | | | | | | | | | | ||||||||
- | - | - | - | - | - | - | - | ||||||||||
5 | | | | | | | | | | | | | | | | | | | ||||||||
- | - | - | - | - | - | - | - | ||||||||||
6 | | | w | | | | | w | | | | | w | | | | | w | | | | | ||||
- | - | - | - | - | - | - | - | ||||||||||
7 | | | | | w | | | | | w | | | | | w | | | | | w | | | ||||
- | - | - | - | - | - | - | - | ||||||||||
8 | | | w | | | | | w | | | | | w | | | | | w | | | | | ||||
- | - | - | - | - | - | - | - |
Figure 9: Displaying the board with a grid.
To draw the grid you are allowed to use the code provided in the example program grids.p which can be found in Unix under /home/231/assignments/assignment5. Although it isn't mandatory for you to use the code in this program for your assignment, your checkers program MUST use the system of numbered grids shown in Figure 9 to display the board. Failure to display the checker board using this grid will result in the loss of two letter steps e.g., "A" to "B+". JT: This may seem harsh but imagine you are the TA trying to determine if the 75+ checkers games that he or she will get from the students are working without the benefit of this grid.
The starting pattern of checker pieces must be read in from a file. Your checkers games will be playable only by human opponents. You do not have to write a program that will have computer controlled players. A player moves a piece by typing in the row and column coordinates of the piece that he or she wishes to move. Assuming that the player has selected a square containing a piece that belongs to him or her, then the player will type in the row and column coordinates of square that the player wishes to move the piece to.
The student has invested a considerable effort in the assignment but the program but it does not compile.
The student has invested a considerable effort in the assignment, the program compiles but does it not fulfill any of the specifications listing in the assignment.
The program can read the information for the checker board containing only a single piece from the file called "board1"1 from a file.
Checker game options: |
(M)ove a piece |
(Q)uit game |
Fulfills all the requirements of the C- version plus:
The program will check that pieces are only moved diagonally. If the player tries to move a piece in a non-diagonal fashion, then the program will indicate that pieces can only be moved diagonally and continue prompting the user for the destination coordinates until a valid set of values has been typed in.
Fulfills all the requirements of the C version plus:
The program will check that pieces are only moved forward. If the player tries to move a piece backward then the program will indicate that uncrowned pieces can only be moved forward and it will continue prompting the user for the destination coordinates until a valid set of values has been typed in.
Fulfills all the requirements of the C+ version plus:
When a piece reaches the far row it will be crowned and become a king (indicated by changing the piece from a lower case letter to a capital letter). Crowned pieces are given the ability to move forwards as well as backwards in a diagonal fashion.
Fulfills all the requirements of the B- version plus:
Fulfills all the requirements of the B version plus:
Players can capture pieces of the opposing color. When the player enters in a set of destination coordinates, then the program will determine if this move results in the capture of an opposing piece. The program should check to see if attempted jumps are valid by checking that pieces only jump diagonally and that an opposing piece will actually be captured by the jump. If the jump and capture is valid, then the opposing piece is removed from the board and the player's piece is moved to the appropriate location on the board. If it is not valid then the program will indicate that this is not a valid jump and it will continue prompting the player until a valid set of destination coordinates have been entered. This version of the game need only handle the case where single jumps are made for each turn. Multiple jumps in a turn will be handled by the A- version of this assignment.
Fulfills all the requirements of the B+ version plus:
In situations where multiple jumps are possible the player can indicate to the program that he or she wishes to perform a multiple jump by entering (0,0) for the row/column coordinates. The program will then prompt the user to input the coordinates for each square that the player wishes to jump to until the player types in (0,0) again to indicate that he or she has completed the multiple set of jumps. The program will then check this path in order to determine if it is a valid series of jumps. If this is a valid set of multiple jumps then the appropriate opposing pieces will be removed from the board and the player's piece will be moved to the coordinates of the final destination square. If this is not a valid set of multiple jumps then the program will indicate to the player that the path that they provided is not valid for a multiple jump and it will prompt the person to enter in a valid set of destination coordinates.
Fulfills all the requirements of the A- version plus:
The program can determine when a player has won the game. At the end of each player's turn, the program will check to see if the opposing player has any pieces left and if this is the not case then the program will indicate that the player has won and the game will end.
Fulfills all the requirements of the A version plus:
Add two extra menu options (see below) to allows the player to save and load games. When a game is saved, your program will write out to a text file the positions of the pieces at that point in the game. The format and appearance of this file will be similar to the one for board2 and consist of upper and lower case alphabetic characters representing the red pieces "R" and "r" and the white pieces "W" and "w" and spaces for empty squares. The load game option will read in the position of the pieces from a previously saved game and allow the player to continue playing the game from that point onward.
Checker game options: |
(M)ove a piece |
(L)oad a game |
(S)ave game |
(Q)uit game |
1 You are of course allowed to change the names of these files.
1. Good coding style and documentation: They will play a role in determining your final grade for this assignment. Your grade can be reduced by a full step e.g., "A" to "A-" for poor style.
Understanding and using two-dimensional arrays in Pascal. Learning how to read information from files.
There are two major steps required in the submission of this assignment:
1. Step for the electronic submissionUse the submit system to electronically submit the source code for your assignment i.e., the file with the dot-p ".p" suffix. In addition you must also submit a text file called "README" for your TA. This file will provide step-by-step instructions for running your program, as well what version of the assignment you have completed e.g., the A version, the B version etc. Since this is a complex assignment with multiple requirements it is crucial that clearly indicate in the README file what version of the assignment that you have completed. Failing to include this information will result in a grade reduction of one step (e.g., "A" to "A-"). Other information to include in the README includes any special cases or conditions that you may have implemented which are extra to the requirements of the basic assignment. As was the case with previous assignments, you need to include a set of instructions that describe how to run your program. These instructions must be clear and complete enough so that your TA will know how to mark your assignment. Don't expect your marker to have to decipher cryptic instructions, he or she will only work with the instructions that they provided with (by you) and grade your assignment accordingly.
2. Step for the paper submission
Print out the source code for your assignment (print the source code directly rather than running a script and then printing the script) and put the source code into the appropriate drop box located on the second floor of Math Sciences.