/** * Determines an integer value which represents the quality of a hand. The higher the number the better the hand. * * @param hand array of integers which represent cards in a deck * @param wFace character array representing face names * @param wSuit character array representing suit names * * @return a integer value representing the quality of the hand */ int qualityOfHand(int hand[], const char *wFace[], const char *wSuit[]){ int quality = 0; if(straight(hand, wFace) == 1){ quality = 6; }else if(flush(hand, wSuit) == 1){ quality = 5; }else if(fourOfAKind(hand, wFace) == 1){ quality = 4; }else if(threeOfAKind(hand, wFace) == 1){ quality = 3; }else if(twoPair(hand, wFace) == 1){ quality = 2; }else if(onePair(hand, wFace) == 1){ quality = 1; }else{ quality = 0; } return quality; }
//get the card power, as follow: //royal flush: 900 + all the cards values //straight flush: 800 + all the cards values //four of a kind: 700 + all the cards values //full house: 600 + all the cards values //flush: 500 + all the cards values //straight: 400 + all the cards values //three of a kind: 300 + all the cards values //two pairs: 200 + all the cards values //pair: 100 + all the cards values //high card: sum of all the cards value (5 * 13 will never be more than 100 so...) int getHandPower(Card c[5]) { p = sumCardNums(c, 0); p += sumCardNums(c, 1); sortCards(c); if(royalFlush(c)) { p += 900; return p; } if(straightFlush(c)) { p += 800; return p; } if(fourOfAKind(c)) { p += 700; return p; } if(fullHouse(c)) { p += 600; return p; } if(flush(c)) { p += 500; return p; } if(straight(c)) { p += 400; return p; } if(threeOfAKind(c)) { p += 300; return p; } if(twoPairs(c)) { p += 200; return p; } if(pair(c)) { p += 100; return p; } return p; }
/** * Takes a array array of cards and distributes them among each player * * @param hands array of hands to be filled * @param wDeck array of cards * @param wFace character array representing face names * @param wSuit character array representing suit names */ void deal(int hands[][5], unsigned int wDeck[][FACES], const char *wFace[],const char *wSuit[]){ size_t card; // card counter size_t row; // row counter size_t column; // column counter for(int player = 0; player < PLAYERS; player++){ printf("Player %d: \n\n", player + 1); // deal each of the cards for ( card = 0; card < 5; card++ ) { // loop through rows of wDeck for ( row = 0; row < SUITS; ++row ) { // loop through columns of wDeck for current row for ( column = 0; column < FACES; column++ ) { // if slot contains current card, display card if ( wDeck[ row ][ column ] == card + 1 + (player * 5)) { printf( "%5s of %-8s\n", wFace[column], wSuit[row]); hands[player][card] = (int)((column) + (row * FACES)); } } } } printf("\n"); //Spacer if(straight(hands[player], wFace) == 1){ printf("> [You have a striaght]\n\n"); }else if(flush(hands[player], wSuit) == 1){ printf("> [You have flush]\n\n"); }else if(fourOfAKind(hands[player], wFace) == 1){ printf("> [You have four of a kind]\n\n"); }else if(threeOfAKind(hands[player], wFace) == 1){ printf("> [You have three of a kind]\n\n"); }else if(twoPair(hands[player], wFace) == 1){ printf("> [You have two pairs]\n\n"); }else if(onePair(hands[player], wFace) == 1){ printf("> [You have a pair]\n\n"); }else{ printf("> [You have nothing]\n\n"); } } }