CSE 131 Module 2: Choice & Iteration

Important!

Before beginning any work, do a Team...Pull in your repository.

Game of Nim

Nim is a game of strategy in which two players take turns removing sticks from a common pile. There are many variations of Nim but for the purposes of this assignment, we will stick with a simple and common implementation. On each turn, a player must remove either 1 or 2 sticks from the pile. The goal of the game is to be the player who removes the last stick.

In this assignment, you will design a game in which one human player is competing against a computer. The human player should also be able to decide if he or she wants to play the first or second move.

It's important to note that while there is a winning strategy for this game, you are required only to implement a computer player which employs random moves.
Example output of one game:
```Computer starts
Round 0, 7 sticks at start, computer took 2, so 5 sticks remain
Round 1, 5 sticks at start, human took 1, so 4 sticks remain
Round 2, 4 sticks at start, computer took 2, so 2 sticks remain
Round 3, 2 sticks at start, human took 1, so 1 sticks remain
Round 4, 1 sticks at start, computer took 1, so 0 sticks remain
Computer wins
```

Notes

• Clearly, the human could have played better in the above game.
• The computer randomly removes 1 or 2 sticks, but cannot remove more sticks than are left.
• The human is prompted at each turn for how many sticks he or she wants to remove.
Be careful! A human might enter 5 if 5 sticks are left, and if you are not careful, the human could win by playing in that way.
Don't accept the user's input if it is illegal. Continue prompting until you get a valid input.
• Start your work by creating a Nim class in the lab2 package of the labs source folder in your repository.
• Use ArgsProcessor to prompt for inputs.
• Your program must continue play until somebody (computer or human) wins.
• Your output should resemble the sample output shown above.
• When you demo this assignment, be prepared to discuss how you would implement a dominant strategy with your TA

• You must commit and push all of your work to your repository. It's best to do this from the top-most level of your repository, which bears your name and student ID.
• You must demo the commited work to a TA. Make sure the TA knows that your demo is for credit at this point.
• Follow the directions below to have your demo for this work recorded.

When you are done with this lab, you must be cleared by the TA to receive credit.
• Do a Team…Pull to update your repository. You must do this or the commit/push below may fail.
Make certain this has worked by logging into bitbucket. There you will see the commit(s) in your news feed if it was successful. You can also check the Source page to locate and ensure your code was received.

It is your responsibility to make certain the code has been pushed. Some of your work receives credit through testing of your pushed code. You will receive no credit for such work if you failed to push. We generally reserve the right to revoke credit for any of your work that has not been pushed on-time.

• Fill in the form below with the relevant information
• Have a TA check your work
• The TA should check your work and then fill in the TA's name
• Click OK while the TA watches
• If you request propagation, it does not happen immediately, but should be posted in the next day or so

This demo box is for lab 2
 Last name WUSTL Key Propagate? (NOT your numeric ID) Do not propagate lower case only e.g. Smith j.smith 1

Acknowledgements and assertion of integrity

 You must select one of the options below The work submitted here was performed in accordance with this course's policy on collaboration. On your honor, you have neither given nor received any unauthorized aid on this assignment. However, the following TAs, students, or professors were supportive in completing this assignment. Their help was also in accordance with course policies. Thanks to (leave blank if appropriate): In spite of seeking help as allowable by this course's policy on collaboration, you were unable to complete this assignment. No credit will be received for this assignment. You would like to be contacted by an instructor to facilitate staying on track in this course. Comments about this: You have NOT abided by this course's policy on collaboration. No credit will be received for this assignment, but by checking this box, no academic integrity violation will be filed for this assignment. You would like to be contacted by an intructor to faciliate staying on track in this course. Comments about this:

TAs double check!
• This demo box is for lab 2
• The student has committed and pushed the work, and verified that it appears at bitbucket.