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.
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:
a. Follow all specifications: 50%
b. No bugs or crashes: 25%
c. User interface experience: 15%
d. Code, style, and documentation: 10%
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.