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!
Paper#71795 | Written in 18-Jul-2015Price : $27