Question: For the program we will create a two player game of pig. The game of Pig is a very simple dice game in which two

For the program we will create a two player game of pig. The game of Pig is a very simple dice game in which 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

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.

In this lab you will play an entire game with two simulated players. The game begins by asking the user to enter the "roll until" value for each player (the players may have different values). Then the program will play an entire game using the two simulated players. The game ends when one of the player's total score is 100 or greater, and prints a message stating which player won.

One way to have two players play the game would be to copy and paste the code for one player's turn to create a second player's turn. But this means that you will be repeating code, a very bad design practice. Instead, you will write two functions for this program: one that gets the strategy for a player (their "roll until" value), and one that simulates a player's turn. Inside the whole game loop, you can call these functions for each of the players. A real player would end their turn as soon as their game total was 100 or greater. Our computer player will continue its final turn until it reaches its specified turn total, or until it rolls a one

Here is some code that i need to use:

#include #include #include #include using namespace std; int playerRoll(int strat, string name); int getStrat(string name); //////////////////////////////// // Note: It is best to not work on this program in the order that things are // written in this file. Start by writing pseudocode, then write the function // prototypes, followed by the functions, and finally write the main function. //////////////////////////////// //////////////////////////////// // Put the function prototypes here // You will write three functions: One to get the player's strategy from user // input, another to simulate a turn of the game, and a third to print the // game results. // End of function prototypes. Move on to write the block of code in the // main function //////////////////////////////// int main() { int total_player1 = 0; // Player 1 score tracker int total_player2 = 0; // Player 2 score tracker int player1_strat; // Player 1's strategy for each turn int player2_strat; // Player 2's strategy for each turn // seed the random number generator. // Notice that we seed the random number generator in the main function // (not in the player roll function), and we make sure not to put the // random number generator inside a loop. This is because we only want // to seed the random number generator ONCE per program run. srand(static_cast (time(NULL))); //////////////////////////////// // Write code from here until the end comment. Use the comments as guidelines. // Get the strategy for each player (use a function). // You should write a single function and call it twice (once for // each player). // Use a loop to have the two players continue to take turns until one of // has a total game score of 100 or greater. If the first player wins, make // sure that you don't allow the second player to take a turn (quit the loop // as soon as one player reaches 100 or greater). // // Use a function for the player's turn. You should write a single function // and call it two times (once for each player's turn). // End of your code block in the main function. // Move on to write the three functions below the main function. //////////////////////////////// // Print the results // NOTE - you need to write the printResults function if(total_player > total_player2) { printResults("Player 1", total_player, "Player 2", total_player2); } else if(total_player2 > total_player) { printResults("Player 2", total_player2, "Player 1", total_player); } else { // This should never happen because we quit the loop if Player 1 // wins and don't allow Player 2 to play their last turn. // But we'll put this in just for completeness. cout

I have marked each place where you need to add code with a long line of slashes (//////////////). Use incremental development steps like I described for the example program. I have already told you that you need three functions: one to get the strategy for a player, one to simulate a player's turn, and one to print the formatted game results. Your game should play like the game in the following figures.

Start of the game:

For the program we will create a two player game of pig.

End of the game:

The game of Pig is a very simple dice game in which

Enter Player1's play until strategy: 15 Enter Player2's play until strategy: 25 Player 1's rolls for this turn are: 2 Player 1 rolled a 1. it's turn is over Player 1 has completed its turn Player 1 received points for the turn current score for Player 1 is: e0 Player 2's rolls for this turn are 44 3 6 6 6 Player 2 has completed Player 2 received 29 points for the tur current score for Player 2 is: 29 its turn Player 1's rolls for this turn are: 2 3 33 6 Player 1 has completed its turn Player 1 received 1? points for the turn urrent score for Player is 17 Player 2' s rolls for this turn are: 4 3 2 5 Player 2 rolled a 1, it's turn is over Player 2 has completed its turn layer 2 received points for the turn. urrent score for Player 2 is 29 Player 1's rolls for this turn are 2 2 6 4 4 Player 1 has completed its turn layer 1 received 18 points for the turn. urrent score for Player1 is 35 layer 2' s rolls for this turn are: Player 2 rolled a 1 it's turn is over Player 2 has completed its turn Playe 2 received points for te tun urrent score for Player 2 is: 29 layer 1's rolls for this turn are: 4 6 6 Player 1 has completed its turn layer 1 received 16 points for the turn urrent score for Playe is 51 Player 2's rolls for this turn are: 6 6 4 5 4 5 Player 2 has completed its turn. Player 2 received 30 points for the tur urrent score for Player 2 is: 59 Player 1's rolls for this turn are 2 Player 1 rolled a 1, it's turn is over Player 1 has completed its turn layer 1 received points for the turn. urrent score for Player is: 51 Player 2's rolls for this turn are 6 44 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!