Absolute C++
Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 3, Problem 11PP

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 2-6 then he or she can either

— ROLL AGAIN or

— HOLD. At this point the sum of all rolls made this turn is added to the player’s total score and it becomes the other player’s turn.

  • If the player rolls a 1 then the player loses his or her turn. The player gets no new points and it becomes the opponent’s turn.

If a player reaches 100 or more points after holding then the player wins.

Write a program that plays the game of Pig, where one player is a human and the other is the computer. Allow the human to input "r" to roll again or "h" to hold. The computer program should play according to the following rule: keep rolling on the computer’s turn until it has accumulated 20 or more points, then hold. Of course, if the computer wins or rolls a I then the turn ends immediately. Allow the human to roll first.

int humanTurn (int humanTota1Score) ;

int computerTurn ( int computerTota1Score) ;

These functions should perform the necessary logic to handle a single turn for either the computer or the human. The input parameter is the total score for the human or computer. The functions should return the turn total to be added to the total score upon completion of the turn. For example, if the human rolls a 3 and 6 and then holds, then humanTurn should return 9. However, if the human rolls a 3 and 6 and then a 1, then the function should return 0.

Blurred answer
Students have asked these similar questions
Craps is a single player dice game, that proceeds as follows:1. the player rolls 2 six-sided dice once    if the total is 7 or 11, the player wins     if the total is 2, 3 or 12, the player loses    otherwise, the game continues, ... see 2 ... 2. the player the continues to roll the dice repeatedly, until ...    the total is the same as the original total (from 1), in which case the           player wins the total is 7, in which case the player loses Write a function craps using Python that simulates a single game of craps (may be many rolls) and returns 1 if the player wins and 0 otherwise.   Sample results examples: >> import random>>> random.seed(0)>>> craps()0 >>> random.seed(1)>>> craps()1 >>> random.seed(2)>>> craps()0 >>> [ (i,random.seed(i),craps()) for i in range(20)][(0, None, 0), (1, None, 1), (2, None, 0), (3, None, 1), (4, None, 0), (5, None,1), (6, None, 0), (7, None, 1), (8, None, 0), (9, None, 0), (10,…
Nim is a two-player game played with several piles of stones. You can use as many piles and as many stones in each pile as you want, but in order to better understand the game, we'll start off with just a few small piles of stones (see figure 1 below). Pile 1 Pile 1 Pile 2 The two players take turns removing stones from the game. On each turn, the player removing stones can only take stones from one pile, but they can remove as many stones from that pile as they want (please note, a player must remove atleast 1 stone from a pile during his/her turn). If they want, they can even remove the entire pile from the game! The winner is the player who removes the final stone (avoid taking the last stone - see figure 2 below). Pile 2 Pile 3 Pile 3 Let's say its Max (player 1) turn to play. Then Max can win by simply removing a stone from Pile 2 or Pile 3 Draw a game tree (upto depth level 2) for the given version of the Nim game. Please consider figure 1 as your initial game configuration/state…
Java problem First-Player Advantage 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. Problem:  There is an advantage to going first in Pig, but how big an advantage is it for “hold at 20 or goal” play?  We wish to estimate the probability of a first-player win with a hold-at-20-or-goal play policy.  Simulate a given number of two-player Pig games where a player rolls until a 1 ("pig") is rolled, or the turn total is greater than or equal to 20, or the…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges; Author: FreecodeCamp.org;https://www.youtube.com/watch?v=oBt53YbR9Kk;License: Standard YouTube License, CC-BY