Question: Hello, I need help with this poker game example in C++ (im using xcode on the mac btw) There are two parts for this lab
Hello, I need help with this poker game example in C++ (im using xcode on the mac btw)
There are two parts for this lab example but I only need help with the second part right now. The instructions look long, but i promise its just an overkill explanation from the book's part. **AGAIN** I only need help with the second part that i'll show below. After the pictured instructions, I will provide all the source codes mentioned: card, deck & game1 (game1 was part 1).
I need help with game2 and hand please!!
-------------------------------------------------------------------------------------------------------------------------
The first page and half is just explanation, then the instructions for part 1 begin with the words " write a program that deals out 10,000 five card hands ..."



-------------------------------------------------------------------------------------------------------------------------
THIS NEXT PICTURE IS THE DESCRIPTION FOR PART 2: THIS IS THE ONE I NEED HELP WITH PLEASE

-------------------------------------------------------------------------------------------------------------------------
PROVIDED CODES:
/ / card.h
#ifndef _CARD_H
#define _CARD_H
class Card {
public:
// Define types for the suit and value
enum Suit { Diamonds, Hearts, Clubs, Spades };
enum Value { NullCard, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King };
private:
static const char *snames[4];
static const char *vnames[14];
Suit s;
Value v;
public:
// Constructors initialize a card
Card();
Card(Suit newSuit, Value newValue);
Suit getSuit(); // Returns a card's suit.
Value getValue(); // Returns a card's value.
void printSuit(); // Print a card's suit.
void printValue(); // Print a card's value.
void printCard(); // Print a card's suit and value.
};
// Return the next suit or card value in succession
Card::Suit nextSuit(Card::Suit);
Card::Value nextValue(Card::Value);
#endif
-------------------------------------------------------------------------------------------------------------------------
/ / card.cpp
#include
#include "card.h"
using namespace std;
const char * Card::snames[4] = {" Diamonds", "Hearts", "Clubs", "Spades" };
const char * Card::vnames[14] = {" Bad Card", "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
Card::Card() {
v = NullCard;
}
Card::Card(Suit newSuit, Value newValue) {
s = newSuit;
v = newValue;
}
Card::Suit Card::getSuit() {
return s;
}
Card::Value Card::getValue() {
return v;
}
void Card::printSuit() {
cout
}
void Card::printValue() {
cout
}
void Card::printCard() {
printValue();
cout
printSuit();
}
Card::Suit nextSuit(Card::Suit s) {
return(s+1 > Card::Spades) ? Card::Diamonds : (Card::Suit) (s+1);
}
Card::Value nextValue(Card::Value v) {
return(v+1 > Card::King) ? Card::Ace : (Card::Value) (v+1);
}
-------------------------------------------------------------------------------------------------------------------------
/ / deck.h
#ifndef _DECK_H
#define _DECK_H
#include "card.h"
const int DECKSIZE = 52;
class Deck {
private:
Card inDeck[DECKSIZE]; // These are private data members and
int nextCard; // can be used only by member functions.
public:
Deck(); // Initialization. Called automatically
// when a Deck variable is declared.
void shuffle(int); // Exchange random pairs of cards.
Card getCard(); // Returns top card from the deck.
void addCard(Card); // Put named card in the deck.
int totalCards(); // Returns number of cards left in deck.
};
#endif
------------------------------------------------------------------------------------------------------------------------- / / deck.cpp
#include
#include "deck.h"
Deck::Deck() {
int i;
Card::Suit curSuit;
Card::Value curValue;
nextCard = 0;
for(i = 0, curSuit = Card::Diamonds, curValue = Card::Ace; i
inDeck[i] = Card(curSuit, curValue);
curValue = nextValue(curValue);
if (curValue == Card::Ace)
curSuit = nextSuit(curSuit);
}
}
void Deck::shuffle(int swaps) {
Card temp;
for (int i = 0; i
int i1 = rand() % DECKSIZE;
int i2 = rand() % DECKSIZE;
temp = inDeck[i1];
inDeck[i1] = inDeck[i2];
inDeck[i2] = temp;
}
}
Card Deck::getCard() {
return(nextCard
}
void Deck::addCard(Card newCard) {
if (nextCard > 0)
inDeck[--nextCard] = newCard;
}
int Deck::totalCards() {
return DECKSIZE - nextCard;
}
-------------------------------------------------------------------------------------------------------------------------
/ / game1.h
#ifndef game1_h
#define game1_h
#include "card.h"
#include "deck.h"
class Game
{
private:
Card hand[5]; //5 cards to represent the hand
Deck deck;
int maxHands; // the number of hands to deal
int flushs[100], pairs[100]; // the count of flushes and pairs for each trial
int trials;
void dealHand(); //deal a hand
void returnCards(); // return the cards in hand back to deck
void checkHand(int trial); //check the type of hand
bool isPair(); //to check if hand is a pair
bool isFlush(); //to check if hand is flush
public:
Game(int numHands = 10000, int numTrials = 10); //constructor to initialize with how many hands to be dealt
void start();
void printStats();
};
#endif /* game1_h */
-------------------------------------------------------------------------------------------------------------------------
/ / game1.cpp
#include "game1.h"
#include
#include
#include
#include
using namespace std;
Game::Game(int numHands, int trials) //constructor to initialize with how many hands to be dealt
{
this->maxHands = numHands;
this->trials = trials;
}
void Game::start()
{
srand(time(0));
for(int t = 0; t
{
for(int i = 1; i
{
dealHand();
checkHand(t);
returnCards();
}
}
}
void Game::dealHand() //deal a hand
{
deck.shuffle(100);
for(int i = 0; i
{
hand[i] = deck.getCard();
//hand[i].printCard();
}
}
void Game::returnCards() // return the cards in hand back to deck
{
for(int i = 0; i
deck.addCard(hand[i]);
}
void Game::checkHand(int trial)//check the type of hand
{
if(isPair())
pairs[trial]++;
else if(isFlush())
flushs[trial]++;
}
bool Game::isPair()
{
int count[14] = {0}; //counter to keep the count of cards of same value, 1 counter each for ACE, TWO ....etc
Card::Value v;
for(int i = 0; i
{
v = hand[i].getValue();
count[v] ++;
if(count[v] == 2)
return true;
}
return false;
}
bool Game::isFlush()
{
for(int i = 1; i
{
if(hand[i].getSuit() != hand[0].getSuit()) //check to see if all cards are from same suit as 1st card?, if not return false
return false;
}
return true;
}
void Game::printStats()
{
double pairPc, flushPc;
double avgPairPc = 0, avgFlushPc = 0;
cout
cout
for(int i = 0; i
{
pairPc = pairs[i] * 100.0 / maxHands;
flushPc = flushs[i] * 100.0 / maxHands;
avgPairPc += pairPc;
avgFlushPc += flushPc;
cout
}
avgPairPc /= trials;
avgFlushPc /= trials;
cout
cout
}
int main()
{
Game g;
g.start();
g.printStats();
}
Classes Lab (Poker) For this this assignment you will be given the code for two classes (Card and Deck) enting a set of playing cards. Using these classes, you will write a m, game1.h and gamel.cpp, that calculates the representing a set of of certain poker hands. frequency of occurrence be necessary to understand the code (and at this point I don't expect you to) not Note that that while I will give a simple description of each of the classes below, it will for understand the classes in order to use the classes in your program. You will only in order to use the classes in your programYou will only need to need to be able to compile able to compile these classes without modification. In fact, I do not want you classes. You should to modity the the classes, unless your include statement requires a change to modify the cla ostream to iostream.h and your compiler does not require a namespace from iostreanm declaration. The Card class is defined in card. h and card.cpp. These files define a class (data type) for representing individual playing cards. A card can be initialized inspected, and printed using the following methods getSuit (1 getValue () printsuit() printValue () printCard )) Note that the Card class defines enumerated data types to represent the suit and value. You can use these types in your program, but since they are defined within the Card class, you have to use the scope resolution operator to access them. That is, if your program needs to define a variable to contain a card value, it would be declared: Card::Value cv If you want to assign the value ACE to this variable, you would write cv Card:ACE; = Page Focus on Object-Oriented Programming with C++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
