Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ on Visual studio code 1 #include #include 11 4 using namespace std; Nm ON. 5 void init_rolls(string); int roll(); 8 9 10 11

Using C++ on Visual studio code

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

1 #include #include 11 4 using namespace std; Nm ON. 5 void init_rolls(string); int roll(); 8 9 10 11 12 13 int main(int argc, char *argv[]) { if (argc == 1) { init_rolls("rolls.txt"); } else { init_rolls(string(argv[1])): } 14 15 16 17 18 19 20 [/TODO: Your code here. 1: powershell PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. // TODO: Your code here. 21 return 0; 22 23 24 } PROBLEMS OUTPUT DEBUG CONSOLE TERMINAL 1: powe Windows PowerShell Coob Microcof 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 i 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. o 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 yy is the computer's score: New round: User: XX Computer: yy The user goes first. 6:1 3/4 (hp) ort se delete home of 3 + O A IV y velo 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 0 points. 6:19 PM 3/4/2021 + ins prt sc delete home end of 3 a - + ( DAV v 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 0 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: 6:19 PM 3/4/2021 ins prt sc delete home end 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. 619 3/4/2 hp no ins prt sc delete home end 8 9 9 backspace num lock o 7 home

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

Differentiate between hard and soft measures of service quality.

Answered: 1 week ago

Question

Be familiar with the different perspectives of service quality.

Answered: 1 week ago

Question

Describe key customer feedback collection tools.

Answered: 1 week ago