Lab 07: Nim Game
Due: 09:59 AM on Friday, Oct 28 Points: 100 points.
Mission:
• Write a program that allows two human players to play Nim against each other.
• The program should detect when the last counter has been taken and declare a winner.
• Let me introduce you to Nim Game. Watch this Video first to understand the game.
Instructions:
• Create a project called Lab7 with one project class called NimGame.
• Be sure to document your code (add comments on top of your java file). In the comments add your name, date,
course, homework number, and statement of problem.
• Once you are done, upload java file NimGame through Blackboard.
Objective and points break down for each project:
• As described below.
Project: NimGame
•
Nim is a strategy game between two players.
Start by placing counters (coins or toothpicks or something) into 3 piles.
• You need to randomly generate those “3” counters. (Take a look at Random slides presentation).
• Those 3 counters should have a value between 5 and 10. So the minimum value is 5 and the
maximum value is 10.
Player #1 picks a pile, then removes one or more counters from that pile. (It’s okay to take the whole pile.) Player #2 picks a pile, then removes one or more counters from that pile.
Player #1 plays again. (It’s okay to choose a different pile this time.)
Whichever player is forced to take the last counter is the LOSER.
Write a program that allows two human players to play Nim against each other.
The program should detect when the last counter has been taken and declare a winner.
• •
1.
2. 3. 4. 5.
(35 points) Basic Version:
Here is an example game, with starting piles of 3, 4, and 5 counters.
(30 Points) – Cheat Protection
Prevent the users from doing anything bad:
And what about this?
And don’t forget this:
(10 Points) – Dignity
Make your program detect when there is only one counter left and declare the winner one turn earlier.
NEW: Fancy display: You can choose either rows display vs. columns display.
Both have same points weight.
(25 Points) – Fancy Display (Rows)
Visually display the counters in rows instead of just showing a number. You must use loops for this.
OR
(25 Points) – Fancy Display (Columns)
Visually display the counters in columns. You must use a loop for this.