Question

In: Computer Science

use c++ This question is about providing game logic for the game of craps we developed...

use c++
This question is about providing game logic for the game of craps we developed its shell in class. At the end of the game, you should ask the user if wants to play another game, if so, make it happen. Otherwise, quit

**Provide the working output of this game and the picture of the output. **

This is an implementation of the famous 'Game of Chance' called 'craps'.
It is a dice game. A player rolls 2 dice. Each die has six faces: 1, 2, 3, 4, 5, 6.
Based on the values on the dice, we play the game until a player wins or loses.
You add the values of the dice's face.
1) If the sum is 7 or 11 on the first roll, the player wins.
2) If the sum is 2, 3, or 12 on the first roll, the player loses ( or the 'house' wins)
3) If the sum is 4, 5, 6, 8, 9, or 10 on the first roll, then that sum becomes the player's 'point'.
4)To win, the player must continue rolling the dice until he/she 'make the point'.
5)If the player rolls a 7 he/she loses.

#include <cstdlib>
#include <ctime>
#include <iostream>
#include <random>

enum class Status { CONTINUE, WON, LOST};


unsigned int rollDiceAdvanced(); // same as above, but used advance c++ Random Number generation.

   // global variable to use in the advanced version of RNG (Random number Generator)
std::default_random_engine engine{ static_cast<unsigned int>(time(0)) };
std::uniform_int_distribution<unsigned int> randomInt{ 1, 6 };

int main()
{
   Status gameStatus; // can be CONTINUE, WON, or LOST
   unsigned int myPoint{ 0 };
  

   unsigned int sumOfDice = rollDiceAdvanced(); // first roll of dice.

   // bellow the game logic: Provide the game logic

   return 0;
}
// this is distribution based random number generation in c++
unsigned int rollDiceAdvanced()
{
   unsigned int firstRoll{ randomInt(engine) };
   unsigned int secondRoll{ randomInt(engine) };
   unsigned int sum{ firstRoll + secondRoll };
   std::cout << "rollDiceAdvance: " << sum << std::endl;
   return sum;
}

Solutions

Expert Solution

Solution in c++: (Along with output)

#include <iostream>
/* Writ statement to include file stream header */
#include <cstdlib>
#include <ctime>

using std::cout;
using std::cerr;
using std::cin;
using std::ios;
using std::endl;
/* Write appropriate using statement(s) */

void playCraps();
void reviewStatistics();
int rollDice();

int main()
{
int choice;

// continue game unless user chooses to quit
do {

// offer game options
cout << "Choose an option" << endl
<< "1. Play a game of craps" << endl
<< "2. Review cumulative craps statistics" << endl
<< "3. Quit program" << endl;

cin >> choice;
  
if ( choice == 1 )
playCraps();
else if ( choice == 2 )
reviewStatistics();

} while ( choice != 3 );

return 0;

} // end main

// review cumulative craps statistics
void reviewStatistics()
{
/* Write a body for reviewStatistics which displays
the total number of wins, losses and die rolls recorded
in craps.dat */

} // end function reviewStatistics

// play game
void playCraps()
{
enum Status { CONTINUE, WON, LOST };
int sum;
int myPoint;
int rollCount = 0;
Status gameStatus;

/* Write statement to create an output file stream */

// seed random number generator and roll dice
srand( time( 0 ) );
sum = rollDice();
rollCount++;

// check game conditions
switch( sum ) {
case 7:   //win with 7 on first roll
case 11:   // win with 11 on first roll
gameStatus = WON;
break;
case 2:  // lose with 2 on first roll
case 3:  // lose with 3 on first roll
case 12:  //// lose with 12 on first roll
gameStatus = LOST;
break;
default: // did not win or lose, so remember point
gameStatus = CONTINUE;  // game is not over
myPoint = sum; // remember the point
cout << "Point is " << myPoint << endl;
break; // optional at end of switch

} // end switch

// keep rolling until player matches point or loses
while ( gameStatus == CONTINUE ) //// not WON or LOST
{
sum = rollDice();
rollCount++;
  
if ( sum == myPoint ) 
gameStatus = WON;

else
if ( sum == 7 ) // lose by rolling 7 before point
gameStatus = LOST;

} // end while

// display status message and write results to file
if ( gameStatus == WON ) {
cout << "Player wins\n" << endl;
/* Write player WIN status and the total number of die
rolls to a file */

} // end if
else {
cout << "Player loses\n" << endl;
/* Write player LOSE status and the total number of die
rolls to a file */

} // end else

} // end function playCraps

