From 78f773c1143b7b1d8e198ec471a994bd53e07f79 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 23 Jun 2021 19:40:36 -0700 Subject: [PATCH] Added straight. --- src/poker/round/winner.c | 37 +++++++++++++++++++++++++++++-------- src/poker/round/winner.h | 2 ++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/poker/round/winner.c b/src/poker/round/winner.c index 86eaf05e..839c468e 100644 --- a/src/poker/round/winner.c +++ b/src/poker/round/winner.c @@ -44,10 +44,10 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { // TESTING HAND winning.full[0] = CARD_CLUBS_ACE; - winning.full[1] = CARD_CLUBS_TWO; - winning.full[2] = CARD_CLUBS_FIVE; - winning.full[3] = CARD_DIAMONDS_THREE; - winning.full[4] = CARD_SPADES_TWO; + winning.full[1] = CARD_SPADES_TWO; + winning.full[2] = CARD_DIAMONDS_THREE; + winning.full[3] = CARD_HEARTS_FOUR; + winning.full[4] = CARD_SPADES_FIVE; winning.full[5] = CARD_CLUBS_QUEEN; winning.full[6] = CARD_CLUBS_JACK; @@ -64,7 +64,7 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { // Now look for the matching cards (Reverse order to order from A to 10) for(j = 1; j <= 4; j++) { - l = card == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low. + l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low. index = cardContains(winning.full, winning.size, cardGet(l, suit)); if(index == -1) break; winning.set[j] = index; @@ -128,7 +128,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { for(i = 0; i < winning.size; i++) { card = winning.full[i]; suit = cardGetSuit(card); - winning.set[0] = i; winning.count = 1; for(j = i+1; j < winning.size; j++) { if(cardGetSuit(winning.full[j]) != suit) continue; @@ -137,13 +136,35 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { if(winning.count == POKER_WINNING_SET_SIZE) break; } if(winning.count < POKER_WINNING_SET_SIZE) continue; - winning.type = POKER_WINNING_TYPE_FOUR_OF_A_KIND; - printf("Four of a kind\n"); + winning.set[0] = i; + winning.type = POKER_WINNING_TYPE_FLUSH; + printf("Flush\n"); return winning; } // Straight (sequence any suit) winning.count = 0; + for(i = 0; i < winning.size; i++) { + card = winning.full[i]; + number = cardGetNumber(card); + if(number < CARD_FIVE) continue; + winning.count = 1; + + for(j = 1; j <= 4; j++) { + l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low. + index = cardContainsNumber(winning.full, winning.size, l); + if(index == -1) break; + winning.set[j] = index; + winning.count++; + } + + // Check if has all necessary cards. + if(winning.count < POKER_WINNING_SET_SIZE) continue; + winning.set[0] = i; + winning.type = POKER_WINNING_TYPE_STRAIGHT; + printf("Flush\n"); + return winning; + } // Three of a kind winning.count = 0; diff --git a/src/poker/round/winner.h b/src/poker/round/winner.h index 97270301..64469ca1 100644 --- a/src/poker/round/winner.h +++ b/src/poker/round/winner.h @@ -14,6 +14,8 @@ #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_STRAIGHT 0x06 #define POKER_WINNING_SET_SIZE 5