This project is due on the last day of class. It is worth 100 points. You will be graded on the graphics and quality of your program’s performance including its resistance to crashing in the middle of play. You will also be graded on the style of your programming including use of procedures, parameters, recursion and appropriate data structures. Finally, you will be graded on your documentation including how easy it is for me to understand your code. Each group should demo their project to me before the final, and then email me the final version. Do not submit your project into ELearn.
Write a program to allow a person to play Four-Row Nim against the computer. Recall that in this game four rows of sticks are displayed and players take turns removing as many sticks as they wish (zero is not allowed) but from only one row. The player who removes the last stick wins.
The program should explain the rules and tell the user to hit any key when he/she is ready to play. Then the program should show the initial setup of sticks and give the user the choice of going first or second. After the game, the player should be allowed to play again. After the player no longer wishes to play, a tally of how many games the player won out of the total number of games played should be printed. For presentation, you should ask the person their name and refer to them by name in all subsequent messages. During play, only legal moves should be allowed, and the end of the game should be detected.
You need to decide how the user interaction will choose which sticks to take. One way is to have 12 buttons: 4 "+" buttons and 4 "-" buttons to allow the user to adjust the amount they might want to remove from any row, and four buttons labeled "submit" that indicate the user is ready to remove the number they chose from that particular row. A less flexible GUI option can be seen here. You can also imitate this GUI if you wish.
You will need four data structures to hold the current number of sticks in each row, and with my suggested GUI, you will need four additional data structures to store the numbers the user intends to remove.
In any GUI (graphical user interface) program there is usually an underlying data structure that keeps track of the information that is displayed. The picture you see on the screen reflects this data structure, but it is important to realize that the picture the computer draws on the screen is not the same as this data structure. This idea of keeping an abstract data model of the board is called separating the "model" from the "view".
A simple data structure for this project is a collection of four numbers, :r1, :r2, :r3, and :r4.. These numbers should be chosen randomly at the start of the game and each should be between 0 and 10 inclusive. As the game progresses, this list must be updated to reflect the current state of the game. Depending on your GUI choice, you may need four additional data structures :d1, :d2, :d3, and :d4 to store possible values to remove.
Besides helping display a current picture of the board, this list can be accessed in order to handle many other useful tasks, including:
checking if someone won
checking if a move is legal, and
determining a legal (or even clever) move for the computer
For example, let's examine the procedure that checks if someone won. This procedure simply checks whether all the ":r" data structures equal zero.
A preliminary outline of your program very similar to the Nim outline I gave you for assignment 5 should be designed before you even touch the computer. This will ensure that your program is organized and that you will not have to redesign it in the middle. You should show this to me in class as soon as it is complete, and I will help you make any necessary modifications. Of course, I will help you with any details as questions come up.
Grading
Grading will be done as follows:
a. Follow all specifications: 50%
b. No bugs or crashes: 25%
c. User interface experience: 15%
d. Code, style, and documentation: 10%
Extra Credit for Early Demo
You can earn ten points extra credit as a group by finishing your project before the last week of class, and demonstrating it to the class during the last week.