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 Transcribed image text
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...

  • Two player Dice game In C++ The game of ancient game of horse, not the basketball...

    Two player Dice game In C++ The game of ancient game of horse, not the basketball version, is a two player game in which the first player to reach a score of 100 wins. Players take alternating turns. On each player’s turn he/she rolls a six-sided dice. After each roll: a. If the player rolls a 3-6 then he/she can either Roll again or Hold. If the player holds then the player gets all of the points summed up during...

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

  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

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
ADVERTISEMENT