The Game of Nim Problem Description: Two players alternately take marbles from a pile. In each move, a player chooses how many marbles to take. The player must take at least one but at most half of the marbles. The other player takes a turn. The player who takes the last marble loses. Write a program to simulate a game of computer vs. human being. Generate a random number between 10-100 to denote the initial size of the pile. Simulate a coin toss to determine who goes first, the computer or the human. Simulate a coin toss to decide if the computer plays smart or stupid mode. In stupid mode, the computer simply takes a random legal number between 1 and n/2 whenever it has a turn. In smart mode the computer takes off enough marbles to make the size of the pile a power of two minus 1 (that is, 3, 7, 15, 31, or 63). That is always a legal move, except if the size of the pile is currently one less than a power of 2. In that case, the computer makes a random legal move. Note that the computer cannot be beaten in smart mode when it has the first move, unless the pile size happens to be 15, 31, or 63. If the human player knows the winning strategy and takes the first turn, he can win against the computer. Program Requirements: The program must define and use the following methods, • int getComputerStupidMove(int num) Il retum number of marbles to be moved in stupid mode if current marble number is num. int getComputerSmartMove(int num) Il return number of marbles to be moved in smart mode if current marble number is num. boolean computerTurn( ) Il retum true if it is computer's tum and false if human player's turn • boolean smartMode() Il retum true if it is in smart mode and false if in stupid mode

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27PE
icon
Related questions
Question
100%

I'm confused every thing....

The Game of Nim
Problem Description:
Two players alternately take marbles from a pile. In each move, a player chooses how many
marbles to take. The player must take at least one but at most half of the marbles. The other
player takes a turn. The player who takes the last marble loses.
Write a program to simulate a game of computer vs. human being. Generate a random number
between 10-100 to denote the initial size of the pile. Simulate a coin toss to determine who goes
first, the computer or the human. Simulate a coin toss to decide if the computer plays smart or
stupid mode. In stupid mode, the computer simply takes a random legal number between 1 and
n/2 whenever it has a turn. In smart mode the computer takes off enough marbles to make the
size of the pile a power of two minus 1 (that is, 3, 7, 15, 31, or 63). That is always a legal move,
except if the size of the pile is currently one less than a power of 2. In that case, the computer
makes a random legal move.
Note that the computer cannot be beaten in smart mode when it has the first move, unless the pile
size happens to be 15, 31, or 63. If the human player knows the winning strategy and takes the
first turn, he can win against the computer.
Program Requirements:
The program must define and use the following methods,
• int getComputerStupidMove(int num)
I/ return number of marbles to be moved in stupid mode if current marble number is num.
• int getComputerSmartMove(int num)
I/ return number of marbles to be moved in smart mode if current marble number is num.
boolean computerTurn( )
Il return true if it is computer's turn and false if human player's turn
boolean smartMode()
Il return true if it is in smart mode and false if in stupid mode
Transcribed Image Text:The Game of Nim Problem Description: Two players alternately take marbles from a pile. In each move, a player chooses how many marbles to take. The player must take at least one but at most half of the marbles. The other player takes a turn. The player who takes the last marble loses. Write a program to simulate a game of computer vs. human being. Generate a random number between 10-100 to denote the initial size of the pile. Simulate a coin toss to determine who goes first, the computer or the human. Simulate a coin toss to decide if the computer plays smart or stupid mode. In stupid mode, the computer simply takes a random legal number between 1 and n/2 whenever it has a turn. In smart mode the computer takes off enough marbles to make the size of the pile a power of two minus 1 (that is, 3, 7, 15, 31, or 63). That is always a legal move, except if the size of the pile is currently one less than a power of 2. In that case, the computer makes a random legal move. Note that the computer cannot be beaten in smart mode when it has the first move, unless the pile size happens to be 15, 31, or 63. If the human player knows the winning strategy and takes the first turn, he can win against the computer. Program Requirements: The program must define and use the following methods, • int getComputerStupidMove(int num) I/ return number of marbles to be moved in stupid mode if current marble number is num. • int getComputerSmartMove(int num) I/ return number of marbles to be moved in smart mode if current marble number is num. boolean computerTurn( ) Il return true if it is computer's turn and false if human player's turn boolean smartMode() Il return true if it is in smart mode and false if in stupid mode
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr