/* cards.c -- sample program for structs and arrays */
/* A simple card game: Let's call it HIGH CARD WINS */
#include <stdio.h>
typedef struct {
char rank, suit;
} card;
#define DECK_SIZE 52
#define HAND_SIZE 5
/* function prototypes */
void initialize_deck(card theDeck[], char theSuits[], char theRanks[]);
void shuffle(card theDeck[]);
int cardcmp(card c1, card c2);
card find_high_card(card hand[]);
card deal_a_card(card theDeck[]);
#include "cardfns.c"
int main(void) {
char suits[4] = {'S','H','D','C'};
char ranks[13] = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
card deck[DECK_SIZE];
card player_A_hand[HAND_SIZE], player_B_hand[HAND_SIZE];
int i;
int result;
card player_A_high_card, player_B_high_card;
initialize_deck(deck, suits, ranks);
shuffle(deck);
/* Deal 5 cards to each of 2 players */
for (i = 0; i < HAND_SIZE; i++) {
player_A_hand[i] = deal_a_card(deck);
player_B_hand[i] = deal_a_card(deck);
}
player_A_high_card = find_high_card(player_A_hand);
player_B_high_card = find_high_card(player_B_hand);
result = cardcmp(player_A_high_card, player_B_high_card);
if (result < 0) printf("Player B wins!\n");
if (result == 0) printf("It's a tie!\n");
if (result > 0) printf("Player A wins!\n");
return 0;
}