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 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;
// 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))
{
// Check if also a flush
if (isFlush(hand))
{
++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;
}
}
// Display all of the cards in the deck
void deal(const unsigned int wDeck[], const char* wFace[],
const char* wSuit[])
{
// deal each of the cards
for (size_t card =0; card < CARDS; ++card){
size_t suit = wDeck[card]/ FACES;
size_t face = wDeck[card]% FACES;
printf("%5s of %-8s%c", wFace[face], wSuit[suit],
card %4==3?'
' : '\t'); //4-column format
}
}
void dealNextHand(unsigned int wDeck[], unsigned int hand[])
{
static unsigned int currentCard =0; //remembers which is the next card to be dealt.
// Shuffle deck and start from beginning of the deck if not enough cards left for a whole hand
if ((currentCard + HAND_SIZE)>= CARDS)
{
shuffle(wDeck);
currentCard =0;
}
// Deal out HAND_SIZE cards from wDeck into the hand array
for (size_t card =0; card < HAND_SIZE; ++card)
{
hand[card]= wDeck[currentCard++];
}
}
void swap(unsigned int* const card1, unsigned int* const card2)
{
// Student implements this function
}
// Shuffle cards in deck
// Must invoke swap() function above
void shuffle(unsigned int wDeck[])
{
// Student implements this function
}
// Returns true if hand contains only a pair and false other wise.
// Note: will return FALSE if the hand contains any of these hand types as well.
// Hand has 2 pairs.
// hand has 3 of kind
// Hand is a full house
// hand has 4 of kind
int isPair(const unsigned int hand[])
{
}
// NOTE ONLY C PROGRAMMING. ALL CODE IS PROVIDED JUST WRITE CODE FOR THE LAST 3 FUNCTIONS.

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_2

Step: 3

blur-text-image_3

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 Systems For Advanced Applications 27th International Conference Dasfaa 2022 Virtual Event April 11 14 2022 Proceedings Part 2 Lncs 13246

Authors: Arnab Bhattacharya ,Janice Lee Mong Li ,Divyakant Agrawal ,P. Krishna Reddy ,Mukesh Mohania ,Anirban Mondal ,Vikram Goyal ,Rage Uday Kiran

1st Edition

3031001257, 978-3031001253

More Books

Students also viewed these Databases questions

Question

Describe the types of power that effective leaders employ

Answered: 1 week ago

Question

Describe how leadership styles should be adapted to the situation

Answered: 1 week ago