subject

The game of Nim This is a well-known game with a number of variants. The following variant has an interesting winning strategy. 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. Then the other player takes a turn. The player who takes the last marble loses Write a program in which the computer plays against a human opponent. Generate a random integer between 10 and 100 to denote the initial size of the pile. Generate a random integer between 0 and 1 to decide whether the computer or the human takes the first turn. Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid. In the stupid mode, the computer simply takes a random legal value (between 1 and n / 2) from the pile whenever it has a turn. In the 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 when the size of the pile is currently one less than a power of two. In that case, the computer makes a random legal move You will note that the computer cannot be beaten in the smart mode when it has the first move unless the pile size happens to be 15, 31, or 63. Of course, a human player who has the first turn and knows the winning strategy can win against the computer. Below is an example of a game run: Current number of marbles in pile: 95 Computer removes 12 marble(s) Current number of marbles in pile: 83 How many marbles do you want to remove: 12 Current number of marbles in pile: 71 Computer removes 17 marble(s) Current number of marbles in pile: 54 How many marbles do you want to remove: 20 Current number of marbles in pile: 34 Computer removes 6 marble(s) Current number of marbles in pile: 28 How many marbles do you want to remove: 28 How many marbles do you want to remove 25 How many marbles do you want to remove: 20 How many marbles do you want to remove: 12 Current number of mar Computer removes 4 marble(s) Current number of marbles in pile: 12 How many marbles do you want to remove: bles in pile: 16

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 22:50
Which of these might be an example of an advertiser's target group? a.people who have no access to media b.people the advertisers know nothing about c. people who watch a variety of tv shows d. people who live in the same region of the country
Answers: 2
question
Computers and Technology, 25.06.2019 00:00
When pasting an existing chart into a word document, you can choose to using the paste options button. a. paste the chart as a picture b. embed the chart c. add the chart while keeping the destination formatting intact d. insert the chart while keeping the source formatting intact
Answers: 1
question
Computers and Technology, 25.06.2019 10:20
(programming exercise 3-10). a retail company must file a monthly sales tax report listing the total sales for the month, and the amount of state and county sales tax collected. the state sales tax rate is 4 percent and the county sales tax rate is 2 percent. design a modular program that asks the user to enter the total sales for the month. from this figure, the application should calculate and display the following: - the amount of county sales tax - the amount of states sales tax - the total sales tax (county plus state) some of the code has already been provided below. complete the missing code below. // global constants for tax calculations constant real county_tax_rate = .02 constant real state_tax_rate = .04 // main module module main() // local variables declare real monthsales, countytax, statetax // get month sales display β€œenter monthly sales: ” input monthsales // write the statement to calculate county tax // write the statement to calculate state tax // display tax amount call showtaxes(monthsales, countytax, statetax) end module // the showtaxes module accepts monthsales, countytax, statetax // as arguments and displays the resulting data // write the showtaxes module
Answers: 2
question
Computers and Technology, 26.06.2019 07:00
Technology is often discovered by accident
Answers: 1
You know the right answer?
The game of Nim This is a well-known game with a number of variants. The following variant has an in...
Questions
question
Mathematics, 30.09.2021 17:40
question
Mathematics, 30.09.2021 17:40
Questions on the website: 13722362