diff --git a/src/poker/round/winner.c b/src/poker/round/winner.c index e358f203..ee829fbf 100644 --- a/src/poker/round/winner.c +++ b/src/poker/round/winner.c @@ -25,6 +25,18 @@ void pokerWinnerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards){ cardHandSort(cards, poker->cardsFacing+player->cardCount); } +void pokerWinnerFillRemaining(winning_t *winning) { + uint8_t i; + int32_t index; + + for(i = winning->count; i < POKER_WINNING_SET_SIZE; i++) { + if(arrayContains(sizeof(int32_t),winning->set,winning->count,&i)) continue; + winning->set[winning->count++] = i; + } + + arraySortInt32(winning->set, winning->count); +} + winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { winning_t winning; uint8_t i, j, l; @@ -41,15 +53,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { winning.count = 0; winning.type = 0x00; for(i = 0; i < POKER_WINNING_SET_SIZE; i++) winning.set[i] = -1; - - // TESTING HAND - winning.full[0] = CARD_CLUBS_ACE; - 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; //////////////////////// Now look for the winning set //////////////////////// @@ -80,11 +83,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { number == CARD_ACE ? POKER_WINNING_TYPE_ROYAL_FLUSH : POKER_WINNING_TYPE_STRAIGHT_FLUSH ); - if(winning.type == POKER_WINNING_TYPE_ROYAL_FLUSH) { - printf("Royal Flush\n"); - } else { - printf("Straight Flush\n"); - } return winning; } @@ -99,7 +97,7 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { winning.count = pairCount; arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set); winning.type = POKER_WINNING_TYPE_FOUR_OF_A_KIND; - printf("Four of a kind\n"); + pokerWinnerFillRemaining(&winning); return winning; } @@ -138,7 +136,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { if(winning.count < POKER_WINNING_SET_SIZE) continue; winning.set[0] = i; winning.type = POKER_WINNING_TYPE_FLUSH; - printf("Flush\n"); return winning; } @@ -162,7 +159,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { if(winning.count < POKER_WINNING_SET_SIZE) continue; winning.set[0] = i; winning.type = POKER_WINNING_TYPE_STRAIGHT; - printf("Flush\n"); return winning; } @@ -177,7 +173,7 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { 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"); + pokerWinnerFillRemaining(&winning); return winning; } @@ -197,22 +193,22 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) { if(winning.count != 4) continue; winning.type = POKER_WINNING_TYPE_TWO_PAIR; - printf("Two Pair\n"); + pokerWinnerFillRemaining(&winning); return winning; } // Pair if(winning.count == 2) { winning.type = POKER_WINNING_TYPE_PAIR; - printf("One Pair\n"); + pokerWinnerFillRemaining(&winning); return winning; } // High card - winning.count = POKER_WINNING_SET_SIZE; + winning.count = 0; + pokerWinnerFillRemaining(&winning); winning.type = POKER_WINNNIG_TYPE_HIGH_CARD; - arrayCopy(sizeof(int32_t), winning.full, POKER_WINNING_SET_SIZE, winning.set); - + return winning; } @@ -229,6 +225,7 @@ void pokerWinnerInit(poker_t *poker) { if(!pokerPlayerIsAlive(player)) continue; // Get the players' full hand - pokerWinnerGetStatus(poker, player); + winning_t winning = pokerWinnerGetStatus(poker, player); + printf("Winning state %u\n", winning.type); } } \ No newline at end of file diff --git a/src/poker/round/winner.h b/src/poker/round/winner.h index c606d98e..6d81566e 100644 --- a/src/poker/round/winner.h +++ b/src/poker/round/winner.h @@ -35,5 +35,6 @@ typedef struct { void pokerWinnerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards); +void pokerWinnerFillRemaining(winning_t *winning); winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player); void pokerWinnerInit(poker_t *poker); \ No newline at end of file