Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to write the code for a rolling game, I have finished the first part. When I try to write anything when it
I am trying to write the code for a rolling game, I have finished the first part. When I try to write anything when it asks " would you like to 'roll' or 'hold'?" it just repeats the question. Could someone help with this please. I will make sure to give a good feedback and an upvote.
Project 1: Pig Program DUE: Friday, March 5 (by 5:00 pm) Pig is a dice game with the following rules: 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, the player is faced with two decisions: roll - If the player rolls a o 1: the player scores nothing and it becomes the opponent's turn. 02-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. The first player to score 100 or more points wins. For example, the first player, Ann, begins a turn with a roll of 5. Ann could hold and score 5 points, but chooses to roll again. Ann rolls a 2, and could hold with a turn total of 7 points, but chooses to roll again. Ann rolls a 1, and must end her turn without scoring. The next player, Bob, rolls the sequence 4-5-3-5-5, after which he chooses to hold, and adds his turn total of 22 points to his score. Your job is to write a C++ program in which the computer will play the user in a game of Pig. A key decision to build strategy for the computer player is how large a turn total should be risked to possibly get an even larger total. Use "hold at 20" strategy for your computer player (unless holding will win the game). (This will maximize the expected number of points per turn, though it does not maximize the expected probability of winning.) Below are bullet points describing specific behaviors your program should have. . Before every round, the program must output the following where xx is the user's score and Wy is the computer's score: New round: User: XX Computer: yy The user goes first. Before the user makes a decision, the program should tell them their current accumulated points and asks them what they would like to do using this exact prompt: You have zz points this round. Would you like to 'roll' or 'hold' ? The user should then input their request. If it is neither "roll" or "hold" they get the following message (where bad_command is whatever the user entered) and are reminded of their points and asked to make their decision again: I did not understand "bad_command", sorry. If the user decided to roll, they should be told their roll with the following message, and be prompted to decide what to do again: You rolled a n. If the user's roll ends their turn, they should be told the following: Sorry, your turn is over, and you gain points. If the user holds, they should be told how many points they held this turn and their new total (notice there is no period at the end of this line!): You held xx points, bringing you to yy Once it is the computer's turn, it pursues its "hold at 20" strategy. Every time it rolls, output that roll like so: The Computer rolled a n. If the computer rolls a 1, output the following message and end its turn: The Computer turn is over, and they gain points. If the computer manages to hold, output how many points they held this turn and their new total and end its turn: The Computer held xx points, bringing you to yy . At the end of the game output one of the following two lines: The Computer wins! or You win! The random dice rolls are supplied by a file 'rolls.txt". I provide a different set of rolls for each test I give it. Leave the first eight (8) lines of the main function alone. These load the dice rolls. You can access the next dice roll, and store it in an integer result, with the following excerpt of code: result = roll(); You must never re-roll the dice! That is to say, every time roll() is evaluated in your code, you must use that value as a dice roll! One hint you are re-rolling is if the Autograder is telling you that the dice rolls are not correct. EXPLORER C main.cpp X L SW > OPEN EDITORS V PROGRAMMING1-PROJECT1 > .vscode G helper.cpp Emain main.cpp M Makefile Project1.pdf Erolls.txt B G+ main.cpp > main(int, char * []) 1 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started