Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #define SUITS 4 #define FACES 1 3 #define CARDS 5 2 #define HAND _ SIZE 5 #define HANDS _ IN _ DECK

#include
#include
#include
#define SUITS 4
#define FACES 13
#define CARDS 52
#define HAND_SIZE 5
#define HANDS_IN_DECK 10
#define NUMBER_OF_HANDS_PLAYED 10000000//Currently set to 10 million
#define NUMB_HANDS_STR "10 million" //Currently set to 10 million
#define TRUE 1
#define FALSE 0
// prototypes of functions supplied
void deal(const unsigned int wDeck[], const char* wFace[],//display all cards in deck
const char* wSuit[]);
void dealNextHand(unsigned int wDeck[], unsigned int hand[]); //deal out next hand from the deck
int isFourOfAKind(const unsigned int hand[]); // return true if hand contains four of a kind and false otherwise
// prototypes of functions you must implement
void swap(unsigned int* const, unsigned int* const); //swap the two cards pointed to by the 2 pointers
void shuffle(unsigned int wDeck[]); //shuffle deck
int isPair(const unsigned int hand[]); // return true if hand contains a pair and false otherwise
int isTwoPair(const unsigned int hand[]); // return true if hand contains a two pair and false otherwise
int isThreeOfAKind(const unsigned int hand[]); // return true if hand contains three of a kind and false otherwise
int isStraight(const unsigned int hand[]); // return true if hand is a straight and false otherwise
int isFlush(const unsigned int hand[]); // return true if hand is a flush and false otherwise
int isFullHouse(const unsigned int hand[]); // return true if hand is a full house and false otherwise
int isRoyalFlush(const unsigned int hand[]); // return true if hand is a royal flush and false otherwise
int main(void)
{
// define and initialize deck array
unsigned int deck[CARDS];
// initialize deck with values 0 to CARDS-1
// value /13 caluclates suit # { "Hearts", "Diamonds", "Clubs", "Spades" };
// value %13 calculates face card {Ace,2,3,...10, Jack, Queen, King}
for (size_t card =0; card < CARDS; ++card)
{
deck[card]= card;
}
srand((unsigned int)time(NULL)); // seed random-number generator
// initialize suit array
const char* suit[SUITS]=
{ "Hearts", "Diamonds", "Clubs", "Spades" };
// initialize face array
const char* face[FACES]=
{ "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
shuffle(deck); // uncomment after completing the implementation
// of the swap() and shuffle() functions
deal(deck, face, suit); // display the deck unshuffled
unsigned int hand[HAND_SIZE]; // will contain the cards in the hand.
//Define and initialize variables used to count each type of hand
unsigned int pairCount =0;
unsigned int twoPairCount =0;
unsigned int threeOfAKindCount =0;
unsigned int straightCount =0;
unsigned int flushCount =0;
unsigned int fullHouseCount =0;
unsigned int fourOfAKindCount =0;
unsigned int straightFlushCount =0;
unsigned int royalFlushCount =0;//NOTE: This count includes both straight flushes and royal flushes.
// Shuffle the deck for the first time
// After this, we shuffle deck every time we do not have enough undealth cards
// for a complete hand which will be every 10 deals assuming five card hands
shuffle(deck);
// Deal out NUMBER_OF_HANDS_PLAYED hands
for (size_t hands =1; hands < NUMBER_OF_HANDS_PLAYED; ++hands)
{
dealNextHand(deck, hand); // Deal out next 5 cards from the deck into the array hand
// Does hand have a pair?
if (isPair(hand))
{
++pairCount; // Yes, increment pair count
}
// Does hand have two pair?
if (isTwoPair(hand))
{
++twoPairCount;
}
// Does hand have three of a kind?
if (isThreeOfAKind(hand))
{
++threeOfAKindCount;
}
// Does hand have a straight?
if (isStraight(hand))
{
if (isFlush)
{
++straightFlushCount; // both straight and flush
}
else
{
++straightCount; // nope, just a straight
}
}
// Does hand have a flush?
if (isFlush(hand))//not a straight, how about a flush?
{
++flushCount;
}
// Does hand have a full house?
if (isFullHouse(hand))
{
++fullHouseCount;
}
// Does hand have four of a kind?
if (isFourOfAKind(hand))
{
++fourOfAKindCount;
}
}
int isFullHouse(const unsigned int hand[])
{
}
int isRoyalFlush(const unsigned int hand[])
{
}
int isStright(const unsigned int hand[])
{
}
//NOTE write code for just last 3 functions also change if statement in main so straight do not count if a card is royal flush. ++royal flush in main's if statement.

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions