The game of Nim. This is a well-known game with a number of variants. Thefol lowing

Chapter 4, Problem P4.24

(choose chapter or problem)

The game of Nim. This is a well-known game with a number of variants. Thefol lowing variant has an interesting winning strategy. Two players alternately takemarbles from a pile. In each move, a player chooses how many marbles to take. Theplayer must take at least one but at most half of the marbles. Then the other playertakes a turn. The player who takes the last marble loses.You will 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 thehuman takes the first turn. Generate a random integer between 0 and 1 to decidewhether the computer plays smart or stupid. In stupid mode the computer simplytakes a random legal value (between 1 and n2) from the pile whenever it has a turn.In smart mode the computer takes off enough marbles to make the size of the pile apower of two minus 1that is, 3, 7, 15, 31, or 63. That is always a legal move, exceptwhen the size of the pile is currently one less than a power of two. In that case, thecomputer makes a random legal move.You will note that the computer cannot be beaten in smart mode when it has the firstmove, unless the pile size happens to be 15, 31, or 63. Of course, a human player whohas the first turn and knows the win ning strategy can win against the computer.

Unfortunately, we don't have that question answered yet. But you can get it answered in just 5 hours by Logging in or Becoming a subscriber.

Becoming a subscriber
Or look for another answer

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back