Exercise 1. (20 points): Nim: The game of Nim starts with a random number of stones between 15 and 30. Two players alternate turns and on each turn may take either 1, 2, or 3 stones from the pile. The player forced to take the last stone loses. Create a Nim application that allows the user to play against the computer. In this version of the game, the application generates the number of stones to begin with the number of stones the computer takes, and the user goes first The Nim application code should:
Prevent the user and the computer from taking an illegal number of stones. For example, neither should be allowed to take three stones when there are only 1 or 2 stones left.
Include an isValidEntry() method to check user input.
Include a drawStones() method that generates a random number from 1 to 3 for the number of stones the computer draws.
Include separate methods to handle the user’s turn and the computer’s turn.
Application output should look similar to:
There are 22 stones. How many would you like? 3
There are 19 stones. The computer takes 2 stones.
There are 17 stones. How many would you like? 3
There are 14 stones. The computer takes 2 stones.
There are 12 stones. How many would you like? 3
There are 9 stones. The computer takes 3 stones.
There are 6 stones. How many would you like? 3
There are 3 stones. The computer takes 3 stones.
The player beats the computer!
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more