Beispiel #1
0
/* Usage: deck hand_size number_of_hands */
int main(int argc, char *argv[]) {

    /* input */
    int nhands;                   /* stores number of hands from input */
    int handSize;                 /* stores hand size from input */
    int canDisplayHands;          /* flag to indicate if the hands can be displayed */

    int foundErrors = NO_ERRORS;  /* indicate whether errors are found */

    /* validate input */
    if (validInput(argc, argv, &handSize, &nhands)) {

        Card deck[DECK_SIZE];     /* the cards deck */
        Hand hands[nhands];       /* the hands */
        Hand sortedHands[nhands];

        canDisplayHands = (handSize && nhands) > 0 ? TRUE : FALSE;

        /* create a deck of cards. */
        printf("\n   Create and display the deck.\n\n");
        createDeck(deck);
        displayDeck(deck, DECK_SIZE);

        /* shuffle deck of cards */
        printf("\n   Shuffle and display the deck.\n\n");
        shuffleDeck(deck, DECK_SIZE);
        displayDeck(deck, DECK_SIZE);

        if (canDisplayHands) {
            /* create and display hands */
            printf("\n   Create and display hands.\n\n");
            createHands(deck, hands, handSize, nhands);
            sortHands(hands, sortedHands, handSize, nhands);

            displayHands(hands, sortedHands, handSize, nhands);

            /* rank hands */
            printf("\n   Rank and display ranked hands.\n\n");
            displayRankedHands(sortedHands, nhands);

            printf("\n   Display winners.\n\n");
            displayWinners(sortedHands, nhands);
        }
        else {
            printf("\nCould not display hands because either the hand size or the number of hands is zero.\n");
        }
    }
    else {
        /* invalid input */
        printf("Usage: deck hand_size number_of_hands\n");
        foundErrors = ERRORS;
    }
    return foundErrors;
}
Beispiel #2
0
/**
 * 
 * @param argc
 * @param argv
 * @return 
 */
int main(int argc, char** argv) {
    
    //Command line input
    int players;
    int cards;
    
    cards = atoi(argv[1]);
    players = atoi(argv[2]);
    
    cards = 5; //Force cards to 5
//    players = 5;

    //Validate
    if (players < MINPLAYERS || players > MAXPLAYERS) {
        printf("Players too high or too low!!!\n");
        return 0;
    }
    if (cards < MINCARDS || cards > MAXCARDS) {
        printf("Cards too high or too low!!!\n");
        return 0;
    }
        
    //Create
    struct card deck[NUMCARDS]; //Create the deck
    createDeck(deck); //Fill the deck
    
    //Display
    printf("Unshuffled deck(suit, val):\n");
    //printDeck(deck);
    printDeckColumned(deck);
    printf("\n");
    
    //Shuffle
    shuffleDeck(deck);
    
    //Display
    printf("Shuffled deck(suit, val):\n");
    //printDeck(deck);
    printDeckColumned(deck);
    printf("\n");
    
    //Deal
    printf("Dealing.\n\n");
    struct hand * hands = dealDeck(players, cards, deck);
    
    //Show Hands
    printf("Player's hands(unsorted):\n");
    printHandsNamed(players, cards, hands);
    printf("\n");
    
    //Sort Hands
    sortHands(players, cards, hands);
    
    //Show Hands
    printf("Player's hands(sorted):\n");
    printHandsNamed(players, cards, hands);
    printf("\n");
    
//    //Fixed cards for testing (suit, value)
//    struct card card1 = makeCard(4,3);
//    struct card card2 = makeCard(4,4);
//    struct card card3 = makeCard(4,5);
//    struct card card4 = makeCard(4,6);
//    struct card card5 = makeCard(4,7);
//    
//    //Fixed hand for testing
//    struct hand fixedHand;
//    fixedHand.cards[0] = card1;
//    fixedHand.cards[1] = card2;
//    fixedHand.cards[2] = card3;
//    fixedHand.cards[3] = card4;
//    fixedHand.cards[4] = card5;
//    
//    printHandsNamed(1,5,&fixedHand);
//    rankHand(&fixedHand);
//    printHandsNamed(1,5,&fixedHand);
//    printf("%i",fixedHand.rank);
    
    //Rank hands
    rankHands(players, hands);
    
    //Show hands with ranks
    printf("Players hands' ranks:\n");
    printHandsRanked(players, hands);
    
    //Determine winner
    determineWinner(players, hands);
    
    return (0);
}