Winner logic finished.
This commit is contained in:
@ -58,6 +58,7 @@
|
|||||||
#define POKER_RIVER_CARD_COUNT 1
|
#define POKER_RIVER_CARD_COUNT 1
|
||||||
|
|
||||||
/** Winning Types */
|
/** Winning Types */
|
||||||
|
#define POKER_WINNING_TYPE_NULL 0x00
|
||||||
#define POKER_WINNING_TYPE_ROYAL_FLUSH 0x01
|
#define POKER_WINNING_TYPE_ROYAL_FLUSH 0x01
|
||||||
#define POKER_WINNING_TYPE_STRAIGHT_FLUSH 0x02
|
#define POKER_WINNING_TYPE_STRAIGHT_FLUSH 0x02
|
||||||
#define POKER_WINNING_TYPE_FOUR_OF_A_KIND 0x03
|
#define POKER_WINNING_TYPE_FOUR_OF_A_KIND 0x03
|
||||||
@ -72,6 +73,22 @@
|
|||||||
/** How many cards make a winning set */
|
/** How many cards make a winning set */
|
||||||
#define POKER_WINNING_SET_SIZE 5
|
#define POKER_WINNING_SET_SIZE 5
|
||||||
|
|
||||||
|
/** Holds information about the winning player state */
|
||||||
|
typedef struct {
|
||||||
|
/** The full set of both the dealer and player's hand */
|
||||||
|
card_t full[POKER_PLAYER_HAND + POKER_DEALER_HAND];
|
||||||
|
uint8_t fullSize;
|
||||||
|
|
||||||
|
/** Holds the winning set */
|
||||||
|
card_t set[POKER_WINNING_SET_SIZE];
|
||||||
|
uint8_t setSize;
|
||||||
|
|
||||||
|
/** Winning Type */
|
||||||
|
uint8_t type;
|
||||||
|
|
||||||
|
/** If there was a kicker card it will be here, otherwise -1 for no kicker */
|
||||||
|
card_t kicker;
|
||||||
|
} pokerwinning_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
@ -96,6 +113,11 @@ typedef struct {
|
|||||||
/** Player States */
|
/** Player States */
|
||||||
pokerplayer_t players[POKER_PLAYER_COUNT];
|
pokerplayer_t players[POKER_PLAYER_COUNT];
|
||||||
|
|
||||||
|
/** Winning States */
|
||||||
|
pokerwinning_t winnings[POKER_PLAYER_COUNT];
|
||||||
|
uint8_t winners[POKER_PLAYER_COUNT];
|
||||||
|
uint8_t winnerCount;
|
||||||
|
|
||||||
/** The current round the game is on */
|
/** The current round the game is on */
|
||||||
uint8_t round;
|
uint8_t round;
|
||||||
|
|
||||||
@ -153,18 +175,4 @@ typedef struct {
|
|||||||
texture_t cardTexture;
|
texture_t cardTexture;
|
||||||
tileset_t cardTileset;
|
tileset_t cardTileset;
|
||||||
primitive_t cardPrimitive;
|
primitive_t cardPrimitive;
|
||||||
} poker_t;
|
} poker_t;
|
||||||
|
|
||||||
/** Holds information about the winning player state */
|
|
||||||
typedef struct {
|
|
||||||
/** The full set of both the dealer and player's hand */
|
|
||||||
card_t full[POKER_PLAYER_HAND + POKER_DEALER_HAND];
|
|
||||||
uint8_t size;
|
|
||||||
|
|
||||||
/** Holds the winning set */
|
|
||||||
int32_t set[POKER_WINNING_SET_SIZE];
|
|
||||||
uint8_t count;
|
|
||||||
|
|
||||||
/** Winning Type */
|
|
||||||
uint8_t type;
|
|
||||||
} pokerwinning_t;
|
|
@ -55,7 +55,7 @@ void pokerPlayerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards){
|
|||||||
cardHandSort(cards, poker->cardsFacing+player->cardCount);
|
cardHandSort(cards, poker->cardsFacing+player->cardCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
pokerwinning_t pokerPlayerGetWinning(
|
void pokerPlayerGetWinning(
|
||||||
poker_t *poker, pokerplayer_t *player, pokerwinning_t *winning
|
poker_t *poker, pokerplayer_t *player, pokerwinning_t *winning
|
||||||
) {
|
) {
|
||||||
uint8_t i, j, l;
|
uint8_t i, j, l;
|
||||||
@ -65,39 +65,37 @@ pokerwinning_t pokerPlayerGetWinning(
|
|||||||
int32_t pairs[CARD_SUIT_COUNT];
|
int32_t pairs[CARD_SUIT_COUNT];
|
||||||
|
|
||||||
// Get the full poker hand (should be a 7 card hand)
|
// Get the full poker hand (should be a 7 card hand)
|
||||||
winning->size = poker->cardsFacing + player->cardCount;
|
winning->fullSize = poker->cardsFacing + player->cardCount;
|
||||||
pokerPlayerGetFullHand(poker, player, winning->full);
|
pokerPlayerGetFullHand(poker, player, winning->full);
|
||||||
|
|
||||||
// Reset the winning status.
|
// Reset the winning status.
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
winning->type = 0x00;
|
|
||||||
for(i = 0; i < POKER_WINNING_SET_SIZE; i++) winning->set[i] = -1;
|
|
||||||
|
|
||||||
//////////////////////// Now look for the winning set ////////////////////////
|
//////////////////////// Now look for the winning set ////////////////////////
|
||||||
|
|
||||||
// Royal / Straight Flush
|
// Royal / Straight Flush
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
card = winning->full[i];
|
card = winning->full[i];
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
if(number < CARD_FIVE) continue;
|
if(number < CARD_FIVE) continue;
|
||||||
|
|
||||||
suit = cardGetSuit(card);
|
suit = cardGetSuit(card);
|
||||||
winning->count = 1;
|
winning->setSize = 1;
|
||||||
|
|
||||||
// Now look for the matching cards (Reverse order to order from A to 10)
|
// Now look for the matching cards (Reverse order to order from A to 10)
|
||||||
for(j = 1; j <= 4; j++) {
|
for(j = 1; j <= 4; j++) {
|
||||||
l = number == 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));
|
index = cardContains(winning->full, winning->fullSize, cardGet(l, suit));
|
||||||
if(index == -1) break;
|
if(index == -1) break;
|
||||||
winning->set[j] = index;
|
winning->set[j] = winning->full[index];
|
||||||
winning->count++;
|
winning->setSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if has all necessary cards.
|
// Check if has all necessary cards.
|
||||||
if(winning->count < POKER_WINNING_SET_SIZE) continue;
|
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
|
||||||
|
|
||||||
// Add self to array
|
// Add self to array
|
||||||
winning->set[0] = i;
|
winning->set[0] = winning->full[i];
|
||||||
winning->type = (
|
winning->type = (
|
||||||
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
|
||||||
@ -106,112 +104,120 @@ pokerwinning_t pokerPlayerGetWinning(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Four of a kind.
|
// Four of a kind.
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
card = winning->full[i];
|
card = winning->full[i];
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
pairCount = cardCountPairs(winning->full, winning->size, number, pairs);
|
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
|
||||||
if(pairCount < CARD_SUIT_COUNT) continue;
|
if(pairCount < CARD_SUIT_COUNT) continue;
|
||||||
|
|
||||||
winning->count = pairCount;
|
winning->setSize = pairCount;
|
||||||
arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set);
|
for(j = 0; j < pairCount; j++) winning->set[j] = winning->full[pairs[j]];
|
||||||
winning->type = POKER_WINNING_TYPE_FOUR_OF_A_KIND;
|
winning->type = POKER_WINNING_TYPE_FOUR_OF_A_KIND;
|
||||||
pokerPlayerWinningFillRemaining(winning);
|
pokerPlayerWinningFillRemaining(winning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Full House
|
// Full House
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
index = i;// Check we haven't already added this card.
|
// Check we haven't already added this card.
|
||||||
if(arrayContains(sizeof(int32_t),winning->set,winning->count,&index))continue;
|
|
||||||
|
|
||||||
card = winning->full[i];
|
card = winning->full[i];
|
||||||
|
if(cardContains(winning->set, winning->setSize, card) != -1) continue;
|
||||||
|
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
pairCount = cardCountPairs(winning->full, winning->size, number, pairs);
|
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
|
||||||
|
|
||||||
// Did we find either two pair or three pair?
|
// Did we find either two pair or three pair?
|
||||||
if(pairCount != 2 && pairCount != 3) continue;
|
if(pairCount != 2 && pairCount != 3) continue;
|
||||||
if(winning->count == 3) pairCount = 2;//Clamp to 5 max.
|
if(winning->setSize == 3) pairCount = 2;//Clamp to 5 max.
|
||||||
arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set+winning->count);
|
|
||||||
winning->count += pairCount;
|
// Copy found pairs.
|
||||||
if(winning->count != POKER_WINNING_SET_SIZE) continue;
|
for(j = 0; j < pairCount; j++) {
|
||||||
|
winning->set[winning->setSize + j] = winning->full[pairs[j]];
|
||||||
|
}
|
||||||
|
winning->setSize += pairCount;
|
||||||
|
|
||||||
|
// Winned?
|
||||||
|
if(winning->setSize != POKER_WINNING_SET_SIZE) continue;
|
||||||
winning->type = POKER_WINNING_TYPE_FULL_HOUSE;
|
winning->type = POKER_WINNING_TYPE_FULL_HOUSE;
|
||||||
printf("Full House\n");
|
printf("Full House\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush (5 same suit)
|
// Flush (5 same suit)
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
card = winning->full[i];
|
card = winning->full[i];
|
||||||
suit = cardGetSuit(card);
|
suit = cardGetSuit(card);
|
||||||
winning->count = 1;
|
winning->setSize = 1;
|
||||||
for(j = i+1; j < winning->size; j++) {
|
for(j = i+1; j < winning->fullSize; j++) {
|
||||||
if(cardGetSuit(winning->full[j]) != suit) continue;
|
if(cardGetSuit(winning->full[j]) != suit) continue;
|
||||||
winning->set[winning->count] = j;
|
winning->set[winning->setSize] = winning->full[j];
|
||||||
winning->count++;
|
winning->setSize++;
|
||||||
if(winning->count == POKER_WINNING_SET_SIZE) break;
|
if(winning->setSize == POKER_WINNING_SET_SIZE) break;
|
||||||
}
|
}
|
||||||
if(winning->count < POKER_WINNING_SET_SIZE) continue;
|
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
|
||||||
winning->set[0] = i;
|
winning->set[0] = winning->full[0];
|
||||||
winning->type = POKER_WINNING_TYPE_FLUSH;
|
winning->type = POKER_WINNING_TYPE_FLUSH;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Straight (sequence any suit)
|
// Straight (sequence any suit)
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
card = winning->full[i];
|
card = winning->full[i];
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
if(number < CARD_FIVE) continue;
|
if(number < CARD_FIVE) continue;
|
||||||
winning->count = 1;
|
winning->setSize = 1;
|
||||||
|
|
||||||
for(j = 1; j <= 4; j++) {
|
for(j = 1; j <= 4; j++) {
|
||||||
l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
|
l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
|
||||||
index = cardContainsNumber(winning->full, winning->size, l);
|
index = cardContainsNumber(winning->full, winning->fullSize, l);
|
||||||
if(index == -1) break;
|
if(index == -1) break;
|
||||||
winning->set[j] = index;
|
winning->set[j] = winning->full[index];
|
||||||
winning->count++;
|
winning->setSize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if has all necessary cards.
|
// Check if has all necessary cards.
|
||||||
if(winning->count < POKER_WINNING_SET_SIZE) continue;
|
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
|
||||||
winning->set[0] = i;
|
winning->set[0] = winning->full[i];
|
||||||
winning->type = POKER_WINNING_TYPE_STRAIGHT;
|
winning->type = POKER_WINNING_TYPE_STRAIGHT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Three of a kind
|
// Three of a kind
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
card = winning->full[i];
|
card = winning->full[i];
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
pairCount = cardCountPairs(winning->full, winning->size, number, pairs);
|
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
|
||||||
if(pairCount != 3) continue;
|
if(pairCount != 3) continue;
|
||||||
|
|
||||||
winning->count = pairCount;
|
winning->setSize = pairCount;
|
||||||
arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set);
|
for(j = 0; j < pairCount; j++) winning->set[j] = winning->full[pairs[j]];
|
||||||
winning->type = POKER_WINNING_TYPE_THREE_OF_A_KIND;
|
winning->type = POKER_WINNING_TYPE_THREE_OF_A_KIND;
|
||||||
pokerPlayerWinningFillRemaining(winning);
|
pokerPlayerWinningFillRemaining(winning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Two Pair
|
// Two Pair
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
for(i = 0; i < winning->size; i++) {
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
index = i;// Check we haven't already added this card.
|
card = winning->full[i];// Check we haven't already added this card.
|
||||||
if(arrayContains(sizeof(int32_t), winning->set, winning->count, &index)) {
|
if(cardContains(winning->set, winning->setSize, card) != -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
card = winning->full[i];
|
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
pairCount = cardCountPairs(winning->full, winning->size, number, pairs);
|
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
|
||||||
if(pairCount != 2) continue;
|
if(pairCount != 2) continue;
|
||||||
|
|
||||||
arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set+winning->count);
|
for(j = 0; j < pairCount; j++) {
|
||||||
winning->count += pairCount;
|
winning->set[j] = winning->full[winning->setSize + pairs[j]];
|
||||||
if(winning->count != 4) continue;
|
}
|
||||||
|
// arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set+winning->setSize);
|
||||||
|
winning->setSize += pairCount;
|
||||||
|
if(winning->setSize != 4) continue;
|
||||||
|
|
||||||
winning->type = POKER_WINNING_TYPE_TWO_PAIR;
|
winning->type = POKER_WINNING_TYPE_TWO_PAIR;
|
||||||
pokerPlayerWinningFillRemaining(winning);
|
pokerPlayerWinningFillRemaining(winning);
|
||||||
@ -219,28 +225,91 @@ pokerwinning_t pokerPlayerGetWinning(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pair
|
// Pair
|
||||||
if(winning->count == 2) {
|
if(winning->setSize == 2) {
|
||||||
winning->type = POKER_WINNING_TYPE_PAIR;
|
winning->type = POKER_WINNING_TYPE_PAIR;
|
||||||
pokerPlayerWinningFillRemaining(winning);
|
pokerPlayerWinningFillRemaining(winning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// High card
|
// High card
|
||||||
winning->count = 0;
|
winning->setSize = 0;
|
||||||
pokerPlayerWinningFillRemaining(winning);
|
pokerPlayerWinningFillRemaining(winning);
|
||||||
winning->type = POKER_WINNNIG_TYPE_HIGH_CARD;
|
winning->type = POKER_WINNNIG_TYPE_HIGH_CARD;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pokerPlayerWinningFillRemaining(pokerwinning_t *winning) {
|
|
||||||
uint8_t i;
|
card_t pokerPlayerCompareWinning(pokerwinning_t *left, pokerwinning_t *right) {
|
||||||
|
uint8_t i, number;
|
||||||
|
card_t card;
|
||||||
int32_t index;
|
int32_t index;
|
||||||
|
|
||||||
for(i = winning->count; i < POKER_WINNING_SET_SIZE; i++) {
|
card_t highCardLeft, highCardRight;
|
||||||
if(arrayContains(sizeof(int32_t),winning->set,winning->count,&i)) continue;
|
uint8_t highNumberLeft, highNumberRight;
|
||||||
winning->set[winning->count++] = i;
|
|
||||||
|
highNumberLeft = 0xFF;
|
||||||
|
highNumberRight = 0xFF;
|
||||||
|
|
||||||
|
for(i = 0; i < left->setSize; i++) {
|
||||||
|
card = left->set[i];
|
||||||
|
number = cardGetNumber(card);
|
||||||
|
if(highNumberLeft != 0xFF && number < highNumberLeft) continue;// Quick check
|
||||||
|
index = cardContainsNumber(right->set, right->setSize, number);
|
||||||
|
if(index != -1) continue;// In other?
|
||||||
|
|
||||||
|
if(highNumberLeft == 0xFF||number == CARD_ACE||highNumberRight < number) {
|
||||||
|
highNumberLeft = number;
|
||||||
|
highCardLeft = card;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < right->setSize; i++) {
|
||||||
|
card = right->set[i];
|
||||||
|
number = cardGetNumber(card);
|
||||||
|
if(highNumberRight != 0xFF && number < highNumberRight) continue;
|
||||||
|
index = cardContainsNumber(left->set, left->setSize, number);
|
||||||
|
if(index != -1) continue;
|
||||||
|
|
||||||
|
if(highNumberRight == 0xFF||number == CARD_ACE||highNumberRight < number) {
|
||||||
|
highNumberRight = number;
|
||||||
|
highCardRight = card;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arraySortInt32(winning->set, winning->count);
|
if(highNumberLeft < highNumberRight) return 0xFF;
|
||||||
|
return highCardLeft;//Greater or Equal to.
|
||||||
|
}
|
||||||
|
|
||||||
|
void pokerPlayerWinningFillRemaining(pokerwinning_t *winning) {
|
||||||
|
uint8_t i, highest, current;
|
||||||
|
card_t highestCard, currentCard;
|
||||||
|
|
||||||
|
// Set the kicker
|
||||||
|
winning->kicker = 0xFF;
|
||||||
|
|
||||||
|
// Fill the remaining cards
|
||||||
|
while(winning->setSize < POKER_WINNING_SET_SIZE) {
|
||||||
|
highest = 0xFF;
|
||||||
|
|
||||||
|
for(i = 0; i < winning->fullSize; i++) {
|
||||||
|
currentCard = winning->full[i];
|
||||||
|
if(cardContains(winning->set, winning->setSize, currentCard) != -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(highest == 0xFF) {
|
||||||
|
highestCard = currentCard;
|
||||||
|
highest = cardGetNumber(highestCard);
|
||||||
|
} else {
|
||||||
|
current = cardGetNumber(currentCard);
|
||||||
|
if(current != CARD_ACE && current < highest) continue;
|
||||||
|
highestCard = currentCard;
|
||||||
|
highest = current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
winning->set[winning->setSize++] = highestCard;
|
||||||
|
}
|
||||||
|
cardHandSort(winning->set, winning->setSize);
|
||||||
}
|
}
|
@ -69,10 +69,20 @@ void pokerPlayerGetFullHand(poker_t *poker,pokerplayer_t *player,card_t *cards);
|
|||||||
* @param winning Pointer to the poker winning to fill out.
|
* @param winning Pointer to the poker winning to fill out.
|
||||||
* @return The winning state for this player.
|
* @return The winning state for this player.
|
||||||
*/
|
*/
|
||||||
pokerwinning_t pokerPlayerGetWinning(
|
void pokerPlayerGetWinning(
|
||||||
poker_t *poker, pokerplayer_t *player, pokerwinning_t *winning
|
poker_t *poker, pokerplayer_t *player, pokerwinning_t *winning
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two winning sets. The returned card is the kicker if the LEFT side
|
||||||
|
* is the winner. If LEFT is not a winner then 0xFF will be returned.
|
||||||
|
*
|
||||||
|
* @param left Left winning set.
|
||||||
|
* @param right Right winning set.
|
||||||
|
* @return The kicker card from left's hand or 0xFF if left is not the winner.
|
||||||
|
*/
|
||||||
|
card_t pokerPlayerCompareWinning(pokerwinning_t *left, pokerwinning_t *right);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the remaining cards for a given poker player winning hand.
|
* Fills the remaining cards for a given poker player winning hand.
|
||||||
* @param winning Pointer to the poker winning to fill out.
|
* @param winning Pointer to the poker winning to fill out.
|
||||||
|
@ -14,7 +14,6 @@ void pokerDealInit(poker_t *poker) {
|
|||||||
|
|
||||||
// Shuffle the deck
|
// Shuffle the deck
|
||||||
arrayShuffle(sizeof(card_t), poker->deck, CARD_DECK_SIZE);
|
arrayShuffle(sizeof(card_t), poker->deck, CARD_DECK_SIZE);
|
||||||
arrayShuffle(sizeof(card_t), poker->deck, CARD_DECK_SIZE);
|
|
||||||
|
|
||||||
// Deal 2 card to each player
|
// Deal 2 card to each player
|
||||||
pokerPlayerDealAll(poker, POKER_DEAL_CARD_EACH);
|
pokerPlayerDealAll(poker, POKER_DEAL_CARD_EACH);
|
||||||
|
@ -4,25 +4,77 @@
|
|||||||
* This software is released under the MIT License.
|
* This software is released under the MIT License.
|
||||||
* https://opensource.org/licenses/MIT
|
* https://opensource.org/licenses/MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include "winner.h"
|
#include "winner.h"
|
||||||
|
|
||||||
|
int32_t _pokerWinnersSorter(void *left, void* right) {
|
||||||
|
return ((pokerwinning_t *)right)->type - ((pokerwinning_t *)left)->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pokerWinnersSort(pokerwinning_t *winnings, int32_t length) {
|
||||||
|
arraySort(sizeof(pokerwinning_t),
|
||||||
|
winnings, length, (arraysort_t *)&_pokerWinnersSorter
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void pokerWinnerInit(poker_t *poker) {
|
void pokerWinnerInit(poker_t *poker) {
|
||||||
uint8_t winners[POKER_PLAYER_COUNT];
|
uint8_t i, j, number, highNumber;
|
||||||
uint8_t i, winnerCount;
|
pokerwinning_t *left, *right;
|
||||||
pokerwinning_t winning;
|
pokerplayer_t *player;
|
||||||
|
card_t card, highCard;
|
||||||
|
bool winner;
|
||||||
|
|
||||||
poker->round = POKER_ROUND_WINNER;
|
poker->winnerCount = 0;
|
||||||
printf("Winner Winner Chicken Dinner\n");
|
|
||||||
|
|
||||||
// Kill me
|
|
||||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||||
pokerplayer_t *player = poker->players + i;
|
left = poker->winnings + i;
|
||||||
|
left->type = POKER_WINNING_TYPE_NULL;
|
||||||
|
player = poker->players + i;
|
||||||
if(!pokerPlayerIsAlive(player)) continue;
|
if(!pokerPlayerIsAlive(player)) continue;
|
||||||
|
|
||||||
// Get the players' full hand
|
// Get the players' full hand.
|
||||||
pokerPlayerGetWinning(poker, player, &winning);
|
pokerPlayerGetWinning(poker, player, left);
|
||||||
printf("Winning state %u\n", winning.type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||||
|
left = poker->winnings + i;
|
||||||
|
if(left->type == POKER_WINNING_TYPE_NULL) continue;
|
||||||
|
|
||||||
|
winner = true;
|
||||||
|
highNumber = 0xFF;
|
||||||
|
|
||||||
|
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
|
||||||
|
if(i == j) continue;
|
||||||
|
|
||||||
|
right = poker->winnings + j;
|
||||||
|
if(right->type == POKER_WINNING_TYPE_NULL) continue;
|
||||||
|
|
||||||
|
// Am I the better hand?
|
||||||
|
if(left->type < right->type) continue;
|
||||||
|
if(left->type > right->type) {
|
||||||
|
// No
|
||||||
|
winner = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equal, compare hands.
|
||||||
|
card = pokerPlayerCompareWinning(left, right);
|
||||||
|
if(card == 0xFF) {
|
||||||
|
winner = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
number = cardGetNumber(card);
|
||||||
|
if(highNumber == 0xFF || number == CARD_ACE || number > highNumber) {
|
||||||
|
highCard = card;
|
||||||
|
highNumber = number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!winner) continue;
|
||||||
|
left->kicker = highCard;
|
||||||
|
poker->winners[poker->winnerCount++] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Winner Count %u\n", poker->winnerCount);
|
||||||
}
|
}
|
@ -9,4 +9,6 @@
|
|||||||
#include <dawn/dawn.h>
|
#include <dawn/dawn.h>
|
||||||
#include "../player.h"
|
#include "../player.h"
|
||||||
|
|
||||||
|
int32_t _pokerWinnersSorter(void *left, void* right);
|
||||||
|
void pokerWinnersSort(pokerwinning_t *winnings, int32_t length);
|
||||||
void pokerWinnerInit(poker_t *poker);
|
void pokerWinnerInit(poker_t *poker);
|
Reference in New Issue
Block a user