Question

# The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...

The Rules of Pig
Pig is a folk jeopardy dice game with simple rules: Two players race to
reach 100 points. Each turn, a player repeatedly rolls a die until either a 1
(”pig”) is rolled or the player holds and scores the sum of the rolls (i.e. the
turn total). At any time during a player’s turn, the player is faced with two
decisions:
roll If the player rolls a
1: the player scores nothing and it becomes the opponent’s turn.
2 - 6: the number is added to the player’s turn total and the player’s
turn continues.
hold The turn total is added to the player’s score and it becomes the opponent's turn
1 One Automated Turn of Pig
Our first exercise is to simulate a single turn of Pig where a player rolls until
a 1 (“pig”) is rolled, or the turn total is greater than or equal to 20. We will
call this strategy Hold-at-20. The user doesn’t need to make any choices,
the computer will roll automagically, following the hold-at-20 strategy.
• For each roll, print a line with “Roll:” and the random die roll value
(1-6).
• After a “pig” roll of 1, or a “hold,” print a line with “Turn total:”
followed by the turn total. In the case of a “pig,” this turn total is 0.
1.1 Sample Outputs
The different runs of the program are separated by dots.
1.1 Sample Outputs
The different runs of the program are separated by dots
Roll: 4
Roll: 5
Roll: 6
Roll: 5
Turn total: 20
...
Roll: 3
Roll: 1
Turn total: 0
...
Roll: 5
Roll: 2
Roll: 3
Roll: 6
Roll: 5
Turn total: 21

Python

Code

import random

totalValue=0
while True:
diceValue=random.randint(1,6)
print("Roll: ",diceValue)
totalValue+=diceValue
if(diceValue==1):
print("Turn total: 0")
break
if(totalValue>=20):
print("Turn total: ",totalValue)
break

output

code snaps

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

#### Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
• ### The game of Pig is a simple two-player dice game in which the first player to...

The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die: If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn. If the player rolls 2 through 6, then he or she can either ROLL AGAIN or HOLD:      At this point, the sum of all rolls...

• ### For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two p...

For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn,...

• ### java thank you! Pig is a traditional dice jeopardy game. Players take turns, starting with a...

java thank you! Pig is a traditional dice jeopardy game. Players take turns, starting with a randomly-chosen player. On their turn a player rolls a single 6-sided die 1 or more times. After each roll, the player has a choice: hold Stop rolling and add the total of al numbers rolled this turn to their score, or roll Roll the die again. If the player rolls a 1, their turn ends and they score 0 for the turn. Points scored...

• ### // This program creates a simulated player who takes one turn in the // Pig dice...

// This program creates a simulated player who takes one turn in the // Pig dice game. The simulated player keeps rolling the die until // the total for the turn is 20 or greater, or until a 1 is rolled. // If a 1 is rolled, the player's score for the turn is 0. Otherwise // the player's score is the sum of the rolls for the turn. // ///////////////////////////////////////////////////////////////////// #include<iostream> #include<cstdlib> #include<time.h> using namespace std; int randNumGen(int upper,...

• ### The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values...

The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values together. 2. Choose whether to roll the dice again or pass the dice to your opponent. 3. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your...

• ### Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of...

Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of scoring outcomes of a single turn in a game called Pig. Your Task For this assignment you will simulate a given number of hold?at?N turns of a game called Pig, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single turn of this game. The value of N will be acquired via user...

• ### please write the following program in Java PIG is one of a family of games called...

please write the following program in Java PIG is one of a family of games called jeopardy dice games, since a player's main decision after each roll is whether to jeopardize previous gains by trying for potentially even greater gains. In PIG, all players start with ZERO points, and each turn involves rolling a die to earn points. The first player to earn 100 points or more total shouts "PIG!" and wins the game. On their turn, a player does...

• ### python code( using functions please)! Rules of the game: - This game requires a dice. The...

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 =...

• ### Please i need helpe with this JAVA code. Write a Java program simulates the dice game...

Please i need helpe with this JAVA code. Write a Java program simulates the dice game called GAMECrap. For this project, assume that the game is being played between two players, and that the rules are as follows: Problem Statement One of the players goes first. That player announces the size of the bet, and rolls the dice. If the player rolls a 7 or 11, it is called a natural. The player who rolled the dice wins. 2, 3...

• ### I need some help creating C++ Left, Center, Right (LCR) dice game Pseudocode. Address the following : A. Analyze the giv...

I need some help creating C++ Left, Center, Right (LCR) dice game Pseudocode. Address the following : A. Analyze the given problem statement. B. Break the problem down into distinct steps of pseudocode that will solve the problem. C. Create variables to track the various elements in the pseudocode. D. If applicable, determine any breakdown of pseudocode into functions and/or classes. E. Use natural language to work through the problems. Using three special dice and player pieces called chips. In...