Question: Everything works well except for Simulation class. I cannot properly track the max-min or the scores. I need to be able to print the optimal
Everything works well except for Simulation class. I cannot properly track the max-min or the scores. I need to be able to print the optimal t1 and t2, which player has the advantage, and the average winnings of the (advantaged) player.
IN JAVA
Consider the following game between two players: Both players simultaneously declare "one" or "two". Player 1 wins if the sum of the two declared numbers is odd and Player 2 wins if the sum is even. In either case the loser is obliged to pay the winner (in tokens) the sum of the two declared numbers. So Player 1 may have to pay 2 or 4 tokens or may win 3 tokens. You can imagine a single session between two players involving many games. At the end of a session, one player may have won many tokens from the other.
Determine whether or not this is a fair game. That is, is it better to be Player 1 or Player 2 or does it matter? To do this first write a modified version of the Game class so that it also allows two computer players to play a game against each other. Do this by overloading the constructor so that when a game is instantiated one may specify whether or not it is interactive or simulated (so interactive part has to work too). Since both players are computers in a simulated game each computer player will be a different object with its own threshold (instance) variable t and and its own score (tokens won or lost so far in a session). In the interactive part, the user must choose their side (odd or even) at the beginning of the session, then they can choose to play a 1 or 2 against the computer for as many rounds as they want - until the user decides to quit the session.
Write a new test class called Simulation that allows you to run some simulations (play many games of computer versus computer) using various combinations of the threshold variable t for each player. A single simulated game need not print or return anything. Check to see how much each player loses or wins for each combination of thresholds after many games. Is it better to be the odd player? The even player? Does it matter? Better here means that if enough games are played there is a strategy (threshold) that one player can use that guarantees positive average outcome regardless of the other player's strategy. We call it a fair game if there is no such strategy for either player. By using the computer vs. computer option in your program set up some extended sessions of computer vs. computer to test different combinations of Player 1's t and Player 2's t (Hint: use a nested for loop structure to vary each player's threshold). Determine if either player has an advantage and if so which player it is and determine a threshold value t* that demonstrates the advantage.
No need to use arrays. Remember you don't need to keep track of the average winnings for every combination. Just the max-min. That is, you just need to know which strategy guarantees the maximum minimum return. What do I mean by maximum minimum return? Suppose Player 1 chooses a strategy (t=.6, for example). Player 2 will now want to choose a strategy that minimizes Player 1's average winnings over many games (ie: maximizes Player 2's average winnings). Maybe that's strategy t=.5, maybe it's t=.65, whatever it is, that's Player 2's optimal strategy given Player 1 playing with strategy t=.6 and that's the minimum return Player 1 can expect in the long run when playing with strategy t=.6 for many games. If that minimum is a positive number it means the game is not fair because it means that if Player 1 plays with strategy t=.6, no matter what Player 2 does, Player 1 will win tokens in the long run. So Player 1 wants to find a strategy (a value for t), among all possible strategies, that has a minimum return that's positive. More generally Player 1 wants to maximize their minimum return. Of course Player 2 wants to do the same. If either player can find a strategy with a positive valued max-min return, then the game is not fair.
You only have a ComputerPlayer class, Game class, the main method SimTest class (this class just makes sure that two computers can play against each other for specified amount of games) and the main method Simulation class (this class should run simulations to determine whether or not the Odd-Even game is fair and if not who has the advantage and what is a strategy that will realize that advantage).



public class ComputerPlayer private double t; private int tokenBalance; private boolean isHuman; public ComputerPlayer (double threshold) \{ t= threshold; tokenBalance =0; isHuman =(t=t ? 2:1; //if greater than t throw 2 , else 1 return move; \} public int getscore() \{ return tokenBalance; \} //track the score //if sum is odd, pl increases and p2 decreases public int update0ddScore(Game game, int sum) \{ if ( sum == game. ODD ){ if ( this ==gamegetP1()){ tokenBalance += sum; else \{ tokenBalance = sum; \} else \{ if ( this == game get2()){ tokenBalance -= sum; else \{ tokenBalance += sum; \} return tokenBalance; public int updateEvenScore (Game game, int sum) \{ if ( sum == game. EVEN ){ if ( this == game getP1()){ tokenBalance = sum; 3 else\{ token Bala ance += sum; \} \} else \{ if ( this == game getP2()){ tokenBalance += sum; \} else\{ tokenBalance = sum; \} \} return tokenBalance; \} public int updateScore(Game game, int sum) \{ if ( sum\%2 ==0){ return updateEvenScore (game, sum); \} else \{ return updateoddScore (game, sum) ; 3 \} I/resets threshold so that for-loops work in simulation lluse to reset p2 threshold public void setThreshold(double t) \{ this. t=t \} I/reset tokenBalance at end of each session public void resetscore() \{ tokenBalance =0; \} class simulationt blic static void main(String[] args) \{ double currentMax = Double.NEGATIVE_INFINITY; double currentMin = Double. POSIIIVE_INFINITY; double trMax =0; double t2Max =0; int games =10; Game sin = new Game(0,0);// start with smallest thresholds possible // test numbers for (double t1=0;t1 currentMax) \{ currentMax = totalPayoff 1 ; t1Max=t1; t2Max=t2; 1 if (totalPayoff2 > currentMax ){ currentMax = totalPayoff2; t1Kax=t1; +2Nax=t2; \} if (totalPayoff12){ System.out.print ln ("Player 1 has the advantage."); \} else if (currentinin
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
