Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Please, thanks in advance! This assignment asks you to implement a dice game that I made up. A human (you or me) will

In C++ Please, thanks in advance!

This assignment asks you to implement a dice game that I made up. A human (you or me) will be playing against the computer. Each starts with 0 points, and the game ends when either one or both of the players obtain a score of 150 or greater.

In each round, a player rolls three dice. The human goes first followed by the computer.

In the game, getting a 1 is not a good thing. When a player rolls the dice, four outcomes are possible: Getting three 1's causes the player to lose all accumulated points and lose his/her turn. The other player will then roll. At that time the following message should be printed: Three ones, lose all holdings, and lose turn 2. Getting two 1's causes the player to lose half of all accumulated points and lose his/her turn. At that time the following message should be printed: Two ones, lose half of holdings, and lose turn The other player will then roll. Use integer division, e.g. half of 35 is 17 and half of 50 is 25. 3. Getting a single 1 causes a player to lose a turn. When a player loses a turn there is no change in the amount of accumulated points. At that time the following message should be printed: Single one, lose turn 4. When there are no 1's the human is asked whether to bank the sum of the dice that is showing.

If the player decides to bank the points, the sum that is showing is added to the player's accumulated points and the dice are passed to the other player.

If the player decides not to bank, and tries to obtain a higher sum, the dice are rolled again. And, the numbers showing on the die are evaluated once again according to the above four possible outcomes.

When the player decides to bank, the sum showing is added to the accumulated points, and the dice are passed to the other player.

The following shows the first few rounds of a game. Duplicate all prompts and the format of output. User input is shown bold. $ notAOne Human's turn Rolled 5, 5, 6 sum = 16 Bank(y/n)? y Computer's turn Rolled 5, 5, 4 sum = 14 bank After round 1 human has 16 and computer has 14

Human's turn Rolled 2, 1, 3 Single one, lose turn Computer's turn Rolled 1, 5, 6 Single one, lose turn After round 2 human has 16 and computer has 14

Human's turn Rolled 5, 5, 1 sum = 11 Bank(y/n)? y Computer's turn Rolled 3, 1, 4 Single one, lose turn After round 3 human has 27 and computer has 14

Human's turn Rolled 5, 3, 4 sum = 12 Bank(y/n)? y Computer's turn Rolled 2, 4, 4 sum = 10 bank After round 4 human has 39 and computer has 24

Human's turn Rolled 6, 3, 2 sum = 11 Bank(y/n)? M Bank(y/n)? Y Bank(y/n)? y Computer's turn Rolled 3, 2, 1 sum = 6 no bank Rolled 5, 4, 3 sum = 12 bank After round 5 human has 50 and computer has 36

The question to bank or not, only accepts a lower case y or n. Any other input should result in a re-prompt. If you think about it, the re-prompting requires a loop. Above the values of M and Y were rejected.

Hint: You can use either a string or char variable to capture the user's response to bank.

And the following shows the last round of a game: Human's turn Rolled 2, 5, 5 sum = 12 Bank(y/n)? y Computer's turn Rolled 6, 2, 4 sum = 12 bank After round 15 human has 155 and computer has 130

Human won

Two blank lines should be printed before the very last line. The last line should either be: Human won Computer won Tie

During the same round, it is possible that both the human and computer scores exceed 150. The one with the higher score is the winner. You only can have a tie if both scores are above 150 are equal.

Programming considerations: This program assignment involves random numbers, if-statements and loops.

The format of all prompts and output messages should be duplicated.

A round is defined as the human playing and then the computer playing.

At the beginning of a round what the human has rolled is shown, like: Human's turn Rolled 2, 5, 5

If there are no 1's the next line would show the sum of the three dice, like: sum = 12 Bank(y/n)?

At that point the program is waiting for y or n to be input followed by Enter. If a value other than y or n is entered, the program reissues a prompt. This is shown at the beginning of round 5 above.

After the human answers with y to Bank? The program should print "Computer's turn", followed by what the computer rolled as shown here: Computer's turn Rolled 3, 2, 1 sum = 6 no bank Rolled 5, 4, 3 sum = 12 bank After round 5 human has 50 and computer has 36

The program must have some intelligence whether to "bank" the sum that was rolled. If the computer rejects a sum, "no bank" should be printed after the sum. This intelligence could be: a. as simple as simple always accepting. b. only accepting if the sum is above a certain value. c. altering the sum that is acceptable (possibly holding out for a higher sum) based upon whether the computer or human is leading, and the gap between them could be factor. Programming for c will be worth more than b, and programming for b will be worth more than a.

At the end of a round (human followed by computer) a line like the following should be printed: After round 5 human has 50 and computer has 36

A single blank line should follow the reporting of the score, as shown here: After round 3 human has 27 and computer has 14

Human's turn Rolled 5, 3, 4 sum = 12 Bank(y/n)? y Computer's turn Rolled 2, 4, 4 sum = 10 bank After round 4 human has 39 and computer has 24

Hint: It might be advisable to first develop a solution for just the human player. After that part is working, with come copying and pasting and giving the computer some variable names that are similar to those used with the human's code, you could add the functionality for your opponent.

Since we started talking about functions, you might want to have some short functions to do things like roll a die, count the number of ones rolled, etc.

Do not have any variables declared above main() or outside of any function. They are global (aka external) variables. Globals should be avoided.

Also attached are two complete games.

Once again the format all prompts and messages must be reproduced.

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Relational Contexts in Organizations

Answered: 1 week ago