diff --git a/src/poker/round/winner.c b/src/poker/round/winner.c index 839c468e..e358f203 100644 --- a/src/poker/round/winner.c +++ b/src/poker/round/winner.c @@ -44,9 +44,9 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { // TESTING HAND winning.full[0] = CARD_CLUBS_ACE; - winning.full[1] = CARD_SPADES_TWO; - winning.full[2] = CARD_DIAMONDS_THREE; - winning.full[3] = CARD_HEARTS_FOUR; + winning.full[1] = CARD_SPADES_THREE; + winning.full[2] = CARD_DIAMONDS_TWO; + winning.full[3] = CARD_HEARTS_TWO; winning.full[4] = CARD_SPADES_FIVE; winning.full[5] = CARD_CLUBS_QUEEN; winning.full[6] = CARD_CLUBS_JACK; @@ -168,14 +168,50 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { // Three of a kind winning.count = 0; + for(i = 0; i < winning.size; i++) { + card = winning.full[i]; + number = cardGetNumber(card); + pairCount = cardCountPairs(winning.full, winning.size, number, pairs); + if(pairCount != 3) continue; + + winning.count = pairCount; + arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set); + winning.type = POKER_WINNING_TYPE_THREE_OF_A_KIND; + printf("Three of a kind\n"); + return winning; + } // Two Pair winning.count = 0; + for(i = 0; i < winning.size; i++) { + index = i;// Check we haven't already added this card. + if(arrayContains(sizeof(int32_t),winning.set,winning.count,&index))continue; + + card = winning.full[i]; + number = cardGetNumber(card); + pairCount = cardCountPairs(winning.full, winning.size, number, pairs); + if(pairCount != 2) continue; + + arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set+winning.count); + winning.count += pairCount; + if(winning.count != 4) continue; + + winning.type = POKER_WINNING_TYPE_TWO_PAIR; + printf("Two Pair\n"); + return winning; + } // Pair - winning.count = 0; + if(winning.count == 2) { + winning.type = POKER_WINNING_TYPE_PAIR; + printf("One Pair\n"); + return winning; + } // High card + winning.count = POKER_WINNING_SET_SIZE; + winning.type = POKER_WINNNIG_TYPE_HIGH_CARD; + arrayCopy(sizeof(int32_t), winning.full, POKER_WINNING_SET_SIZE, winning.set); return winning; } diff --git a/src/poker/round/winner.h b/src/poker/round/winner.h index 64469ca1..c606d98e 100644 --- a/src/poker/round/winner.h +++ b/src/poker/round/winner.h @@ -14,8 +14,12 @@ #define POKER_WINNING_TYPE_STRAIGHT_FLUSH 0x02 #define POKER_WINNING_TYPE_FOUR_OF_A_KIND 0x03 #define POKER_WINNING_TYPE_FULL_HOUSE 0x04 -#define POKER_WINNING_TYPE_FLUSH 0x06 +#define POKER_WINNING_TYPE_FLUSH 0x05 #define POKER_WINNING_TYPE_STRAIGHT 0x06 +#define POKER_WINNING_TYPE_THREE_OF_A_KIND 0x07 +#define POKER_WINNING_TYPE_TWO_PAIR 0x08 +#define POKER_WINNING_TYPE_PAIR 0x09 +#define POKER_WINNNIG_TYPE_HIGH_CARD 0x0A #define POKER_WINNING_SET_SIZE 5