Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could use some help creating this craps game. // C++ program to implement a virtual craps game. // ************************************************************************** ********** #include #include #include #include crapsType.h

Could use some help creating this craps game.

// C++ program to implement a virtual craps game.

//

**************************************************************************

**********

#include

#include

#include

#include "crapsType.h"

using namespace std;

void showSummary(crapsType myGame, int w, int l, int r, string title);

//

**************************************************************************

**********

int main()

{

// ----------

// General initializations

string bars = "---------------------------";

cout << bars << endl;

cout << "CS 202 Assignment #3" << endl;

cout << "Craps Game Simulation." << endl;

cout << endl;

// ----------

// Start initial game.

// Game strategy:

// - bet 100 each bet.

// - if run out of money, quit

// - if stake is quadrupled, quit

crapsType gameA;

int wins=0, losses=0, rounds=0;

int myBet = 100, balance;

string gameAtitle = "Game Example A (w/display)";

cout << bars << endl;

cout << gameAtitle << endl << endl;

gameA.readStake();

gameA.setDisplay(true);

while(true) {

cout << bars << endl;

if (gameA.playCraps(myBet))

wins++;

else

losses++;

rounds++;

balance = gameA.getCurrentBalance();

cout << "Current Balance: $" << balance << endl;

if (balance <= myBet)

break;

if (balance >= (gameA.getStake()*4))

break;

}

showSummary(gameA, wins, losses, rounds, gameAtitle);

// ----------

// Start two more games.

// For simplicity on these games:

// - set stake directly (no need to read from user)

// - do not display each game status (i.e., set display to false)

// Game 1 Strategy:

// - set stake to 1000, and set bet 100

// if win, increase bet by 10

// if lose, set bet back to 100

// - if run out of money, quit

// - if stake is doubled, quit

crapsType game1;

int wins1=0, losses1=0, rounds1=0;

int myBet1 = 100, balance1;

bool stat;

game1.setStake(1); // note, invalid

game1.setStake(1000);

game1.setDisplay(false);

stat = game1.playCraps(5); // note, invalid

while(true) {

stat = game1.playCraps(myBet1);

if (stat)

wins1++;

else

losses1++;

if (stat)

myBet1 += 10;

else

myBet1 = 100;

rounds1++;

balance1 = game1.getCurrentBalance();

if (balance1 <= myBet1)

break;

if (balance1 >= (game1.getStake()*4))

break;

}

showSummary(game1, wins1, losses1, rounds1, "Game Example 1

(wo/display)");

// ----------

// Game 2 Strategy:

// - players choice.

// Challenge: find a winning strategy. :-)

// ----------

// Done...

return 0;

}

//

**************************************************************************

**********

// Simple function to display game summary.

void showSummary(crapsType myGame, int w, int l, int r, string title)

{

string stars =

"************************************************";

string spc = " ";

cout << endl << stars << endl;

cout << "Game Results:" << endl;

cout << spc << "Game Title: " << title << endl;

cout << spc << "Wins = " << w << endl;

cout << spc << "Losses = " << l << endl;

cout << spc << "Rounds = " << r << endl;

cout << spc << "Original Stake: $" << myGame.getStake() << ".00" <<

endl;

cout << spc << "Final Balance: $" << myGame.getCurrentBalance() <<

".00" << endl;

if (myGame.getCurrentBalance() > myGame.getStake())

cout << spc << "Winner!!" << endl;

else

cout << spc << "Loser." << endl;

cout << stars << endl << endl;

}

// **********************************************************************

// Play a simplified craps game.

#include

#include

#include

#include

using namespace std;

class crapsType

{

public:

// Constructor -> Initialize class variables.

crapsType();

// Function to read stake amount from player.

// Verifies range, re-prompts until correct input

void readStake();

// Function to set the stake amount (from argument).

void setStake(int);

// Function to return the current stake.

int getStake() const;

// Function to get the current balance.

int getCurrentBalance() const;

// Function to set the display flag.

void setDisplay(bool);

// Play a single game of craps (simplified version).

// if display is true, calls displayGame()

bool playCraps(int);

private:

void displayRoll(int, int); // Privtae function to display

roll details

// including

roll name

int originalStake; // Original stake amount

int cashOnHand; // Current cash amount

bool display; // Dislpay game details

// true to

display, false otherwise

static const int MINSTAKE = 50;

static const int MAXSTAKE = 10000;

static const int MINBET = 10;

static const int MAXBET = 1000;

};

Craps Game Simulation.

---------------------------

Game Example A (w/display)

Enter you stake: 3

Error - invalid entry, must be between 50 and 10000

Please re-enter.

Enter you stake: 100

---------------------------

die 1: 2 die 2: 5 sum: 7 Seven Out

Won

Current Balance: $200

---------------------------

die 1: 4 die 2: 2 sum: 6 Easy Six

Point: 6

die 1: 6 die 2: 2 sum: 8 Easy Eight

die 1: 5 die 2: 1 sum: 6 Easy Six

Won

Current Balance: $300

---------------------------

die 1: 4 die 2: 2 sum: 6 Easy Six

Point: 6

die 1: 3 die 2: 2 sum: 5 Fever Five

die 1: 3 die 2: 2 sum: 5 Fever Five

die 1: 6 die 2: 5 sum: 11 Yo-eleven

die 1: 1 die 2: 1 sum: 2 Snake Eyes

die 1: 5 die 2: 5 sum: 10 Hard Ten

die 1: 6 die 2: 3 sum: 9 Nina

die 1: 4 die 2: 4 sum: 8 Hard Eight

die 1: 3 die 2: 3 sum: 6 Hard Six

Won

Current Balance: $400

************************************************

Game Results:

Game Title: Game Example A (w/display)

Wins = 3

Losses = 0

Rounds = 3

Original Stake: $100.00

Final Balance: $400.00

Winner!!

************************************************

Error - invalid stake amount.

Error - invalid bet amount

************************************************

Game Results:

Game Title: Game Example 1 (wo/display)

Wins = 111

Losses = 82

Rounds = 193

Original Stake: $1000.00

Final Balance: $4050.00

Winner!!

************************************************

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 And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Compute the derivative of f(x)cos(-4/5x)

Answered: 1 week ago

Question

Discuss the process involved in selection.

Answered: 1 week ago

Question

2. Develop a program for effectively managing diversity.

Answered: 1 week ago

Question

7. What is coaching? Is there only one type of coaching? Explain.

Answered: 1 week ago