Question: NEEDED IN PYTHON *You must use functions appropriately to break down the complexity of the program. * The Pig Dice game is a simple game
NEEDED IN PYTHON
*You must use functions appropriately to break down the complexity of the program. *
The Pig Dice game is a simple game with many variant (See references in footnote). We will use the variant described below (description adapted from [2]). Each player takes turn rolling the two dice and accumulate the points shown by the dice. The first player reaching 100 wins. At each turn, the player rolls the dice repeatedly until either (s)he rolls exactly one 1 or the player decide to hold.
1. It neither dice show a 1, the sum of the dice is added to the turn total.
2. If exactly one of the two dice shows a 1, the player loses her/his turn and the total for the turn is zero.
3. If both dice show a 1, then 25 points are added to the turn total.
When the turn of player ends (by rolling one 1 or holding), the turn total is added to the players total. The first player reaching 100 wins.
One simple, but not optimal, strategy to play the game is to choose a threshold at which the player decides to hold. For example, whenever the turn total is 20 or more, the player holds. You will write a program to simulate a game of Pig between the computer and one human player. The computer will simulate the rolls of dice for both the computer player and the human player. Your program will implement the threshold strategy described above for the computer. You can either have the user set the threshold value at the start of the game or use a fixed value (18 to 20 is suggested). The human user will select her/his own strategy.
At the start of the game, the program will randomly decide who plays first (computer or human). Then computer and player will take turns according to the rules given above. After each computer turn, the program will display the total number of points earned by the computer at that turn. At the beginning of the human turn, the computer should display the current score for both computer and human. After each roll for the human, the program will display the value of the last roll, the turn total and, if the turn is not ending by rolling one 1, ask the user whether to roll again or hold. The game ends when either computer or human has won by reaching 100 points. The program must display who is the winner.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
