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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education