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, 23.06.2019 02:30
People with high self-esteem: accept their strengths and weaknesses. believe that failed experiences are failures of their whole self. feel good about who they are only when they reach total success. need positive external experiences to counteract negative feelings that constantly plague them.
Answers: 1
question
Computers and Technology, 23.06.2019 04:20
4. a1. vince owns a television repair shop that is insured undera commercial package policy. the policy includes thebuilding and personal property coverage form and thecauses-of-loss broad form. the declarations page indicatesthat coverage applies to both the building and the namedinsured's business property. explain whether or not thefollowing losses would be covered under his policy.a. a fire occurs on the premises, and the building isbadly damaged.b. a burglar steals some money and securities from anunlocked safe.c. a business computer is damaged by vandals whobreak into the shop after business hours.d. a tornado touches down near the store. several tel-evision sets of customers in the shop for repair aredamaged in the storm.til
Answers: 2
question
Computers and Technology, 23.06.2019 18:30
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
Answers: 2
question
Computers and Technology, 24.06.2019 03:40
4. does the kernel phenotype distribution support the idea that the cob is the result of a dihybrid cross? what information supports your answer? if a dihybrid cross (i.e. f1 to f2 of standard mendelian crosses) is not indicated what conditions might contribute to this finding.
Answers: 2
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, 01.11.2020 04:10
Questions on the website: 13722360