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 2 coins and Alice is the rst player to pick,
she will denitely pick 2
coins and win. If there are 3 coins and Alice is still the rst
player to pick, no matter she
picks 1 or 2 coins, Bob will get the last coin and win the
game.
Given the number of coins and the order of players (which means the
rst and the second
players to pick the coins), you are required to write a program
pickcoin.java to calculate
the winner of the game, and calculate how many different strategies
there are for he/she
to win the game. You should use recursion to solve the problem, and
the parameters are
read from the command line. You can assume that there are no more
than 35 coins.
Code:
public class CoinGame
{
public static void Count(int n, String[] s) // n: no. of
coins
//s:{"Alice","Bob"} (order)
{
if(n>0)
{
if(n==1 || n==2 || n==4) System.out.println( s[0] ); // if
1/2/4
//coins left, the one with first chance wins
else
{
Count(n-1,new String[]{s[1],s[0]});
Count(n-2,new String[]{s[1],s[0]});
Count(n-4,new String[]{s[1],s[0]});
}
}
}
public static void main(String[] args)
{
String[] order = new String[]{"Alice","Bob"};
Count(5,order);
}
}
Output:

USING RECURSIONN!!! JAVA CODE Coin game: Alice and Bob are playing a game using a bunch...
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,...
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...
Develop a game using Matlab. Work in groups of two. A Game of Sticks The rules are as follows: Players: 2 Sticks: 20 Players take turns sequentially to pick 1~3 sticks. Loser picks up the last stick! This project has the following deliverables: (1) Your project implements a 2-player version of the game of sticks in the command window. Required display in command window: ‘Welcome to the game!’ ‘Please enter player 1 name:’ ‘Please enter player 1 name:’ ‘Player 1...
python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows: 1—penny 2—nickel 3—dime 4—quarter 5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...
Alice has two coins. The probability of Heads for the first coin is 1/4, and the probability of Heads for the second is 3/4. Other than this difference, the coins are indistinguishable. Alice chooses one of the coins at random and sends it to Bob. The random selection used by Alice to pick the coin to send to Bob is such that the first coin has a probability p of being selected. Assume that 0<p<1. Bob tries to guess which...
Problem 1. (20 points) Consider a game with two players, Alice and Bob. Alice can choose A or B. The game ends if she chooses A while it continues to Bob if she chooses B. Bob then can choose C or D. If he chooses C the game ends, and if he chooses D the game continues to Alice. Finally, Alice can choose E or F and the game ends after each of these choices. a. Present this game as...
Problem 1. Alice and Bob sell used CDs at music festivals. Each is deciding whether or not to set up their booth at the last festival of the summer. The festival is scheduled to take place in Alton, very near where Alice lives. It will cost her only $30 to travel the festival. Bob is farther away, and it will cost her $100 to travel to Alton. Both Alice and Bob would prefer to be only CD sellers at the...
In need of some help with a LCR C++ game. The code will run, but I need it to cycle through the turns automatically so that the only input from the user is the number of players. It's also showing the winner as the person with 0 chips which is incorrect and I can't figure out why. Any help is greatly appreciated as this is already late. Game rules: Develop a program that follows the rules of Left Center Right...
Problem 2.(20 points) Consider the following game: In the first step, Alice has two $10 bills and can take one of the following two actions: (i) she can give S20 to Bob or (ii) she can give one of the S10 bills to Bob. All the money will be used to buy popcorns before the movie they will see. Each one dollar of popcorn gives one unit of payoff for the player who buys it. In the second step, they...
Problem 2.(20 points) Consider the following game: In the first step, Alice has two $10 bills and can take one of the following two actions: (i) she can give S20 to Bob or (ii) she can give one of the S10 bills to Bob. All the money will be used to buy popcorns before the movie they will see. Each one dollar of popcorn gives one unit of payoff for the player who buys it. In the second step, they...