Question: Don't worry about the pics i have all the classes with the code at the bottom!!!!! Introduction Bunco is a well-known dice game that originated
Don't worry about the pics i have all the classes with the code at the bottom!!!!!
Introduction
Bunco is a well-known dice game that originated in England in the 19th century and eventually arrived in San Francisco during the Gold Rush. It was popular during the Prohibition era in the United States and continues to be played today. If you are unfamiliar with Bunco, please review the rules of the game (Links to an external site.) and you can also play for fun (Links to an external site.) to get some practice with the game.
Our game will focus on two players, the Computer and a Human Player. There will be a total of six rounds, 1-6. Using just a single Die, each player will roll, with the human player starting first. The first player to roll the round value will wind winning that round. If both players roll the round value at the same time, play in that round will continue until one of the players finally rolls the round value again all by themselves. After all six rounds are played, the winner of the game will be the player who won the most rounds.
As the above description points out, I have made a number of simplifications to our Bunco game from the one you can play online. First, we will use only 1 die for each player, not three. Second, round play does not continue to 21 (because that takes way too long...) so the first player to roll the round number wins that round, unless both players do at the same time.
Your task
Your assignment is to complete this C++ program skeleton (XCode (Links to an external site.) VS2012 (Links to an external site.)) to produce a program that implements the described behavior. (We've indicated where you have work to do by comments containing the text TODO. Please remove those comments as you finish each thing you have to do.) The program skeleton you are to flesh out defines five classes that represent the five kinds of objects this program works with: Die, Player, Board, BoardRow and Bunco. You will need to complete code for the Board, Player and Bunco classes. Details of the interface to all of these classes are in the program skeleton, but here are the essential responsibilities of each class:
In order to simulate a real game, a Die class has been provided to you. The Die supports any number of sides but for the Bunco game we will be dealing with a six sided die. The major method of this class is .roll( ). It randomly picks one of the values between 1 and 6 inclusively. The value rolled is returned by calling .getValue( ). The Die class is fully implemented and does not require any student changes.

The class Player is used by the Bunco game to track the play of the two players. Each Player has its own Die that gets rolled when Player::roll( ) is called. For testing purposes, you can force a Player to roll a specific value by passing the desired (non-zero) value you want to .roll( ). In either case of a real roll or a cheated roll, the value rolled gets returned by .roll( ) for later use. Each Player tracks which round of play is currently active in the member mRound, a value between 1-6 inclusive. Player::getScore( )returns how many times the mRound value has been rolled by this Player in the current round of play. All of the operations of Player need to be completed. Please see the TODOcomments in the class for further information.
The relationship between Player and Die is diagrammed below.

The class BoardRow represents one row in the table that gets displayed while the game is running. Each row tracks the winner, if any, (designated with an X), if it is the current round of play (designated by an -----> ) and the row's round value. An array of BoardRow is stored inside the Board class. BoardRow::display( ) gets called whenever Board::display( ) is called. The BoardRow class is fully implemented and does not require any student changes.
The class Board represents the table that gets displayed while the game is running. Each Board tracks the current round of play, a value between 1-6 inclusive. Each Board has a set of 6 BoardRows that get looped over and printed whenever Board::display( ) is called. For simplicity sake, array elements 1-6 makeup the displayed board, exactly matching the round value. element 0 of the mBoardRow array is never shown. Board::setCurrentRound( ) informs the array elements that the round of play has changed. Board::markHumanAsWinner( ) and Board::markComputerAsWinner( ) should update the current BoardRow that a winner has been identified. Board::countUpHumanRoundWins( ) and Board::countUpComputerRoundWins( ) is used to determine who won the game. These methods should walk the array of BoardRow and count up how many times the human or computer won the six rounds of play, returning a count value between 0-6 inclusive. Various operations of the Board class need to be completed. Please see theTODO comments in the class for further information.

The relationship between Board and BoardRow is diagrammed below.
The class Bunco stores two Players (one human, one computer), a Board and tracks the current round of play. Bunco::computerPlay( ) and Bunco::humanPlay( ) let a Die roll take place by using operations of the Player class. For testing purposes, you can force a Player to roll a specific value by passing the desired (non-zero) value you want to .computerPlay( ) or .humanPlay( ) operation. In either case of a real roll or a cheated roll, the value rolled gets returned by .computerPlay( ) or .humanPlay( ) for later use. Various operations of the Bunco class need to be completed. Please see the TODO comments in the class for further information.
The enumeration ROUNDOUTCOME on the Bunco class describes the possible results of one round of play in the Bunco game. Either the human won, the computer won or the round has not yet been determined (because play is still underway or that round has not yet been played at all). The method Bunco::determineRoundOutcome( ) returns one of these values, considering the current round of play.
Once a game finishes, the GAMEOUTCOME enumeration on the Bunco class describes the possible results of the game. Either the Human won, the Computer won, the game wound up tied (because both the human and the computer won three rounds of play), or the outcome isGAMENOTOVER(meaning the game is still underway and the outcome is not yet known). The methodBunco::determineGameOutcome( ) returns one of these values, considering the state of the six BoardRows displayed on the Board.

The following diagram shows how all these classes are interconnected. As you can see, a Bunco class has two Players and a Board.
You are free to create additional public and private methods and data members as you see fit. However, the test cases will only be driving the public methods of the Player, Board and Bunco classes diagrammed here.
The source files you turn in will be these classes and a main routine. You can have the main routine do whatever you want, because we will rename it to something harmless, never call it, and append our own main routine to your file. Our main routine will thoroughly test your functions. You'll probably want your main routine to do the same. If you wish, you may write functions in addition to those required here. We will not directly call any such additional functions. If you wish, your implementation of a function required here may call other functions required here.
The program you turn in must build successfully, and during execution, no method may read anything from cin. If you want to print things out for debugging purposes, write to cerr instead of cout. When we test your program, we will cause everything written to cerr to be discarded instead we will never see that output, so you may leave those debugging output statements in your program if you wish.
Programming Guidelines
Your program must not use any function templates from the algorithms portion of the Standard C++ library. If you don't know what the previous sentence is talking about, you have nothing to worry about. Your implementations must not use any global variables whose values may be changed during execution. The correctness of your program must not depend on undefined program behavior.
What you will turn in for this assignment is a zip file named Project1 containing the following 11 files and nothing more:
The text files named Board.h and Board.cpp that implement the Board class diagrammed above, the text files named BoardRow.h and BoardRow.cpp that implement the BoardRow class diagrammed above, the text files named Die.h and Die.cpp that implement the Die class diagrammed above, the text files named Bunco.h and Bunco.cpp that implement the Bunco class diagrammed above, the text files named Player.h and Player.cpp that implement the Player class diagrammed above, and the text file named main.cpp which will hold your main program. Your source code should have helpful comments that explain any non-obvious code.
A nice way to test your functions is to use the assert facility from the standard library. As an example, here's a very incomplete set of tests for Project 1. Again, please build your solution incrementally. So I wouldn't run all these tests from the start because many of them will fail until you have all your code working. But I hope this gives you some ideas....
#include #include #include #include "Die.h" #include "Player.h" #include "Bunco.h" int main() { using namespace std; using namespace cs31; // test code
Die d; for (int i = 1; i =1 && valuePlayer p; assert( p.getScore() == 0 ); p.setRound( 1 ); assert( p.getScore() == 0 ); assert( p.roll( 6 ) == 6 ); assert( p.getScore() == 0 ); assert( p.roll( 5 ) == 5 ); assert( p.getScore() == 0 ); assert( p.roll( 1 ) == 1); assert( p.getScore() == 1 ); p.setRound( 6 ); assert( p.getScore() == 0 ); assert( p.roll( 6 ) == 6 ); assert( p.getScore() == 1 );Bunco b; b.setRound( 1 ); assert( b.determineRoundOutcome() == Bunco::NOTDECIDED ); b.computerPlay( 5 ); b.humanPlay( 5 ); assert( b.determineRoundOutcome() == Bunco::NOTDECIDED ); b.computerPlay( 1 ); b.humanPlay( 1 ); assert( b.determineRoundOutcome() == Bunco::NOTDECIDED ); b.computerPlay( 1 ); b.humanPlay( 2 ); assert( b.determineRoundOutcome() == Bunco::COMPUTERWON );couthere are the code in classes;
/////////// main.cpp//////////////////
#include
#include "Die.h"
#include "Player.h"
#include "Bunco.h"
void clearScreen( );
int main()
{
using namespace cs20;
using namespace std;
clearScreen();
Bunco game;
int human, computer;
int round = 1;
game.setRound( round );
std::string action, message = "(r)oll (q)uit: ";
cout
do
{
getline( cin, action );
while (action.size() == 0)
{
getline( cin, action ); // no blank entries allowed....
}
switch (action[0])
{
default: // if bad move, nobody moves
cout
continue;
case 'Q':
case 'q':
return 0;
case 'r':
case 'R':
human = game.humanPlay();
computer = game.computerPlay();
cout
cout
if (game.determineRoundOutcome() != Bunco::NOTDECIDED)
{
round = round + 1;
game.setRound(round);
cout
}
if (game.gameIsOver())
{
cout
}
break;
}
} while( !game.gameIsOver() );
return( 0 );
}
void clearScreen();
///////////////////////////////////////////////////////////////////////////
// clearScreen implementations
///////////////////////////////////////////////////////////////////////////
// DO NOT MODIFY OR REMOVE ANY CODE BETWEEN HERE AND THE END OF THE FILE!!!
// THE CODE IS SUITABLE FOR VISUAL C++, XCODE, AND g++ UNDER LINUX.
// Note to Xcode users: clearScreen() will just write a newline instead
// of clearing the window if you launch your program from within Xcode.
// That's acceptable.
#ifdef _MSC_VER // Microsoft Visual C++
#include
void clearScreen()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
COORD upperLeft = { 0, 0 };
DWORD dwCharsWritten;
FillConsoleOutputCharacter(hConsole, TCHAR(' '), dwConSize, upperLeft,
&dwCharsWritten);
SetConsoleCursorPosition(hConsole, upperLeft);
}
#else // not Microsoft Visual C++, so assume UNIX interface
#include
void clearScreen() // will just write a newline in an Xcode output window
{
using namespace std;
static const char* term = getenv("TERM");
if (term == nullptr || strcmp(term, "dumb") == 0)
{
cout
}
else
{
static const char* ESC_SEQ = "\x1B["; // ANSI Terminal esc seq: ESC [
cout
}
}
#endif
///////////die.cpp////////////
#include "Die.h"
#include
namespace cs20
{
Die::Die( int sides ) : mSides( sides ), mValue( 1 )
{
}
// this code generates a random distribution of values
// between 1 and mSides, storing the random value in the
// member variable mValue for later use
void Die::roll()
{
std::random_device rd;
std::mt19937 e2(rd());
std::uniform_int_distribution dist(1, mSides);
mValue = dist(e2);
}
// returns the most recent tossed value
int Die::getValue( ) const
{
return( mValue );
}
}
////////// die.h ///////
#ifndef Die_h
#define Die_h
namespace cs20
{
// CS 20A Students have been provided this class which
// simulates a random Die toss. When roll( ) is called,
// a value between 1 - mSides will be calculated and stored.
// Retrieve the value rolled by calling getValue( ).
class Die
{
public:
Die( int sides = 6 ); // by default, a six sided die
void roll(); // tossing the die, updating mValue
int getValue( ) const; // retrieve the value that was just tossed
private:
int mSides; // how many sides are on this die?
int mValue; // the value of the most recent toss
};
}
#endif /* Die_h */
//// player.cpp //////
#include "Player.h"
namespace cs20
{
Player::Player() : mDie( 6 ), mScore( 0 ), mRound( 0 )
{
}
// TODO: roll the die and adjust the score for the current round
// accordingly
// when the amount is zero, the Die should be rolled for random play
// when the amount is not zero, we are trying to cheat for testing
// purposes. in that case, this method should force a specific roll
// amount.
int Player::roll( int amount )
{
// stubbed out for now...
return( 0 );
}
// TODO: set the current round and reset the player's score to 0
void Player::setRound( int round )
{
// stubbed out for now...
}
// TODO: return the score member variable
int Player::getScore( ) const
{
// stubbed out for now...
return( 0 );
}
}
//// player.h //////
#ifndef Player_h
#define Player_h
#include "Die.h"
namespace cs20
{
// CS 20A students have been provided this class to represent
// one of the Bunco Players. Each Player has its own Die, knows
// which round is currently being played and knows how to scores
// it rolled value for the current round.
// CS 20A students need to complete the TODO portions of this class
class Player
{
public:
Player();
int roll( int amount = 0 ); // toss the Die, unless provided a forced amount value
void setRound( int round ); // set current round, resetting the Player's score
int getScore( ) const; // how many times has Player tossed the current round value?
private:
Die mDie; // the Player's Die
int mScore; // the Player's score for this round
int mRound; // the current round value, a number between 1 and 6
};
}
#endif /* Player_h */
////// Bunco.cpp //////
#include "Bunco.h"
#include
namespace cs20
{
Bunco::Bunco() : mRound( 0 )
{
}
// stringify the game by stringifying the board
std::string Bunco::display( std::string msg ) const
{
using namespace std;
std::string s = mBoard.display();
s = s + msg;
if (gameIsOver())
{
if (determineGameOutcome() == TIEDGAME)
{
s = s + " \t\tBunco wound up tied! ";
}
else if (determineGameOutcome() == HUMANWONGAME)
{
s = s + " \t\tyou won Bunco! ";
}
else
{
s = s + " \t\tyou lost Bunco! ";
}
}
return( s );
}
// set the current round of play, notifying the board and each
// player of the current round
void Bunco::setRound( int round )
{
mRound = round;
mBoard.setCurrentRound( round );
mHuman.setRound(round);
mComputer.setRound(round);
}
// TODO: let the human player play
// when the amount is zero, the Die should be rolled for random play
// when the amount is not zero, we are trying to cheat for testing
// purposes. in that case, this method should force a specific roll
// amount.
int Bunco::humanPlay( int amount )
{
// stubbed out for now...
int amountrolled = 0;
return( amountrolled );
}
// TODO: let the computer player play
// when the amount is zero, the Die should be rolled for random play
// when the amount is not zero, we are trying to cheat for testing
// purposes. in that case, this method should force a specific roll
// amount.
int Bunco::computerPlay( int amount )
{
// stubbed out for now...
int amountrolled = 0;
return( amountrolled );
}
// TODO: considering each player's score, determine the
// winner of this round of play
Bunco::ROUNDOUTCOME Bunco::determineRoundOutcome( )
{
// stubbed out for now...
ROUNDOUTCOME result = ROUNDOUTCOME::NOTDECIDED;
return( result );
}
// TODO: count up the number of won rounds by each player to determine
// the game's outcome
Bunco::GAMEOUTCOME Bunco::determineGameOutcome( ) const
{
// stubbed out for now...
GAMEOUTCOME result = GAMEOUTCOME::GAMENOTOVER;
return( result );
}
// is the game over?
bool Bunco::gameIsOver() const
{
GAMEOUTCOME result = determineGameOutcome();
return( result != GAMENOTOVER );
}
}
///// Bunco.h //////
#ifndef Bunco_h
#define Bunco_h
#include
#include "Player.h"
#include "Board.h"
namespace cs20
{
// CS 20A students have been provided this class to represent
// a Bunco Game. Each Game is made up of a Board, two Players
// and tracks the current round of play.
// CS 20A students need to complete the TODO portions of this class
class Bunco
{
public:
Bunco();
// the possible results of a round:
// - either a player won (human or computer) or
// - the outcome has yet to be decided yet
enum ROUNDOUTCOME { HUMANWON, COMPUTERWON, NOTDECIDED };
// the possible results of a game:
// - either a player won (human or computer) or
// - the game wound up tied or
// - the game is not yet over
enum GAMEOUTCOME { HUMANWONGAME, COMPUTERWONGAME, TIEDGAME, GAMENOTOVER };
// stringify this Game by stringifying the Game's Board
std::string display( std::string msg = "" ) const;
// set the current round of play
void setRound( int round );
// let the human player toss the die, returning the value rolled
// if a non-zero amount is passed, we are trying to cheat for
// testing purposes and force a particular rolled value
int humanPlay( int amount = 0 );
// let the computer player toss the die, returning the value rolled
// if a non-zero amount is passed, we are trying to cheat for
// testing purposes and force a particular rolled value
int computerPlay( int amount = 0 );
// what is the current round's result?
ROUNDOUTCOME determineRoundOutcome( );
// what is the game's result?
GAMEOUTCOME determineGameOutcome( ) const;
// is the game over?
bool gameIsOver() const;
private:
Player mHuman; // the human player
Player mComputer; // the computer player
int mRound; // the current round of play
Board mBoard; // this game's board
};
}
#endif /* Bunco_h */
///// Board.cpp ////
#include "Board.h"
namespace cs20
{
Board::Board() : mRound( 0 )
{
// initialize each BoardRow
for (int i = 1; i
{
mBoardRow[ i ].setRound( i );
}
}
void Board::setCurrentRound( int round )
{
// unset the current board row
if (mRound >= 0 && mRound
mBoardRow[ mRound ].setCurrentRound( false );
mRound = round;
// set the current board row
if (mRound >=0 && mRound
mBoardRow[ mRound ].setCurrentRound(true);
}
// TODO: set the human player to have won this current BoardRow
void Board::markHumanAsWinner()
{
// stubbed out for now...
}
// TODO: set the computer player to have won this current BoardRow
void Board::markComputerAsWinner()
{
// stubbed out for now...
}
// stringify the Board
std::string Board::display( ) const
{
std::string s = "\t\t Bunco Game \tHuman\t\t\tComputer ";
for( int i = 1; i
{
s += mBoardRow[ i ].display() + " ";
}
return( s );
}
// TODO: how many rounds has the human player won?
int Board::countUpHumanRoundWins( ) const
{
// stubbed out for now...
return( 0 );
}
// TODO: how many rounds has the computer player won?
int Board::countUpComputerRoundWins( ) const
{
// stubbed out for now...
return( 0 );
}
}
//// Board.h /////
#ifndef Board_h
#define Board_h
#include "BoardRow.h"
namespace cs20
{
// CS 20 students have been provided this class to represent
// a Bunco Board. Each Board is made up of an array of BoardRow.
// The display( ) method is used by the Bunco game to print the
// current state of the game. Each Board knows the current round
// in play. Each Board gets told when either the human player wins
// the round or the computer player wins the round. Given the
// array of BoardRow, this class can count up how many rounds each
// player has won.
// CS 20 students need to complete the TODO portions of this class
class Board
{
public:
Board();
// set the current round
void setCurrentRound( int round );
// set human as the round winner
void markHumanAsWinner();
// set the computer as the round winner
void markComputerAsWinner();
// how many rounds has the computer won so far?
int countUpComputerRoundWins( ) const;
// how many rounds has the comptuer won so far?
int countUpHumanRoundWins( ) const;
// stringify this Board
std::string display( ) const;
private:
BoardRow mBoardRow[ 7 ]; // elements 1-6, ignoring spot 0,
// are used for rounds 1-6
int mRound; // the current round of play
};
}
#endif /* Board_h */
//// BoardRow.cpp ////
#include "BoardRow.h"
namespace cs20
{
BoardRow::BoardRow() : mHumanWinner( false ),
mComputerWinner( false ),
mRound( 0 ),
mCurrentRound( false )
{
}
void BoardRow::setHumanAsWinner()
{
mHumanWinner = true;
}
void BoardRow::setComputerAsWinner()
{
mComputerWinner = true;
}
void BoardRow::setRound( int round )
{
mRound = round;
}
void BoardRow::setCurrentRound( bool b )
{
mCurrentRound = b;
}
bool BoardRow::didComputerWin( ) const
{
return( mComputerWinner );
}
bool BoardRow::didHumanWin( ) const
{
return( mHumanWinner );
}
// in stringifying this row, -----> is used to mark the current
// row in play and X is used to mark the winner of the round
std::string BoardRow::display() const
{
std::string s = "";
if (mCurrentRound)
{
s = s + "--->";
}
s = s + "\t";
if (mHumanWinner)
{
s = s + "X\t";
}
else
{
s = s + "\t";
}
s = s + "\t";
char c = mRound + '0';
s = s + c + "\t";
if (mComputerWinner)
{
s = s + "X\t";
}
else
{
s = s + "\t";
}
return( s );
}
}
//// BoardRow.h /////
#ifndef BoardRow_h
#define BoardRow_h
#include
namespace cs20
{
// CS 20A Students have been provided this class which
// is used to print one row in the Bunco board. A row
// tracks who won (the human player or the computer player)
// with an X and uses an arrow (------>) to mark the
// current round
class BoardRow
{
public:
BoardRow();
void setHumanAsWinner(); // has the human player won?
bool didHumanWin( ) const;
void setComputerAsWinner(); // has the computer player won?
bool didComputerWin( ) const;
void setRound( int round ); // what is the round of this row?
void setCurrentRound( bool b ); // is this round the current round in play?
std::string display() const; // stringify this row
private:
bool mHumanWinner;
bool mComputerWinner;
int mRound;
bool mCurrentRound;
};
}
#endif /* BoardRow_h */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
