Fixed some poker bugs.
This commit is contained in:
@ -427,6 +427,7 @@ void pokerWinnerGetForPlayer(
|
|||||||
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
|
if(winning->setSize < POKER_WINNING_SET_SIZE) continue;
|
||||||
winning->set[0] = winning->full[i];
|
winning->set[0] = winning->full[i];
|
||||||
winning->type = POKER_WINNING_TYPE_STRAIGHT;
|
winning->type = POKER_WINNING_TYPE_STRAIGHT;
|
||||||
|
debug_WinnerFillRemaining(winning);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,7 +459,7 @@ void pokerWinnerGetForPlayer(
|
|||||||
if(pairCount != 2) continue;
|
if(pairCount != 2) continue;
|
||||||
|
|
||||||
for(j = 0; j < pairCount; j++) {
|
for(j = 0; j < pairCount; j++) {
|
||||||
winning->set[j] = winning->full[winning->setSize + pairs[j]];
|
winning->set[winning->setSize+j] = winning->full[pairs[j]];
|
||||||
}
|
}
|
||||||
// arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set+winning->setSize);
|
// arrayCopy(sizeof(int32_t), pairs, pairCount, winning->set+winning->setSize);
|
||||||
winning->setSize += pairCount;
|
winning->setSize += pairCount;
|
||||||
|
@ -1036,6 +1036,209 @@ void test_pokerWinnerGetForPlayer_should_CalculateTwoPair(void) {
|
|||||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[4]);
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGetForPlayer_should_CalculateThreeOfAKind(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_ACE;
|
||||||
|
poker.community[1] = CARD_CLUBS_THREE;
|
||||||
|
poker.community[2] = CARD_SPADES_TWO;
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_SIX;
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_CLUBS_TWO;
|
||||||
|
player->cards[1] = CARD_DIAMONDS_TWO;
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_THREE_OF_A_KIND, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGetForPlayer_should_CalculateAStraight(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_ACE;//0 - 3
|
||||||
|
poker.community[1] = CARD_CLUBS_THREE;//2 - 1
|
||||||
|
poker.community[2] = CARD_SPADES_THREE;//Hmm?
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_FOUR;//3 - 4
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_CLUBS_TWO;//1 - 0
|
||||||
|
player->cards[1] = CARD_DIAMONDS_FIVE;//4 - 2
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_STRAIGHT, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_THREE, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_FIVE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_FOUR, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGetForPlayer_should_CalculateAFlush(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_ACE;
|
||||||
|
poker.community[1] = CARD_SPADES_SIX;
|
||||||
|
poker.community[2] = CARD_SPADES_THREE;
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_NINE;
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_SPADES_TWO;
|
||||||
|
player->cards[1] = CARD_SPADES_KING;
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FLUSH, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGet_should_CalculateFullHouse(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_ACE;
|
||||||
|
poker.community[1] = CARD_SPADES_SIX;
|
||||||
|
poker.community[2] = CARD_SPADES_THREE;
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_NINE;
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_SPADES_TWO;
|
||||||
|
player->cards[1] = CARD_SPADES_KING;
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FULL_HOUSE, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGetForPlayer_should_CalculateFourOfAKind(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_ACE;
|
||||||
|
poker.community[1] = CARD_SPADES_SIX;
|
||||||
|
poker.community[2] = CARD_SPADES_THREE;
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_NINE;
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_SPADES_TWO;
|
||||||
|
player->cards[1] = CARD_SPADES_KING;
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FOUR_OF_A_KIND, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGetForPlayer_should_CalculateStraightFlush(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_ACE;
|
||||||
|
poker.community[1] = CARD_SPADES_SIX;
|
||||||
|
poker.community[2] = CARD_SPADES_THREE;
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_NINE;
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_SPADES_TWO;
|
||||||
|
player->cards[1] = CARD_SPADES_KING;
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_STRAIGHT_FLUSH, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush(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_ACE;
|
||||||
|
poker.community[1] = CARD_SPADES_SIX;
|
||||||
|
poker.community[2] = CARD_SPADES_THREE;
|
||||||
|
poker.community[3] = CARD_SPADES_QUEEN;
|
||||||
|
poker.community[4] = CARD_HEARTS_NINE;
|
||||||
|
player->cardCount = 2;
|
||||||
|
player->cards[0] = CARD_SPADES_TWO;
|
||||||
|
player->cards[1] = CARD_SPADES_KING;
|
||||||
|
|
||||||
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_ROYAL_FLUSH, winning.type);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_TWO, winning.set[0]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, winning.set[1]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, winning.set[2]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[3]);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
||||||
|
}
|
||||||
|
|
||||||
int test_poker2() {
|
int test_poker2() {
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
|
||||||
@ -1079,6 +1282,11 @@ int test_poker2() {
|
|||||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateHighCard);
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateHighCard);
|
||||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculatePair);
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculatePair);
|
||||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateTwoPair);
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateTwoPair);
|
||||||
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateThreeOfAKind);
|
||||||
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateAStraight);
|
||||||
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateAFlush);
|
||||||
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateFourOfAKind);
|
||||||
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush);
|
||||||
|
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
Reference in New Issue
Block a user