Professor Simonson       How Computers Work

CSC 195

Programming Project - Four-Row Nim


This project is due on the day of the final exam.  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.

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 then 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.  You will need four data structures to store these numbers.  Four more buttons labeled "submit" will tell the program that 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.

Hints on Structuring Your Program

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:

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, Early Demo, and AI

The minimum requirements for this assignment, is to have the computer play random legal moves.  You can earn up to 25 points extra credit by adding more "intelligence."  Indeed, there is a mathematical strategy using binary numbers that plays Four-Row Nim perfectly!  Strategies for adding "AI" can be discussed with me.  Note:  Although your basic project is a group grade, individuals may do extra credit on their own.  If that is the case, please let me know clearly which person is responsible for which enhancements.

You may also earn up to 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.