// Authors: Deitel & Deitel - C How to Program #include #include #include void shuffle (int wDeck[][13]); void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[]); void evaluate_hand(Card hand2); int which_one_better(Card hand1, Card hand2); typedef strcut { int face_index; int suit_index; }Card; int main (void) { /* initialize suit array */ const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"}; /* initialize face array */ const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; /* initalize deck array */ int deck[4][13] = {0}; Card hand1[5]; Card hand2[5]; evaluate_hand(hand1); evaluate_hand(hand2); which_one_better(hand1, hand2); srand ((unsigned) time (NULL)); /* seed random-number generator */ shuffle (deck); deal (deck, face, suit, hand); return 0; } /* shuffle cards in deck */ void shuffle (int wDeck[][13]) { int row = 0; /* row number */ int column = 0; /*column number */ int card = 0; /* card counter */ /* for each of the 52 cards, choose slot of deck randomly */ for (card = 1; card <= 52; card++) { /* choose new random location until unoccupied slot found */ do { row = rand () % 4; column = rand () % 13; } while (wDeck[row][column] != 0); /* place card number in chosen slot of deck */ wDeck[row][column] = card; } } /* deal cards in deck */ void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[], Card * hand_deal) { int row = 0; /* row number */ int column = 0; /*column number */ int card = 0; /* card counter */ int h = 0; /* deal each of the 52 cards */ for (card = 1; card <= 5; card++) { /* loop through rows of wDeck */ for (row = 0; row <= 3; row++) { /* loop through columns of wDeck for current row */ for (column = 0; column <= 12; column++) { /* if slot contains current card, display card */ if (wDeck[row][column] == card) { hand_deal[h]->face_index = row; hand_deal[h]->suit_index = column; h++; printf ("%5s of %-8s%c", wFace[column], wSuit[row], card % 2 == 0 ? '\n' : '\t'); } } } } } /* Question 2 */ void evaluate_hand(Card hand_eva[]) { if (a_pair(hand_eva)) {printf("The hand has a pair\n");} else { printf("The hand does not have a pair \n");} /* use "if else" to evalute other cases: two pairs, three of a kind, etc.*/ } int which_one_better(Card hand1_cmp, Card hand2_cmp) { /* Evaluate hands by ranking: four of a kind, flush, straight, three of a kind, two pair, and one pair*/ if (four_of_kind(hand1_cmp) > four_of_kind(hand2_cmp)) {return 1;} // hand1 is better than hand2. else if (four_of_kind(hand1_cmp) < four_of_kind(hand2_cmp)) {return -1;} else {..... /*the case that both hands have four of a kind*/} // do the similar statement for other cases: flush, straight, .... }