// dice rolling function
int rollDice()
{
int die1;
int die2;
int workSum;

// roll two dice
die1 = 1 + rand() % 6;// first die roll
die2 = 1 + rand() % 6; //// second die roll

// total and print results
workSum = die1 + die2; // compute sum of die values
cout << "Player rolled " << die1 << " + " << die2 << " = " << workSum << endl;
  
return workSum;

} // end function rollDice

Output:


Related Solutions

2) This question is about providing game logic for the game of craps we developed its...
2) This question is about providing game logic for the game of craps we developed its shell in class. THe cpp of the class is attached to this project. At the end of the game, you should ask user if wants to play another game, if so, make it happen. Otherwise quit. Here is the attached cpp file for que2:- /*** This is an implementation of the famous 'Game of Chance' called 'craps'. It is a dice game. A player...
Write a C++ program to play the dice game "Craps". Craps is one of the most...
Write a C++ program to play the dice game "Craps". Craps is one of the most popular games of chance and is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the...
Use at least 50000 simulations to answer the following questions. In the game of craps, the...
Use at least 50000 simulations to answer the following questions. In the game of craps, the shooter rolls two dice and wins if the sum of the dice is 7 or 11 ("natural"); he loses if the sum is 2,3, or 12 (craps). If the sum is 4, 5, 6, 8, 9, or 10, then the result is not yet decided. He must roll the dice again and again, as often as is necessary until the initial sum, be it...
we are going to focus on basic logic and how you can use logic outside of...
we are going to focus on basic logic and how you can use logic outside of the classroom. Unfortunately, many of our daily interactions include logical errors. Respond to the following prompts in a minimum of 175 words: Consider a recent interaction you have had with a co-worker or item that you saw in the media that might have included logical errors. Share the example as well as the logical errors that are present in the example. Be sure to...
Use your understanding of game theory and the Prisoner's Dilemma to explain the logic of multilateral...
Use your understanding of game theory and the Prisoner's Dilemma to explain the logic of multilateral trade agreements
in C language only. Write a program called gamecards.c that has a card game logic by...
in C language only. Write a program called gamecards.c that has a card game logic by comparing the cards from 4 people and calculating which player has the best card. 1. Every card must be represented by exactly two chars representing a rank and a suit. ranks: '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'. ('T' = 10) Suits: 'H', 'D', 'S', 'C'. 7D represents the “7 of Diamond” etc.. 2. Write a function called...
Write a C program called cards.c that simulates some card game logic by comparing the cards...
Write a C program called cards.c that simulates some card game logic by comparing the cards from 4 people and determining which person has the best card. The program MUST work as follows: Eachcardmustberepresentedbyexactlytwocharsrepresenting a rank and a suit. The possible rank options are: '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'. The possiblesuit options are: 'H', 'D', 'S', 'C'. So 6H represents the “6 of hearts”, JC represents the “Jack of Clubs” etc... YouMUSTwriteafunctioncalledisValidRank(charc)which...
How can we use game theory to improve strategic decision-making? How can we use game theory...
How can we use game theory to improve strategic decision-making? How can we use game theory in the construction and/or design of a strategy?
Setup The game that we will use for this simulation is "darts." We will randomly throw...
Setup The game that we will use for this simulation is "darts." We will randomly throw a number of darts at a specially configured dartboard. The set up for our board is shown below. In the figure, you can see that we have a round ‘dart board’ mounted on a square piece of ‘wood’. The dartboard has a radius of one unit. The piece of wood is exactly two units square so that the round board fits perfectly inside the...
C# Question: OO Design Our battleships game needs several different kinds of ship – we need...
C# Question: OO Design Our battleships game needs several different kinds of ship – we need a type to store the ships and information about it. Create a base class called Ship Create child classes for each of the ship types in the game (https://en.wikipedia.org/wiki/Battleship_(game)#Description) that inherit from Ship Ships should have the following properties A private array of positions A Position is composed of an X and Y coordinate – you should create a struct to encapsulate this A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT