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
0 0
Add a comment Improve this question
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
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...

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

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

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

  • #2 New Turn Rules A frustrating aspect of programming on a project with other programmers is the ...

    #2 New Turn Rules A frustrating aspect of programming on a project with other programmers is the fact that everyone solves problems in different ways. Just when you think you know which way things are headed, someone throws a snag in your design. Objects needed: Die Attributes Current value of the die Actions roll the die DiceSet Attributes An array of six Die The number of dice available to roll. When this number reaches 0, it is reset to 6....

  • Hello, Could you please help me code this program in Java? It is important that all...

    Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT