Fixed winner hand filling

This commit is contained in:
2021-06-24 13:50:19 -07:00
parent 2ba4dc2901
commit 58dbfc65dd
2 changed files with 22 additions and 24 deletions

View File

@ -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);
}
}

View File

@ -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);