Part 1 of this assignment is to be completed in teams of two. You will work with a partner to design and implement a Java class for simulating the game of Pig. In part 2, you will work on your own to simulate a variant of the game.
You are to design and implement a class for simulating the game of Pig. Pig is a 2-player dice game in which the players take turns rolling a die. On a given turn, a player rolls until either (1) he/she rolls a 1, in which case his/her turn is over and no points are awarded, or (2) he/she chooses to hold, in which case the sum of the rolls from that player's turn are added to his/her score. The winner of the game is the first player to reach 100 points.
Your PigGame
class should have the following methods:
playTurn
: simulates a single player's turn, rolling the dice until a specific cutoff point total is reached.
For example, if the method is called with a cutoff of 20, it should repeatedly roll the die until
a 1 is rolled or until the sum of the rolls on that turn reach 20. The player's score
should be updated appropriately.
playGame
: simulates the player playing a complete game, starting with 0 points and
calling the playTurn
method repeatedly until 100 points are reached. The method should
have a parameter specifying the cutoff for each turn, and should
return the number of turns it took to complete the game.
averageGameLength
: simulates a specified number of games and calculates the average
number of turns required to play a game. The method should have parameters for the number of games
and the turn cutoff, and should returned the average number of turns.
Once you have completed and tested your class, perform repeated simulations to determine the optimal cutoff point total, i.e., the cutoff amount that minimizes the number of turns needed to complete a game. Provide a justification of your answer, including data obtained from your simulations.
Implement a variant of the Pig game named DoublePigGame
. In this variant, each
player rolls two dice. If the roll is snake-eyes (double 1's), the player's turn is over and no
points are awarded. Every other doubles roll is ignored - the player's turn continues but the roll is
not added to the sum. Non-doubles result in the two dice values being added to the turn total.
As in part 1, you will want a playTurn
method that simulates a single turn, a
playGame
method that simulates an entire game, and an averageGameLength
method that calculates the average number of turns required to play a game.
Once you have completed and tested your class, perform repeated simulations to determine the optimal cutoff point total, i.e., the cutoff amount that minimizes the number of turns needed to complete a game. Provide a justification of your answer, including data obtained from your simulations.