prototypes
void shuffle(int deck[][FACES]);
void deal(int deck[][FACES], const char *face[], const char *suit[]);
int main(void) {
// initialize deck array
int deck[SUITS][FACES] = {{0}};
srand(time(NULL)); // seed random-number generator
shuffle(deck); // shuffle the deck
// 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"};
deal(deck, face, suit); // deal the deck
}
// shuffle cards in deck
void shuffle(int deck[][FACES]) {
// for each of the cards, choose slot of deck randomly
for (size_t card = 1; card <= CARDS; card++) {
size_t row = 0; // row number
size_t col = 0; // column number
// choose new random location until unoccupied slot found
do {
row = rand() % SUITS;
col = rand() % FACES;
} while (deck[row][col] != 0);
deck[row][col] = card; // place card number in chosen slot
}
}
// deal cards in deck
void deal(int deck[][FACES], const char *face[], const char *suit[]) {
// deal each of the cards
for (size_t card = 1; card <= CARDS; card++) {
// loop through rows of deck
for (size_t row = 0; row < SUITS; row++) {
// loop through columns of deck for current row
for (size_t col = 0; col < FACES; ++col) {
// if slot contains current card, display card
if (deck[row][col] == card) {
printf("%5s of %-8s %c", face[col], suit[row],
card % 4 == 0 ? '\n' : '\0'); // 2-column format
}
}
}
}
}
int containsPair(int hand[][FACES]) {
for (int )
}
Modify the program so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determine whether the hand contains two pairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determine whether the hand contains four of a kind (e.g., four aces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of consecu- tive face values).
Обсуждают сегодня