MONT 105S, Spring 2009
Home | | Course Schedule | | Assignments | | Lecture NotesDue Wednesday, February 4, at the beginning of class.
Introduction
The game of Nim is a simple board game played between two players.
The game board consists of some number of squares in a line. Each player is allowed to
place 1, 2, or 3 markers on the board in turn. Player 1 plays with X's and player 2 plays
with O's. The winner is the player who places their marker in the last square. The following
figure shows a decision tree for this game when the board has 7 squares.
In this project, you will create and implement a decision tree for a 6 square game of Nim. The rules are exactly the same as for the 7 square version, except there are only 6 squares on the board. The winner is the player who places a piece on the 6th square.
Decision Tree
First you will create a decision tree for the 6-square game of Nim. The
user makes the first move, placing 1, 2 or 3 X's on the board. If the user plays 1 or 2 X's,
the computer should respond with a single O. If the user plays 3 X's, the computer
should play three O's (to win and end the game). In the first 2 cases, the user makes a
second move of 1, 2, or 3 X's. The computer should then respond with an appropriate
move to win the game or report that the user has won. Note that there should be only one
condition under which the user wins. Draw the decision tree for this 6-square game of
Nim.
Program Description
The program will implement the decision tree you develop above.
The user will be prompted for their move, and they should enter 1, 2 or 3 X's. Depending
on the user's entry, the program will make a move of 1,2 or 3 O's as shown in your
decision tree. When the last (6th) box is filled, the program reports the winner.
Project Specifications
Place all your code in a file named <username>_nim.py,
where <username> refers to your own username. For example, Professor Royden's file
would be named croyden_nim.py.
Specifications for Documentation and Format.
Fully correct documentation for this homework assignment must include:
Specifications for Output.
Directly below, you can see an example of the display that
will appear on the monitor screen during the prompting for user input and the computer
responses for two sample games. Note that after the user's second move
the computer reports the final
board status before announcing the winner. Underlined characters indicate user input.
Sample Game 2:
Sample Game 3:
Sample Game 4:
Sample Game 1:
What is your move? X
The board is X.
I play O.
The board is XO.
What is your next move? X
The board is XOX.
I play OOO.
The board is XOXOOO.
I win!
What is your move? XX
The board is XX.
I play O.
The board is XXO.
What is your next move? XXX
The board is XXOXXX.
You win!
What is your move? XX
The board is XX.
I play O.
The board is XXO.
What is your next move? XX
The board is XXOXX.
I play O.
The board is XXOXXO.
I win!
What is your move? XXX
The board is XXX.
I play OOO.
The board is XXXOOO.
I win!
To Submit Your Finished Project:
1. Hand in your decision tree in class on the project's due date.
2. Hand in a hard copy of the file <username>_nim.py in class on the project's due date.
3. Hand in a printout of 4 sample games like those shown above in class on the project's due date.
4. Print your name at the top of the cover page and staple it to the top of your hard copy.
5. In addition to the hard copy listed above, email your <username>_nim.py file to me at croyden@mathcs.holycross.edu. The subject line should read: mont105S hw4 <your_username>.
Get started early and have fun!