Fixed winner hand filling
This commit is contained in:
@ -25,6 +25,18 @@ void pokerWinnerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards){
|
|||||||
cardHandSort(cards, poker->cardsFacing+player->cardCount);
|
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 pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
||||||
winning_t winning;
|
winning_t winning;
|
||||||
uint8_t i, j, l;
|
uint8_t i, j, l;
|
||||||
@ -41,15 +53,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
|||||||
winning.count = 0;
|
winning.count = 0;
|
||||||
winning.type = 0x00;
|
winning.type = 0x00;
|
||||||
for(i = 0; i < POKER_WINNING_SET_SIZE; i++) winning.set[i] = -1;
|
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 ////////////////////////
|
//////////////////////// 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 :
|
number == CARD_ACE ? POKER_WINNING_TYPE_ROYAL_FLUSH :
|
||||||
POKER_WINNING_TYPE_STRAIGHT_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;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +97,7 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
|||||||
winning.count = pairCount;
|
winning.count = pairCount;
|
||||||
arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set);
|
arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set);
|
||||||
winning.type = POKER_WINNING_TYPE_FOUR_OF_A_KIND;
|
winning.type = POKER_WINNING_TYPE_FOUR_OF_A_KIND;
|
||||||
printf("Four of a kind\n");
|
pokerWinnerFillRemaining(&winning);
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +136,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
|||||||
if(winning.count < POKER_WINNING_SET_SIZE) continue;
|
if(winning.count < POKER_WINNING_SET_SIZE) continue;
|
||||||
winning.set[0] = i;
|
winning.set[0] = i;
|
||||||
winning.type = POKER_WINNING_TYPE_FLUSH;
|
winning.type = POKER_WINNING_TYPE_FLUSH;
|
||||||
printf("Flush\n");
|
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +159,6 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
|||||||
if(winning.count < POKER_WINNING_SET_SIZE) continue;
|
if(winning.count < POKER_WINNING_SET_SIZE) continue;
|
||||||
winning.set[0] = i;
|
winning.set[0] = i;
|
||||||
winning.type = POKER_WINNING_TYPE_STRAIGHT;
|
winning.type = POKER_WINNING_TYPE_STRAIGHT;
|
||||||
printf("Flush\n");
|
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +173,7 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
|||||||
winning.count = pairCount;
|
winning.count = pairCount;
|
||||||
arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set);
|
arrayCopy(sizeof(int32_t), pairs, pairCount, winning.set);
|
||||||
winning.type = POKER_WINNING_TYPE_THREE_OF_A_KIND;
|
winning.type = POKER_WINNING_TYPE_THREE_OF_A_KIND;
|
||||||
printf("Three of a kind\n");
|
pokerWinnerFillRemaining(&winning);
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,22 +193,22 @@ winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player) {
|
|||||||
if(winning.count != 4) continue;
|
if(winning.count != 4) continue;
|
||||||
|
|
||||||
winning.type = POKER_WINNING_TYPE_TWO_PAIR;
|
winning.type = POKER_WINNING_TYPE_TWO_PAIR;
|
||||||
printf("Two Pair\n");
|
pokerWinnerFillRemaining(&winning);
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pair
|
// Pair
|
||||||
if(winning.count == 2) {
|
if(winning.count == 2) {
|
||||||
winning.type = POKER_WINNING_TYPE_PAIR;
|
winning.type = POKER_WINNING_TYPE_PAIR;
|
||||||
printf("One Pair\n");
|
pokerWinnerFillRemaining(&winning);
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
// High card
|
// High card
|
||||||
winning.count = POKER_WINNING_SET_SIZE;
|
winning.count = 0;
|
||||||
|
pokerWinnerFillRemaining(&winning);
|
||||||
winning.type = POKER_WINNNIG_TYPE_HIGH_CARD;
|
winning.type = POKER_WINNNIG_TYPE_HIGH_CARD;
|
||||||
arrayCopy(sizeof(int32_t), winning.full, POKER_WINNING_SET_SIZE, winning.set);
|
|
||||||
|
|
||||||
return winning;
|
return winning;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +225,7 @@ void pokerWinnerInit(poker_t *poker) {
|
|||||||
if(!pokerPlayerIsAlive(player)) continue;
|
if(!pokerPlayerIsAlive(player)) continue;
|
||||||
|
|
||||||
// Get the players' full hand
|
// Get the players' full hand
|
||||||
pokerWinnerGetStatus(poker, player);
|
winning_t winning = pokerWinnerGetStatus(poker, player);
|
||||||
|
printf("Winning state %u\n", winning.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,5 +35,6 @@ typedef struct {
|
|||||||
|
|
||||||
|
|
||||||
void pokerWinnerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards);
|
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);
|
winning_t pokerWinnerGetStatus(poker_t *poker, pokerplayer_t *player);
|
||||||
void pokerWinnerInit(poker_t *poker);
|
void pokerWinnerInit(poker_t *poker);
|
Reference in New Issue
Block a user