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
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…
Othello is played as follows: Each Othello piece is white on one side and black on the other. When a piece is surrounded by its opponents on both the left and right sides, or both the top and bottom, it is said to be captured and its color is flipped. On your turn, you must capture at least one of your opponent's pieces. The game ends when either user has no more valid moves. The win is assigned to the person with the most pieces. Implement the object-oriented design for Othello.
Stick or roll is a game involving two players, A and B, and a die with four faces (numbered 1, 2, 3, 4). The faces are equally likely to occur when the die is rolled. Player A rolls the die once and sticks with that number as the score or rolls it again and scores the sum of the two numbers. • If A's score is greater than 4 then A loses. • If A's score is 4 then A wins. If A's score is less than 4, then B rolls the die once and sticks with that number as the score or rolls it again and scores the sum of the two numbers. • If B's score is greater than 4 then B loses. • If B's score is 4 or less and equal to A's or less, then B loses. • If B's score is 4 or less and greater than A's, then B wins. Player B sticks on the first roll if that number wins and rolls again if it doesn't win and it is possible to win with a second roll. Some example games might be: • A rolls a 2, chooses to roll again and rolls a 3. A's score is then 5 so A loses and B wins. * A rolls a 2 and chooses not to roll…
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
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