Pig is a simple dice game first described by John Scarne in 19451. It is a form of
jeopardy dice game, where a players decisions are between protecting current gains,
or risking current gains to make greater gains.
In Pig, each player takes a turn rolling a 6-sided dice, playing to reach a certain total
(typically 100). If a player rolls a value between 2 and 6 it is added to their score, and
they can roll again. If they roll a 1 (a “pig”), they lose their turn and add nothing to
their score. At any point after rolling a 2-6, the player may choose to to hold, which
ends their turn, and adds their turn total to their score. The winner is the first player to
get a score greater than or equal to the total.
When looking at the simple rules of the game, one can surmise that the game involves
some form of repetition to deal with the different turns of the players, and decision
statements to deal with the choice of roll or hold. The game also involves a random
number generator to simulate the dice. The game has two players, so an algorithm
may perform like this (starting with one player):
1. Ask the player whether they wish to roll or hold?
1.1. If roll is chosen, use the random number generator to generate a number
between 1 and 6.
1.1.1. If the number “rolled” is 1, go to step 2.
1.1.2. If the number “rolled” is 2-6, the value is added to the players roll total. Go
to step 1.
1.2. If hold is chosen, transfer the roll total to the players total. Go to Step 2.
2. Is one of the players total greater than or equal to the total?
2.1. Yes - the game ends.
1 Scarne, J., Scarne on Dice. Harrisburg, Pennsylvania: Military Service Publishing Co. (1945)
2.2. No - go to step 3.
3. Control is passed to the other player. Go to step 1.
Task
Design and implement a C program to play the Game of Pig. The game will be played
with two human players taking alternate turns. The total for the game (which is typically
100), should be input by the user before the game begins. The program should display
the dice rolled, for example:
Your program should include the following: decision statements, loops, character input,
random number generation.
See Program Guidelines at the end of this assignment.
Test Program Execution
An example of a program with these features is shown running below (user inputs are
bolded):
(r)oll or (h)old?
r
dice rolls a
+-------+
| O O |
| |
| O O |
+-------+
Roll total: 4
(r)oll or (h)old?
r
dice rolls a
+-------+
| O |
| |
| O |
+-------+
Roll total: 6
(r)oll or (h)old?
h
Player 1 score = 6
(r)oll or (h)old?
r
dice rolls a
+-------+
| |
| O |
| |
+-------+
Sorry, loose a turn!
Player 2 score = 0
Player 1 (score = 6)
--------------------------[Click Here](file:///C:/Users/Joseph97/Downloads/A1_f15%20(1).pdf)
hello guys, if anyone could help me out with this pig game ill appreciate it forever. im really lost and dont know how to code it completely. i also am confused with showing the dice in the way its been asked.
hope anyone can help out. thanks!