A subtraction game Subtraction games are two-player games in which there is a pile of objects, say coins. There are two players, Alice and Bob, who alternate turns subtracting 4.9. A SUBTRACTION GAME 19 from the pile some number of coins belonging to a set S (the subtraction set). Alice goes first. The first player who is unable to make a legal move loses. For example, suppose the initial pile contains 5 coins, and each player can, on his turn, remove any number of coins belonging to the set S = {1, 2, 3}. Who wins? Alice goes first. On her turn she removes 1, 2, or 3 coins from the pile. If she removes 3, then the game reduces to a 2-coin game with Bob going first. Bob wins on his next move. Similarly, if she removes 2, then the game reduces to a 3-coin game with Bob going first, and Bob wins on his next move. But, if she removes 1, then the game reduces to a 4-coin game with Bob going first, and no matter what move Bob makes, Alice wins on her next move. In any subtraction game, the winner can be determined if we know how many coins are in the pile, and which player is next to play. Suppose there are n coins in the pile. If the player next to play take some coins and leave a position from which the opponent (who becomes the player next to play) has no winning strategy, then he can win. If he can not do this, then every legal move leaves a position from which the opponent has a winning strategy, and so the player whose turn it is cannot win.
Consider the following variation of the subtraction game. Each player can (only) remove 1 or 2 coins from the pile on their turn and, now, the last player to move loses (i.e., the player who takes the last coin loses). Suppose Alice and Bob play this game starting from a pile of 15 coins, and Alice makes the first move. Who wins?
A subtraction game Subtraction games are two-player games in which there is a pile of objects,...
Design an O(n)-time non-losing strategy for the first player, Alice, in the coins in-a-line game. Your strategy does not have to be optimal, but it should be guaranteed to end in a tie or better for Alice. Coins in a Line 12.4.1 The first game we consider is reported to arise in a problem that is sometimes asked during job interviews at major software and Internet companics (probably because it is so tempting to apply a greedy strategy to this...
Developing an optimal strategy for a variant of the game Nim Nim is a subtraction game that is played with sticks. The subtraction game variant is simple. A pile of sticks is placed in front of a pair of participants. The players take turns removing either 1, 2, 3, or 4 sticks from the pile. The player who removes that last stick from the pile loses the game. It turns out that there is an optimal strategy for playing this...
1. NIM game. This is a different version or easier version of NIM game Consider a pile of 5 matchsticks. Two people take turns removing 1 or 2 sticks each time from this pile. Suppose both players play smartly (nobody plays a fool move trying to let the opponent wins. But there is only one winner anyway) a)If the person getting the last stick wins, will the first player win? Why? Show the steps the first and second player will...
Answer the following Nim game style questions. (Robert's Game) In this game, two players take turns removing stones from a pile that begins with n stones. The player who takes the last stone wins. A player removes either one stone or p stones, where p is a prime dividing the number of stones in the pile at the start of the turn For which n does the First Player have a winning strategy? A winning strategy for the First Player...
USING RECURSIONN!!! JAVA CODE Coin game: Alice and Bob are playing a game using a bunch of coins. The players pick several coins out of the bunch in turn. Each time a player is allowed to pick 1, 2 or 4 coins, and the player that gets the last coin is the winner. Assume that both players are very smart and he/she will try his/her best to work out a strategy to win the game. For example, if there are...
Problem 2: Tails and (Heads or Tails?) Alice and Bob play a coin-tossing game. A fair coin (that is a coin with equal probability of 1. The coin lands 'tails-tails' (that is, a tails is immediately followed by a tails) for the first 2. The coin lands 'tails-heads (that is, a tails is immediately followed by a heads) for the landing heads and tails) is tossed repeatedly until one of the following happens time. In this case Alice wins. first...
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 C program in which the computer plays against...
Gambler’s Ruin. A gambler, player A, plays a sequence of games against an opponent, player B. In each game, the probability of player A winning is p. If player A wins, he wins $1 which is paid by player B. If he loses a hand with probability q = 1-p, he must pay $1 to player B. The game ends either player B wins all the money from player A, and he is “ruined,” or when player A wins all...
Need Help with homework problem writing the game of nim in Python IDLE. Its 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. Instructions...