We have provided for you most of what you need to build a graphical application to play the NIM game Lab5.zip. As always, download and unzip the files on your removable media and create/save a Dr Java Project file in your directory. Here is a summary of the names of the source files with an explanation of their purpose. The details are in the doc files.

  • SimpleNIMGUI,java – the user interface to the game
  • SimpleNIM.java– the game itself
  • Player.java– common code for player objects (human or computer)
  • HumanPlayer.java– represents the human player
  • MachinePlayer.java– represents the computer player
  • NIMStrategy.java- you need to write this class. This class needs only one method:
    • public int bestMove(Player player, SimpleNIM game) – returns the number of sticks the computer player takes given the current state of the game.
    • The parameters mean: player – the computer player, game – the current game.
  • Try different strategies for the computer player:
    • Start by having the computer player take one stick no matter what the configuration of the game. This will allow you to play and see that the game works.
    • Have the computer play the best strategy where, if possible, take the number of sticks such that after the move, the number of remaining sticks is one more than a multiple of 4. If it is not possible to leave one more than a multiple of 4 sticks, then take one stick. For example, if there are 18 sticks remaining, the computer should take one stick.
  • You will need to use at least one method of the SimpleNIM class in order to write your bestMove method.

Lab Report

Write a document describing your experiences. Your lab must be printed (not handwritten). Answer the following questions related to what you did in this week’s lab.

  • What is wrong with the strategy of having the computer player always take two sticks with every move? Explain.
  • What method(s) of the SimpleNIM class did you need to use in writing your method?
  • Comment on the usefulness of the Javadco documentation for learning how to use a method of the SimpleNim class.
  • Describe what you learned doing this lab. Explain what was difficult and what was easy.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.