Added additional tests.

This commit is contained in:
2021-10-05 00:10:09 -07:00
parent a9a7d40df8
commit 189da04c8f
6 changed files with 551 additions and 10 deletions

View File

@ -58,10 +58,9 @@ uint8_t cardCountPairs(card_t *in, uint8_t inCount, uint8_t number,
int32_t out[CARD_SUIT_COUNT]
) {
uint8_t i, count;
int32_t index;
count = 0;
for(i = 0; i <= inCount; i++) {// "For each suit"
for(i = 0; i < inCount; i++) {// "For each suit"
if(cardGetNumber(in[i]) != number) continue;
out[count++] = i;
}
@ -77,4 +76,23 @@ uint8_t cardWriteDeck(card_t *hand) {
uint8_t i;
for(i = 0; i < CARD_DECK_SIZE; i++) hand[i] = i;
return CARD_DECK_SIZE;
}
card_t cardGetHighestCard(card_t *cards, uint8_t cardCount) {
uint8_t i, number, bestNumber;
card_t card, bestCard;
bestNumber = 0xFF;
for(i = 0; i < cardCount; i++) {
card = cards[i];
number = cardGetNumber(card);
if(number == CARD_ACE) return card;
if(bestNumber != 0xFF && number <= bestNumber) continue;
bestCard = card;
bestNumber = number;
}
return bestCard;
}

View File

@ -202,4 +202,13 @@ void cardShuffle(card_t *hand, uint8_t length);
* @param hand Hand to write the deck to.
* @return The count of cards in the deck.
*/
uint8_t cardWriteDeck(card_t *hand);
uint8_t cardWriteDeck(card_t *hand);
/**
* Get the highest card from a hand of cards.
*
* @param cards Array of cards.
* @param cardCount Length of the array.
* @return The highest card in the array.
*/
card_t cardGetHighestCard(card_t *cards, uint8_t cardCount);

View File

@ -169,7 +169,6 @@ bool pokerPlayerDoesNeedToBetThisRound(poker2_t *poker, uint8_t playerIndex) {
uint8_t pokerPlayerGetRemainingBetter(poker2_t *poker) {
uint8_t i, j;
poker2player_t *player;
for(i = 0; i < poker->playerCount; i++) {
j = (i + poker->playerBigBlind + 1) % poker->playerCount;
@ -180,7 +179,6 @@ uint8_t pokerPlayerGetRemainingBetter(poker2_t *poker) {
uint8_t pokerPlayerGetNextBetter(poker2_t *poker, uint8_t current) {
uint8_t i, j;
poker2player_t *player;
for(i = 0; i < poker->playerCount; i++) {
j = (i + current + 1) % poker->playerCount;
@ -212,6 +210,10 @@ void pokerPlayerBet(poker2_t *poker, uint8_t playerIndex, int32_t chips) {
);
}
bool pokerPlayerCanCheck(poker2_t *poker, poker2player_t *player) {
return pokerGetCallValue(poker) <= player->currentBet;
}
poker2turn_t pokerTurnFold(poker2_t *poker, uint8_t player) {
return (poker2turn_t){
.chips = 0,
@ -244,4 +246,240 @@ poker2turn_t pokerTurnBet(poker2_t *poker, uint8_t playerIndex, int32_t chips) {
}
return turn;
}
// Winning
void pokerHandGetFull(
poker2_t *poker, poker2player_t *player, card_t cards[POKER_WINNING_FULL_SIZE]
) {
uint8_t i;
// Add the dealer hand
for(i = 0; i < poker->communitySize; i++) {
cards[i] = poker->community[i];
}
// Add the player hand
for(i = 0; i < player->cardCount; i++) {
cards[i+poker->communitySize] = player->cards[i];
}
}
void debug_WinnerFillRemaining(poker2playerwinning_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;
}
}
if(highest == 0xFF) break;
winning->set[winning->setSize++] = highestCard;
}
cardHandSort(winning->set, winning->setSize);
}
void pokerWinnerGetForPlayer(
poker2_t *poker, poker2player_t *player, poker2playerwinning_t *winning
) {
uint8_t i, j, l;
int32_t index;
card_t card;
uint8_t number, suit, pairCount;
int32_t pairs[CARD_SUIT_COUNT];
// Get the full poker hand (should be a 7 card hand, but MAY not be)
winning->fullSize = poker->communitySize + player->cardCount;
pokerHandGetFull(poker, player, winning->full);
cardHandSort(winning->full, winning->fullSize);
// Reset the winning status.
winning->setSize = 0;
//////////////////////// Now look for the winning set ////////////////////////
// Royal / Straight Flush
for(i = 0; i < winning->fullSize; i++) {
card = winning->full[i];
number = cardGetNumber(card);
if(number < CARD_FIVE) continue;
suit = cardGetSuit(card);
winning->setSize = 1;
// Now look for the matching cards (Reverse order to order from A to 10)
for(j = 1; j <= 4; j++) {
l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
index = cardContains(winning->full, winning->fullSize, cardGet(l, suit));
if(index == -1) break;
winning->set[j] = winning->full[index];
winning->setSize++;
}
// Check if has all necessary cards.
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
// Add self to array
winning->set[0] = winning->full[i];
winning->type = (
number == CARD_ACE ? POKER_WINNING_TYPE_ROYAL_FLUSH :
POKER_WINNING_TYPE_STRAIGHT_FLUSH
);
return;
}
// Four of a kind.
winning->setSize = 0;
for(i = 0; i < winning->fullSize; i++) {
card = winning->full[i];
number = cardGetNumber(card);
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
if(pairCount < CARD_SUIT_COUNT) continue;
winning->setSize = pairCount;
for(j = 0; j < pairCount; j++) winning->set[j] = winning->full[pairs[j]];
winning->type = POKER_WINNING_TYPE_FOUR_OF_A_KIND;
debug_WinnerFillRemaining(winning);
return;
}
// Full House
winning->setSize = 0;
for(i = 0; i < winning->fullSize; i++) {
// Check we haven't already added this card.
card = winning->full[i];
if(cardContains(winning->set, winning->setSize, card) != -1) continue;
number = cardGetNumber(card);
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
// Did we find either two pair or three pair?
if(pairCount != 2 && pairCount != 3) continue;
if(winning->setSize == 3) pairCount = 2;//Clamp to 5 max.
// Copy found pairs.
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;
printf("Full House\n");
return;
}
// Flush (5 same suit)
for(i = 0; i < winning->fullSize; i++) {
card = winning->full[i];
suit = cardGetSuit(card);
winning->setSize = 1;
for(j = i+1; j < winning->fullSize; j++) {
if(cardGetSuit(winning->full[j]) != suit) continue;
winning->set[winning->setSize] = winning->full[j];
winning->setSize++;
if(winning->setSize == POKER_WINNING_SET_SIZE) break;
}
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
winning->set[0] = winning->full[0];
winning->type = POKER_WINNING_TYPE_FLUSH;
return;
}
// Straight (sequence any suit)
winning->setSize = 0;
for(i = 0; i < winning->fullSize; i++) {
card = winning->full[i];
number = cardGetNumber(card);
if(number < CARD_FIVE) continue;
winning->setSize = 1;
for(j = 1; j <= 4; j++) {
l = number == CARD_FIVE && j == 4 ? CARD_ACE : number - j;//Ace low.
index = cardContainsNumber(winning->full, winning->fullSize, l);
if(index == -1) break;
winning->set[j] = winning->full[index];
winning->setSize++;
}
// Check if has all necessary cards.
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
winning->set[0] = winning->full[i];
winning->type = POKER_WINNING_TYPE_STRAIGHT;
return;
}
// Three of a kind
winning->setSize = 0;
for(i = 0; i < winning->fullSize; i++) {
card = winning->full[i];
number = cardGetNumber(card);
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
if(pairCount != 3) continue;
winning->setSize = pairCount;
for(j = 0; j < pairCount; j++) winning->set[j] = winning->full[pairs[j]];
winning->type = POKER_WINNING_TYPE_THREE_OF_A_KIND;
debug_WinnerFillRemaining(winning);
return;
}
// Two Pair
winning->setSize = 0;
for(i = 0; i < winning->fullSize; i++) {
card = winning->full[i];// Check we haven't already added this card.
if(cardContains(winning->set, winning->setSize, card) != -1) {
continue;
}
number = cardGetNumber(card);
pairCount = cardCountPairs(winning->full, winning->fullSize, number, pairs);
if(pairCount != 2) continue;
for(j = 0; j < pairCount; j++) {
winning->set[j] = winning->full[winning->setSize + pairs[j]];
}
// 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;
debug_WinnerFillRemaining(winning);
return;
}
// Pair
if(winning->setSize == 2) {
winning->type = POKER_WINNING_TYPE_PAIR;
debug_WinnerFillRemaining(winning);
return;
}
// High card
winning->setSize = 0;
debug_WinnerFillRemaining(winning);
winning->type = POKER_WINNING_TYPE_HIGH_CARD;
return;
}

View File

@ -31,6 +31,36 @@
#define POKER_TURN_TYPE_CALL_ALL_IN 0x04
#define POKER_TURN_TYPE_CHECK 0x05
#define POKER_WINNING_FULL_SIZE (\
POKER_PLAYER_HAND_SIZE_MAX+POKER_COMMUNITY_SIZE_MAX\
)
#define POKER_WINNING_SET_SIZE 5
#define POKER_WINNING_TYPE_NULL 0x00
#define POKER_WINNING_TYPE_ROYAL_FLUSH 0x01
#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 0x05
#define POKER_WINNING_TYPE_STRAIGHT 0x06
#define POKER_WINNING_TYPE_THREE_OF_A_KIND 0x07
#define POKER_WINNING_TYPE_TWO_PAIR 0x08
#define POKER_WINNING_TYPE_PAIR 0x09
#define POKER_WINNING_TYPE_HIGH_CARD 0x0A
#define POKER_WINNING_CONFIDENCE_ROYAL_FLUSH 1.0f
#define POKER_WINNING_CONFIDENCE_STRAIGHT_FLUSH 0.99f
#define POKER_WINNING_CONFIDENCE_FOUR_OF_A_KIND 0.9f
#define POKER_WINNING_CONFIDENCE_FULL_HOUSE 0.85f
#define POKER_WINNING_CONFIDENCE_FLUSH 0.8f
#define POKER_WINNING_CONFIDENCE_STRAIGHT 0.7f
#define POKER_WINNING_CONFIDENCE_THREE_OF_A_KIND 0.5f
#define POKER_WINNING_CONFIDENCE_TWO_PAIR 0.4f
#define POKER_WINNING_CONFIDENCE_PAIR 0.2f
#define POKER_WINNING_CONFIDENCE_HIGH_CARD 0.1f
typedef struct {
int32_t chips;
card_t cards[POKER_PLAYER_HAND_SIZE_MAX];
@ -39,6 +69,23 @@ typedef struct {
int32_t currentBet;
} poker2player_t;
/** Holds information about a player's winning state */
typedef struct {
/** The full set of both the dealer and player's hand */
card_t full[POKER_WINNING_FULL_SIZE];
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;
} poker2playerwinning_t;
typedef struct {
int32_t chips;
uint8_t players[POKER_PLAYER_COUNT_MAX];
@ -102,9 +149,13 @@ void pokerPlayerBetPot(
poker2_t *poker, poker2pot_t *pot, uint8_t playerIndex, int32_t chips
);
void pokerPlayerBet(poker2_t *poker, uint8_t playerIndex, int32_t chips);
bool pokerPlayerCanCheck(poker2_t *poker, poker2player_t *player);
poker2turn_t pokerTurnFold(poker2_t *poker, uint8_t player);
poker2turn_t pokerTurnBet(poker2_t *poker, uint8_t playerIndex, int32_t chips);
poker2turn_t pokerTurnFold(poker2_t *poker, uint8_t player);
poker2turn_t pokerTurnBet(poker2_t *poker, uint8_t playerIndex, int32_t chips);
void pokerHandGetFull(
poker2_t *poker, poker2player_t *player, card_t cards[POKER_WINNING_FULL_SIZE]
);
void debug_WinnerFillRemaining(poker2playerwinning_t *winning);
void pokerWinnerGetForPlayer(
poker2_t *poker, poker2player_t *player, poker2playerwinning_t *winning
);

View File

@ -238,6 +238,37 @@ void test_cardWriteDeck_should_ReturnCardsWritten(void) {
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, cardWriteDeck(cards));
}
void test_cardGetHighestCard_should_ReturnTheHighestCard(void) {
card_t cards[CARD_DECK_SIZE];
uint8_t l = cardWriteDeck(cards);
TEST_ASSERT_EQUAL(CARD_CLUBS_ACE, cardGetHighestCard(cards, l));
TEST_ASSERT_EQUAL(CARD_CLUBS_ACE, cardGetHighestCard(cards, l));
l = 3;
TEST_ASSERT_EQUAL(CARD_CLUBS_FOUR, cardGetHighestCard(cards, l));
cards[0] = CARD_CLUBS_SIX;
cards[1] = CARD_HEARTS_SEVEN;
cards[2] = CARD_DIAMONDS_EIGHT;
cards[3] = CARD_SPADES_NINE;
l = 4;
TEST_ASSERT_EQUAL(CARD_SPADES_NINE, cardGetHighestCard(cards, l));
cards[2] = CARD_DIAMONDS_TEN;
TEST_ASSERT_EQUAL(CARD_DIAMONDS_TEN, cardGetHighestCard(cards, l));
cards[2] = CARD_DIAMONDS_TEN;
TEST_ASSERT_EQUAL(CARD_DIAMONDS_TEN, cardGetHighestCard(cards, l));
cards[4] = CARD_CLUBS_TEN;
l = 5;
TEST_ASSERT_EQUAL(CARD_DIAMONDS_TEN, cardGetHighestCard(cards, l));
cards[1] = CARD_HEARTS_TEN;
TEST_ASSERT_EQUAL(CARD_HEARTS_TEN, cardGetHighestCard(cards, l));
}
int test_card() {
UNITY_BEGIN();
@ -253,6 +284,7 @@ int test_card() {
RUN_TEST(test_cardCountPairs_should_CountPairs);
RUN_TEST(test_cardWriteDeck_should_WriteCardsToArray);
RUN_TEST(test_cardWriteDeck_should_ReturnCardsWritten);
RUN_TEST(test_cardGetHighestCard_should_ReturnTheHighestCard);
return UNITY_END();
}

View File

@ -736,6 +736,44 @@ void test_pokerPlayerBet_should_BetToTheActivePot(void) {
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
}
void test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet(void) {
poker2_t poker;
uint8_t p0, p1, p2;
pokerInit(&poker);
p0 = pokerPlayerAdd(&poker);
p1 = pokerPlayerAdd(&poker);
p2 = pokerPlayerAdd(&poker);
pokerPlayerChipsAdd(poker.players + p0, 1000);
pokerPlayerChipsAdd(poker.players + p1, 1000);
pokerPlayerChipsAdd(poker.players + p2, 1000);
pokerPlayerBet(&poker, p0, 100);
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p1));
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p2));
pokerPlayerBet(&poker, p1, 100);
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p2));
pokerPlayerBet(&poker, p2, 100);
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p0));
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
pokerPlayerBet(&poker, p2, 100);
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p0));
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p1));
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
pokerPlayerBet(&poker, p1, 100);
TEST_ASSERT_EQUAL(false, pokerPlayerCanCheck(&poker, poker.players+p0));
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p1));
TEST_ASSERT_EQUAL(true, pokerPlayerCanCheck(&poker, poker.players+p2));
}
void test_pokerTurnFold_should_ReturnAFoldAction(void) {
poker2_t poker;
poker2turn_t turn;
@ -818,6 +856,157 @@ void test_pokerTurnBet_should_ReturnARaiseAction(void) {
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
}
void test_pokerHandGetFull_should_ReturnTheFullHand(void) {
poker2_t poker;
poker2player_t *player;
uint8_t i;
card_t cards[POKER_WINNING_FULL_SIZE];
pokerInit(&poker);
i = pokerPlayerAdd(&poker);
player = poker.players + i;
pokerPlayerDeal(&poker, player, POKER_PLAYER_HAND_SIZE_MAX);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, player->cards[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, player->cards[1]);
pokerTurn(&poker, POKER_COMMUNITY_SIZE_MAX);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.community[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.community[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, poker.community[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, poker.community[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, poker.community[4]);
pokerHandGetFull(&poker, player, cards);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, cards[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, cards[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, cards[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, cards[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[4]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, cards[5]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, cards[6]);
poker.community[0] = CARD_CLUBS_THREE;
poker.community[1] = CARD_DIAMONDS_TWO;
poker.community[2] = CARD_SPADES_EIGHT;
poker.community[3] = CARD_DIAMONDS_ACE;
poker.community[4] = CARD_SPADES_FIVE;
player->cards[0] = CARD_DIAMONDS_KING;
player->cards[1] = CARD_HEARTS_QUEEN;
pokerHandGetFull(&poker, player, cards);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_THREE, cards[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, cards[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_ACE, cards[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_FIVE, cards[4]);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_KING, cards[5]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_QUEEN, cards[6]);
}
void test_pokerWinnerFillRemaining_should_FillTheRestOfTheArray(void) {
poker2playerwinning_t winning;
winning.fullSize = 7;
winning.full[0] = CARD_CLUBS_ACE;
winning.full[1] = CARD_CLUBS_TWO;
winning.full[2] = CARD_CLUBS_THREE;
winning.full[3] = CARD_CLUBS_FOUR;
winning.full[4] = CARD_CLUBS_FIVE;
winning.full[5] = CARD_CLUBS_SIX;
winning.full[6] = CARD_CLUBS_SEVEN;
cardHandSort(winning.full, 7);
winning.setSize = 1;
winning.set[0] = CARD_CLUBS_ACE;
debug_WinnerFillRemaining(&winning);
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_SET_SIZE, winning.setSize);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_ACE, winning.set[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_SEVEN, winning.set[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_SIX, winning.set[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_FIVE, winning.set[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_FOUR, winning.set[4]);
}
void test_pokerWinnerGetForPlayer_should_CalculateHighCard(void) {
poker2_t poker;
uint8_t i;
poker2player_t *player;
poker2playerwinning_t winning;
pokerInit(&poker);
i = pokerPlayerAdd(&poker);
player = poker.players + i;
poker.communitySize = 5;
poker.community[0] = CARD_HEARTS_QUEEN;
poker.community[1] = CARD_CLUBS_TWO;
poker.community[2] = CARD_DIAMONDS_ACE;
poker.community[3] = CARD_SPADES_NINE;
poker.community[4] = CARD_HEARTS_SIX;
player->cardCount = 2;
player->cards[0] = CARD_CLUBS_FOUR;
player->cards[1] = CARD_DIAMONDS_SEVEN;
pokerWinnerGetForPlayer(&poker, player, &winning);
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_FULL_SIZE, winning.fullSize);
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_HIGH_CARD, winning.type);
TEST_ASSERT_EQUAL_UINT8(0x05, winning.setSize);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_ACE, winning.set[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_SEVEN, winning.set[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_QUEEN, winning.set[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_SIX, winning.set[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, winning.set[4]);
}
void test_pokerWinnerGetForPlayer_should_CalculatePair(void) {
poker2_t poker;
uint8_t i;
poker2player_t *player;
poker2playerwinning_t winning;
pokerInit(&poker);
i = pokerPlayerAdd(&poker);
player = poker.players + i;
poker.communitySize = 5;
poker.community[0] = CARD_HEARTS_QUEEN;
poker.community[1] = CARD_CLUBS_TWO;
poker.community[2] = CARD_DIAMONDS_ACE;
poker.community[3] = CARD_SPADES_QUEEN;
poker.community[4] = CARD_HEARTS_SIX;
player->cardCount = 2;
player->cards[0] = CARD_CLUBS_FOUR;
player->cards[1] = CARD_DIAMONDS_SEVEN;
pokerWinnerGetForPlayer(&poker, player, &winning);
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_FULL_SIZE, winning.fullSize);
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winning.type);
TEST_ASSERT_EQUAL_UINT8(0x05, winning.setSize);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_ACE, winning.set[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_SEVEN, winning.set[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_QUEEN, winning.set[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_SIX, winning.set[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[4]);
poker.community[3] = CARD_SPADES_NINE;
player->cards[0] = CARD_HEARTS_TWO;
pokerWinnerGetForPlayer(&poker, player, &winning);
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winning.type);
TEST_ASSERT_EQUAL_UINT8(0x05, winning.setSize);
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_ACE, winning.set[1]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_QUEEN, winning.set[2]);
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_TWO, winning.set[3]);
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, winning.set[4]);
}
int test_poker() {
UNITY_BEGIN();
@ -850,12 +1039,16 @@ int test_poker() {
RUN_TEST(test_pokerPlayerBetPot_should_AddChipsToThePot);
RUN_TEST(test_pokerPlayerBetPot_should_UpdatePlayerState);
RUN_TEST(test_pokerPlayerBet_should_BetToTheActivePot);
RUN_TEST(test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet);
RUN_TEST(test_pokerTurnFold_should_ReturnAFoldAction);
RUN_TEST(test_pokerTurnBet_should_ReturnACheckAction);
RUN_TEST(test_pokerTurnBet_should_ReturnAnAllInAction);
RUN_TEST(test_pokerTurnBet_should_ReturnACallAction);
RUN_TEST(test_pokerTurnBet_should_ReturnARaiseAction);
RUN_TEST(test_pokerHandGetFull_should_ReturnTheFullHand);
RUN_TEST(test_pokerWinnerFillRemaining_should_FillTheRestOfTheArray);
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateHighCard);
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculatePair);
return UNITY_END();
}