CPSC 120B - Assignment #3

Phase I Due by Saturday, November 12, 2005 at 5:00 pm
Completed Project by Friday, November 18, 2005 at 4:00 pm

In this assignment you will write an object-oriented program to play the game of Nim (reverse Nim). The game has two players and a "board" that consists of three rows of sticks. In his or her (or its) turn, a player removes any number of sticks from one row of the board. The player who clears the board of sticks after a move loses the game. (NOTE: In some versions the player who removes the last stick wins but we are doing the reverse.)

Your program should work for a player being either a person or a computer. Near the beginning the program should prompt for the names of each player and, for each player, ask whether the player is a person or a computer.

Your program should then prompt the user for the number of sticks in each row to set up the Nim board. The player whose name was entered first will take the first turn. A human player will enter two integers for a turn - the first will be the number of the row they want to remove sticks from and the second will be the number of sticks to remove from that row. The program should make sure that the numbers input are valid. A computer player will generate a random play - that is a row number between 1 and 3 and then a random number of sticks to remove from that row (the play generated should be valid). After each player makes a move the board should be displayed in a format similar to the following:


Row 1: | | |
Row 2: | |
Row 3: | | | | | |

The players continue taking turns until no sticks remain. The program should keep track of the number of moves made by each player and the total number of sticks removed by each player. At the end of a game it should print the name of the winner along with the number of moves and the number of sticks removed for each of the players.

After each game the program should ask if the user wants to play again. If so, ask again about the number of sticks in each row (but assume the players will be the same) to set up a new board. The program should keep track of overall statistics - how many times each player won, the average number of moves the winning player made, the minimum number of moves the winning player made, and the maximum number of moves the winning player made. These statistics should be printed at the end of the program.

Step #1: Design (due in class Wednesday, Nov. 9)

Step #2: Implement Phase I Specifications for this will be handed out in class Wednesday.

Step #3: Correct & Complete the Program!

Requirements: As always, your program should:

Grading As usual your program will be graded on both style and correctness with very little credit for a program that does not compile or run. A grading rubric will be handed out.

Academic Integrity Reminder: Programming assignments are to be your own work. You may get help on the specifics of the assignment from no one except the instructor. You may not show your program to anyone or look at anyone's program or share ideas with anyone about how to write the program.

Hand in: For phase I just send a tar file by email. For the completed project send a tar file and hand in printed copies of all program files.