1555 lines
54 KiB
C
1555 lines
54 KiB
C
/**
|
|
* Copyright (c) 2021 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "poker.h"
|
|
|
|
void test_pokerInit_should_InitializePokerGame(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
|
}
|
|
|
|
void test_pokerResetRound_should_ResetTheRound(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
poker.potCount = 0x03;
|
|
poker.graveSize = 0x10;
|
|
poker.communitySize = 0x03;
|
|
poker.deckSize = 0x0;
|
|
|
|
pokerResetRound(&poker);
|
|
|
|
TEST_ASSERT_NOT_EQUAL_UINT8(0, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.graveSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.communitySize);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.potCount);
|
|
}
|
|
|
|
void test_pokerResetRound_should_ResetThePlayers(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
|
|
|
|
for(i = 0; i < poker.playerCount; i++) {
|
|
poker.players[i].cardCount = 32;
|
|
poker.players[i].chips = 100;
|
|
poker.players[i].state = 0xFF;
|
|
poker.players[i].currentBet = 12345;
|
|
};
|
|
|
|
pokerResetRound(&poker);
|
|
|
|
for(i = 0; i < poker.playerCount; i++) {
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[i].cardCount);
|
|
TEST_ASSERT_EQUAL_INT32(0, poker.players[i].currentBet);
|
|
TEST_ASSERT_EQUAL_INT32(100, poker.players[i].chips);
|
|
TEST_ASSERT_EQUAL_INT32(100, poker.players[i].chips);
|
|
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_FOLDED, poker.players[i].state);
|
|
TEST_ASSERT_BITS_LOW(
|
|
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, poker.players[i].state
|
|
);
|
|
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_SHOWING, poker.players[i].state);
|
|
}
|
|
}
|
|
|
|
void test_pokerResetBettingRound_should_ResetTheBettingRound(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
|
|
pokerInit(&poker);
|
|
poker.better = 0x32;
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
|
|
|
|
for(i = 0; i < poker.playerCount; i++) {
|
|
pokerPlayerChipsAdd(poker.players + i, 1000);
|
|
};
|
|
|
|
pokerResetBettingRound(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, poker.better);
|
|
|
|
for(i = 0; i < poker.playerCount; i++) {
|
|
TEST_ASSERT_BITS_LOW(
|
|
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, poker.players[i].state
|
|
);
|
|
}
|
|
}
|
|
|
|
void test_pokerNewDealer_should_FindANewDealer(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerBigBlind);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(4, poker.playerBigBlind);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(4, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(4, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
|
}
|
|
|
|
void test_pokerNewDealer_should_SkipOutPlayers(void) {
|
|
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerAdd(&poker);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerBigBlind);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerBigBlind);
|
|
|
|
pokerNewDealer(&poker);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerDealer);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerSmallBlind);
|
|
TEST_ASSERT_EQUAL_UINT8(3, poker.playerBigBlind);
|
|
}
|
|
|
|
void test_pokerTakeBlinds_should_TakeTheBlinds(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
|
|
pokerNewDealer(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 0)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 1)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 2)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 3)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 4)->chips);
|
|
|
|
pokerTakeBlinds(&poker, 100, 200);
|
|
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 0)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 1)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(900, (poker.players + 2)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(800, (poker.players + 3)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 4)->chips);
|
|
|
|
pokerNewDealer(&poker);
|
|
pokerTakeBlinds(&poker, 100, 200);
|
|
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 0)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 1)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(900, (poker.players + 2)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(700, (poker.players + 3)->chips);
|
|
TEST_ASSERT_EQUAL_INT32(800, (poker.players + 4)->chips);
|
|
}
|
|
|
|
void test_pokerPotAdd_should_AddAPot(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.potCount);
|
|
TEST_ASSERT_EQUAL_UINT8(1, pokerPotAdd(&poker));
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.potCount);
|
|
}
|
|
|
|
void test_pokerPotAdd_should_ResetThePot(void) {
|
|
poker_t poker;
|
|
pokerpot_t *pot;
|
|
uint8_t i;
|
|
pokerInit(&poker);
|
|
|
|
i = pokerPotAdd(&poker);
|
|
pot = poker.pots + i;
|
|
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
|
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
|
}
|
|
|
|
void test_pokerPotAddPlayer_should_AddAPlayer(void) {
|
|
poker_t poker;
|
|
pokerpot_t *pot;
|
|
|
|
pokerInit(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
|
|
pot = poker.pots + 0;
|
|
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
|
|
|
pokerPotAddPlayer(pot, 1);
|
|
TEST_ASSERT_EQUAL_UINT8(1, pot->playerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, pot->players[0]);
|
|
|
|
pokerPotAddPlayer(pot, 0);
|
|
TEST_ASSERT_EQUAL_UINT8(2, pot->playerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, pot->players[1]);
|
|
}
|
|
|
|
void test_pokerPlayerAdd_should_AddAPlayer(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.playerCount);
|
|
TEST_ASSERT_EQUAL(0, pokerPlayerAdd(&poker));
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.playerCount);
|
|
TEST_ASSERT_EQUAL(1, pokerPlayerAdd(&poker));
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.playerCount);
|
|
}
|
|
|
|
void test_pokerPlayerAdd_should_ResetThePlayer(void) {
|
|
poker_t poker;
|
|
pokerplayer_t *player;
|
|
pokerInit(&poker);
|
|
|
|
player = poker.players + pokerPlayerAdd(&poker);
|
|
TEST_ASSERT_EQUAL_INT32(0, player->chips);
|
|
TEST_ASSERT_EQUAL_INT32(0, player->currentBet);
|
|
TEST_ASSERT_EQUAL_UINT8(0, player->cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_PLAYER_STATE_OUT, player->state);
|
|
}
|
|
|
|
void test_pokerTurn_should_TurnCardsFromTheDeck(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.communitySize);
|
|
|
|
pokerTurn(&poker, 1);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 1, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.communitySize);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.community[0]);
|
|
|
|
pokerTurn(&poker, 3);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 4, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(4, poker.communitySize);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.community[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.community[2]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.community[3]);
|
|
}
|
|
|
|
void test_pokerBurn_should_SendCardsToTheGrave(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.graveSize);
|
|
|
|
pokerBurn(&poker, 1);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 1, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.graveSize);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.grave[0]);
|
|
|
|
pokerBurn(&poker, 3);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 4, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(4, poker.graveSize);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.grave[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.grave[2]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.grave[3]);
|
|
|
|
}
|
|
|
|
void test_pokerGetCallValue_should_CalculateTheCallValue(void) {
|
|
poker_t poker;
|
|
uint8_t first, second;
|
|
pokerInit(&poker);
|
|
first = pokerPlayerAdd(&poker);
|
|
second = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + first, 10000);
|
|
pokerPlayerChipsAdd(poker.players + second, 10000);
|
|
|
|
TEST_ASSERT_EQUAL_INT32(0, pokerGetCallValue(&poker));
|
|
pokerPlayerBet(&poker, first, 100);
|
|
TEST_ASSERT_EQUAL_INT32(100, pokerGetCallValue(&poker));
|
|
pokerPlayerBet(&poker, second, 150);
|
|
TEST_ASSERT_EQUAL_INT32(150, pokerGetCallValue(&poker));
|
|
|
|
pokerPotAdd(&poker);
|
|
TEST_ASSERT_EQUAL_INT32(150, pokerGetCallValue(&poker));
|
|
TEST_ASSERT_EQUAL_INT32(0, poker.pots[1].chips);
|
|
pokerPlayerBet(&poker, second, 50);
|
|
TEST_ASSERT_EQUAL_INT32(200, pokerGetCallValue(&poker));
|
|
TEST_ASSERT_EQUAL_INT32(50, poker.pots[1].chips);
|
|
}
|
|
|
|
void test_pokerGetCallValue_should_SkipOutPlayers(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerInit(&poker);
|
|
|
|
i = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + i, 10000);
|
|
pokerPlayerBet(&poker, i, 300);
|
|
|
|
i = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + i, 10000);
|
|
pokerPlayerBet(&poker, i, 500);
|
|
|
|
i = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + i, 10000);
|
|
pokerPlayerBet(&poker, i, 200);
|
|
|
|
TEST_ASSERT_EQUAL_INT32(500, pokerGetCallValue(&poker));
|
|
poker.players[1].state |= POKER_PLAYER_STATE_OUT;
|
|
TEST_ASSERT_EQUAL_INT32(300, pokerGetCallValue(&poker));
|
|
poker.players[0].state |= POKER_PLAYER_STATE_OUT;
|
|
TEST_ASSERT_EQUAL_INT32(200, pokerGetCallValue(&poker));
|
|
}
|
|
|
|
void test_pokerPlayerDeal_should_DealCardsToThePlayer(void) {
|
|
poker_t poker;
|
|
uint8_t playerIndex;
|
|
pokerplayer_t *player;
|
|
|
|
pokerInit(&poker);
|
|
|
|
playerIndex = pokerPlayerAdd(&poker);
|
|
player = poker.players + playerIndex;
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, player->cardCount);
|
|
|
|
pokerPlayerDeal(&poker, player, 0x01);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 1, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(1, player->cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, player->cards[0]);
|
|
|
|
pokerPlayerDeal(&poker, player, 0x01);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 2, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(2, player->cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, player->cards[1]);
|
|
}
|
|
|
|
void test_pokerPlayerChipsAdd_should_AddChipsToThePlayer(void) {
|
|
poker_t poker;
|
|
uint8_t playerIndex;
|
|
pokerplayer_t *player;
|
|
|
|
pokerInit(&poker);
|
|
playerIndex = pokerPlayerAdd(&poker);
|
|
player = poker.players + playerIndex;
|
|
|
|
TEST_ASSERT_EQUAL_INT32(0, player->chips);
|
|
pokerPlayerChipsAdd(player, 32);
|
|
TEST_ASSERT_EQUAL_INT32(32, player->chips);
|
|
pokerPlayerChipsAdd(player, 10);
|
|
TEST_ASSERT_EQUAL_INT32(42, player->chips);
|
|
pokerPlayerChipsAdd(player, -30);
|
|
TEST_ASSERT_EQUAL_INT32(12, player->chips);
|
|
}
|
|
|
|
void test_pokerPlayerChipsAdd_should_TurnOutStateOff(void) {
|
|
poker_t poker;
|
|
uint8_t playerIndex;
|
|
pokerplayer_t *player;
|
|
|
|
pokerInit(&poker);
|
|
playerIndex = pokerPlayerAdd(&poker);
|
|
player = poker.players + playerIndex;
|
|
|
|
player->state |= POKER_PLAYER_STATE_OUT;
|
|
TEST_ASSERT_BITS_HIGH(POKER_PLAYER_STATE_OUT, player->state);
|
|
pokerPlayerChipsAdd(player, 32);
|
|
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_OUT, player->state);
|
|
}
|
|
|
|
void test_pokerPlayerDealAll_should_DealCardsToEveryone(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[0].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[1].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[2].cardCount);
|
|
|
|
pokerPlayerDealAll(&poker, 1);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE - 3, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.players[0].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.players[1].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(1, poker.players[2].cardCount);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.players[0].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.players[1].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.players[2].cards[0]);
|
|
}
|
|
|
|
void test_pokerPlayerDealAll_should_DealMultipleCardsToEveryone(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[0].cardCount);
|
|
|
|
pokerPlayerDealAll(&poker, 0x02);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[0].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[1].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[2].cardCount);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.players[0].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.players[1].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.players[2].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.players[0].cards[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, poker.players[1].cards[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, poker.players[2].cards[1]);
|
|
}
|
|
|
|
void test_pokerPlayerDealAll_should_NotDealToOutPlayers(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_DECK_SIZE, poker.deckSize);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[0].cardCount);
|
|
|
|
pokerPlayerDealAll(&poker, 0x02);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[0].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[1].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[2].cardCount);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.players[0].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.players[2].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.players[0].cards[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.players[2].cards[1]);
|
|
}
|
|
|
|
void test_pokerPlayerDealAll_should_NotDealToFoldedPlayers(void) {
|
|
poker_t poker;
|
|
pokerInit(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 100);
|
|
poker.players[0].state |= POKER_PLAYER_STATE_FOLDED;
|
|
|
|
pokerPlayerDealAll(&poker, 2);
|
|
TEST_ASSERT_EQUAL_UINT8(0, poker.players[0].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[1].cardCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, poker.players[2].cardCount);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, poker.players[1].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, poker.players[2].cards[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, poker.players[1].cards[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.players[2].cards[1]);
|
|
}
|
|
|
|
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue(void) {
|
|
poker_t poker;
|
|
uint8_t first, second;
|
|
|
|
pokerInit(&poker);
|
|
|
|
first = pokerPlayerAdd(&poker);
|
|
second = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + first, 10000);
|
|
pokerPlayerChipsAdd(poker.players + second, 10000);
|
|
|
|
pokerPlayerBet(&poker, first, 100);
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
pokerPlayerBet(&poker, second, 200);
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
pokerPlayerBet(&poker, first, 100);
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
}
|
|
|
|
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet(void) {
|
|
poker_t poker;
|
|
uint8_t first, second;
|
|
pokerInit(&poker);
|
|
first = pokerPlayerAdd(&poker);
|
|
second = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + first, 10000);
|
|
pokerPlayerChipsAdd(poker.players + second, 10000);
|
|
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
pokerPlayerBet(&poker, first, 100);
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
pokerPlayerBet(&poker, second, 100);
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
}
|
|
|
|
void test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers(void) {
|
|
poker_t poker;
|
|
uint8_t first, second;
|
|
pokerInit(&poker);
|
|
first = pokerPlayerAdd(&poker);
|
|
second = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players + first, 10000);
|
|
pokerPlayerChipsAdd(poker.players + second, 10000);
|
|
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
pokerPlayerBet(&poker, first, 100);
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(true, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
poker.players[second].state |= POKER_PLAYER_STATE_FOLDED;
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
|
|
pokerPlayerBet(&poker, first, 100);
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, first));
|
|
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
|
}
|
|
|
|
void test_pokerPlayerGetRemainingBetter_should_ReturnRemainingBetters(void) {
|
|
poker_t poker;
|
|
uint8_t p0, p1, p2, p3, p4;
|
|
pokerInit(&poker);
|
|
|
|
|
|
p0 = pokerPlayerAdd(&poker);
|
|
p1 = pokerPlayerAdd(&poker);
|
|
p2 = pokerPlayerAdd(&poker);
|
|
p3 = pokerPlayerAdd(&poker);
|
|
p4 = pokerPlayerAdd(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p3, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p4, 10000);
|
|
pokerNewDealer(&poker);
|
|
|
|
// Blind + 1
|
|
TEST_ASSERT_EQUAL(0x04, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// Blind + 2
|
|
pokerPlayerBet(&poker, 0x04, pokerGetCallValue(&poker));
|
|
TEST_ASSERT_EQUAL(0x00, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// Blind + 3
|
|
pokerPlayerBet(&poker, 0x00, pokerGetCallValue(&poker));
|
|
TEST_ASSERT_EQUAL(0x01, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// Blind + 4 / Small Blind
|
|
pokerPlayerBet(&poker, 0x01, pokerGetCallValue(&poker));
|
|
TEST_ASSERT_EQUAL(0x02, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// Blind + 5 / Big Blind
|
|
pokerPlayerBet(
|
|
&poker, 0x02, pokerGetCallValue(&poker) - poker.players[0x01].currentBet
|
|
);
|
|
TEST_ASSERT_EQUAL(0x03, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// No remaining players.
|
|
pokerPlayerBet(&poker, 0x03, 0);
|
|
TEST_ASSERT_EQUAL(0xFF, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// Raise
|
|
pokerPlayerBet(&poker, 0x03, 100);
|
|
TEST_ASSERT_EQUAL(0x04, pokerPlayerGetRemainingBetter(&poker));
|
|
|
|
// Raise
|
|
pokerPlayerBet(&poker, 0x04, 100);
|
|
TEST_ASSERT_EQUAL(0x00, pokerPlayerGetRemainingBetter(&poker));
|
|
}
|
|
|
|
void test_pokerPlayerGetNextBetter_should_GetTheNextBetter(void) {
|
|
poker_t poker;
|
|
uint8_t p0, p1, p2, p3, p4;
|
|
uint8_t better;
|
|
pokerInit(&poker);
|
|
|
|
p0 = pokerPlayerAdd(&poker);
|
|
p1 = pokerPlayerAdd(&poker);
|
|
p2 = pokerPlayerAdd(&poker);
|
|
p3 = pokerPlayerAdd(&poker);
|
|
p4 = pokerPlayerAdd(&poker);
|
|
|
|
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p3, 10000);
|
|
pokerPlayerChipsAdd(poker.players + p4, 10000);
|
|
pokerNewDealer(&poker);
|
|
|
|
// Start at blind+1
|
|
better = poker.playerBigBlind;
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x04, better);
|
|
|
|
// Blind+2
|
|
pokerPlayerBet(&poker, better, pokerGetCallValue(&poker));
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, better);
|
|
|
|
// BLind+3
|
|
pokerPlayerBet(&poker, better, pokerGetCallValue(&poker));
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, better);
|
|
|
|
// Dealer
|
|
pokerPlayerBet(&poker, better, pokerGetCallValue(&poker));
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x02, better);
|
|
|
|
// Small blind
|
|
pokerPlayerBet(
|
|
&poker, better, pokerGetCallValue(&poker) - poker.players[0x02].currentBet
|
|
);
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x03, better);
|
|
|
|
// Big Blind
|
|
pokerPlayerBet(
|
|
&poker, better, pokerGetCallValue(&poker) - poker.players[0x03].currentBet
|
|
);
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0xFF, better);
|
|
|
|
// Raise
|
|
better = poker.playerBigBlind;
|
|
pokerPlayerBet(&poker, better, 100);
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x04, better);
|
|
|
|
// Raise
|
|
pokerPlayerBet(&poker, better, 100);
|
|
better = pokerPlayerGetNextBetter(&poker, better);
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, better);
|
|
}
|
|
|
|
void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
|
|
poker_t poker;
|
|
uint8_t p0, p1, p2;
|
|
|
|
pokerInit(&poker);
|
|
p0 = pokerPlayerAdd(&poker);
|
|
p1 = pokerPlayerAdd(&poker);
|
|
p2 = pokerPlayerAdd(&poker);
|
|
|
|
pokerPlayerBet(&poker, p0, 100);
|
|
TEST_ASSERT_EQUAL_INT32(0, pokerPlayerGetCallBet(&poker,poker.players+p0));
|
|
TEST_ASSERT_EQUAL_INT32(100, pokerPlayerGetCallBet(&poker,poker.players+p1));
|
|
TEST_ASSERT_EQUAL_INT32(100, pokerPlayerGetCallBet(&poker,poker.players+p2));
|
|
|
|
pokerPlayerBet(&poker, p1, 200);
|
|
TEST_ASSERT_EQUAL_INT32(100, pokerPlayerGetCallBet(&poker,poker.players+p0));
|
|
TEST_ASSERT_EQUAL_INT32(0, pokerPlayerGetCallBet(&poker,poker.players+p1));
|
|
TEST_ASSERT_EQUAL_INT32(200, pokerPlayerGetCallBet(&poker,poker.players+p2));
|
|
|
|
pokerPlayerBet(&poker, p2, 300);
|
|
TEST_ASSERT_EQUAL_INT32(200, pokerPlayerGetCallBet(&poker,poker.players+p0));
|
|
TEST_ASSERT_EQUAL_INT32(100, pokerPlayerGetCallBet(&poker,poker.players+p1));
|
|
TEST_ASSERT_EQUAL_INT32(0, pokerPlayerGetCallBet(&poker,poker.players+p2));
|
|
}
|
|
|
|
void test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound(void) {
|
|
poker_t poker;
|
|
uint8_t p0, p1, p2;
|
|
|
|
pokerInit(&poker);
|
|
p0 = pokerPlayerAdd(&poker);
|
|
p1 = pokerPlayerAdd(&poker);
|
|
p2 = pokerPlayerAdd(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker));
|
|
|
|
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, pokerInRoundGetCount(&poker));
|
|
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
|
TEST_ASSERT_EQUAL_UINT8(0x02, pokerInRoundGetCount(&poker));
|
|
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
|
TEST_ASSERT_EQUAL_UINT8(0x03, pokerInRoundGetCount(&poker));
|
|
|
|
poker.players[0].state |= POKER_PLAYER_STATE_FOLDED;
|
|
TEST_ASSERT_EQUAL_UINT8(0x02, pokerInRoundGetCount(&poker));
|
|
poker.players[1].state |= POKER_PLAYER_STATE_FOLDED;
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, pokerInRoundGetCount(&poker));
|
|
poker.players[2].state |= POKER_PLAYER_STATE_OUT;
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker));
|
|
}
|
|
|
|
void test_pokerPlayerGetRemainintBetterCount_should_ReturnCountNeedsToBet(void){
|
|
poker_t poker;
|
|
uint8_t p0, p1, p2;
|
|
|
|
pokerInit(&poker);
|
|
p0 = pokerPlayerAdd(&poker);
|
|
p1 = pokerPlayerAdd(&poker);
|
|
p2 = pokerPlayerAdd(&poker);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, pokerPlayerGetRemainingBetterCount(&poker));
|
|
|
|
pokerPlayerChipsAdd(poker.players + p0, 1000);
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, pokerPlayerGetRemainingBetterCount(&poker));
|
|
pokerPlayerChipsAdd(poker.players + p2, 1000);
|
|
TEST_ASSERT_EQUAL_UINT8(0x02, pokerPlayerGetRemainingBetterCount(&poker));
|
|
pokerPlayerChipsAdd(poker.players + p1, 1000);
|
|
TEST_ASSERT_EQUAL_UINT8(0x03, pokerPlayerGetRemainingBetterCount(&poker));
|
|
|
|
poker.players[0].state |= POKER_PLAYER_STATE_FOLDED;
|
|
TEST_ASSERT_EQUAL_UINT8(0x02, pokerPlayerGetRemainingBetterCount(&poker));
|
|
poker.players[1].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
|
|
TEST_ASSERT_EQUAL_UINT8(0x01, pokerPlayerGetRemainingBetterCount(&poker));
|
|
poker.players[2].chips = 0;
|
|
TEST_ASSERT_EQUAL_UINT8(0x00, pokerPlayerGetRemainingBetterCount(&poker));
|
|
}
|
|
|
|
void test_pokerPlayerBetPot_should_AddChipsToThePot(void) {
|
|
poker_t poker;
|
|
pokerpot_t *pot;
|
|
pokerplayer_t *player;
|
|
uint8_t i;
|
|
|
|
pokerInit(&poker);
|
|
pot = poker.pots;
|
|
i = pokerPlayerAdd(&poker);
|
|
player = poker.players + i;
|
|
pokerPlayerChipsAdd(player, 1000);
|
|
|
|
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
|
TEST_ASSERT_EQUAL_INT32(1000, player->chips);
|
|
|
|
pokerPlayerBetPot(&poker, pot, i, 100);
|
|
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
|
TEST_ASSERT_EQUAL_INT32(900, player->chips);
|
|
}
|
|
|
|
void test_pokerPlayerBetPot_should_UpdatePlayerState(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
|
|
pokerInit(&poker);
|
|
i = pokerPlayerAdd(&poker);
|
|
player = poker.players + i;
|
|
pokerPlayerChipsAdd(player, 1000);
|
|
|
|
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, player->state);
|
|
TEST_ASSERT_EQUAL_INT32(0, player->currentBet);
|
|
|
|
pokerPlayerBetPot(&poker, poker.pots, i, 100);
|
|
TEST_ASSERT_BITS_HIGH(POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, player->state);
|
|
TEST_ASSERT_EQUAL_INT32(100, player->currentBet);
|
|
|
|
pokerPlayerBetPot(&poker, poker.pots, i, 250);
|
|
TEST_ASSERT_EQUAL_INT32(350, player->currentBet);
|
|
}
|
|
|
|
void test_pokerPlayerBet_should_BetToTheActivePot(void) {
|
|
poker_t poker;
|
|
pokerpot_t *pot;
|
|
uint8_t i, j;
|
|
|
|
pokerInit(&poker);
|
|
i = pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players+i, 1000);
|
|
pot = poker.pots;
|
|
|
|
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
|
pokerPlayerBet(&poker, i, 100);
|
|
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
|
|
|
j = pokerPotAdd(&poker);
|
|
pokerPlayerBet(&poker, i, 50);
|
|
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
|
pot = poker.pots + j;
|
|
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
|
|
}
|
|
|
|
void test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet(void) {
|
|
poker_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) {
|
|
poker_t poker;
|
|
pokerturn_t turn;
|
|
pokerInit(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
|
|
turn = pokerTurnFold(&poker, 0x00);
|
|
TEST_ASSERT_EQUAL_INT32(0, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_FOLD, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
}
|
|
|
|
void test_pokerTurnBet_should_ReturnACheckAction(void) {
|
|
poker_t poker;
|
|
pokerturn_t turn;
|
|
pokerInit(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
|
|
turn = pokerTurnBet(&poker, 0x00, 0);
|
|
TEST_ASSERT_EQUAL_INT32(0, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CHECK, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
}
|
|
|
|
void test_pokerTurnBet_should_ReturnAnAllInAction(void) {
|
|
poker_t poker;
|
|
pokerturn_t turn;
|
|
pokerInit(&poker);
|
|
pokerPlayerAdd(&poker);
|
|
pokerPlayerChipsAdd(poker.players, 500);
|
|
|
|
turn = pokerTurnBet(&poker, 0x00, 500);
|
|
TEST_ASSERT_EQUAL_INT32(500, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_ALL_IN, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
|
|
pokerPlayerChipsAdd(poker.players, 500);
|
|
turn = pokerTurnBet(&poker, 0x00, 1001);
|
|
TEST_ASSERT_EQUAL_INT32(1000, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_ALL_IN, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
}
|
|
|
|
void test_pokerTurnBet_should_ReturnACallAction(void) {
|
|
poker_t poker;
|
|
pokerturn_t turn;
|
|
pokerInit(&poker);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
|
|
pokerPlayerBet(&poker, 0, 300);
|
|
pokerPlayerBet(&poker, 1, 500);
|
|
|
|
turn = pokerTurnBet(&poker, 0x00, 200);
|
|
TEST_ASSERT_EQUAL_INT32(200, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CALL, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
|
|
pokerPlayerBet(&poker, 0, 300);
|
|
turn = pokerTurnBet(&poker, 0x01, 100);
|
|
TEST_ASSERT_EQUAL_INT32(100, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_CALL, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
}
|
|
|
|
void test_pokerTurnBet_should_ReturnARaiseAction(void) {
|
|
poker_t poker;
|
|
pokerturn_t turn;
|
|
pokerInit(&poker);
|
|
pokerPlayerChipsAdd(poker.players + pokerPlayerAdd(&poker), 1000);
|
|
|
|
turn = pokerTurnBet(&poker, 0x00, 300);
|
|
TEST_ASSERT_EQUAL_INT32(300, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_BET, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
|
|
turn = pokerTurnBet(&poker, 0x00, 200);
|
|
TEST_ASSERT_EQUAL_INT32(200, turn.chips);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_TURN_TYPE_BET, turn.type);
|
|
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
|
}
|
|
|
|
void test_pokerHandGetFull_should_ReturnTheFullHand(void) {
|
|
poker_t poker;
|
|
pokerplayer_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) {
|
|
pokerplayerwinning_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;
|
|
|
|
pokerWinnerFillRemaining(&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) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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]);
|
|
}
|
|
|
|
void test_pokerWinnerGetForPlayer_should_CalculateTwoPair(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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_ACE;
|
|
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_TWO_PAIR, 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_QUEEN, winning.set[4]);
|
|
}
|
|
|
|
void test_pokerWinnerGetForPlayer_should_CalculateThreeOfAKind(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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;//+2
|
|
poker.community[2] = CARD_SPADES_THREE;//+3
|
|
poker.community[3] = CARD_SPADES_QUEEN;//+1
|
|
poker.community[4] = CARD_HEARTS_NINE;
|
|
player->cardCount = 2;
|
|
player->cards[0] = CARD_SPADES_TWO;//+4
|
|
player->cards[1] = CARD_SPADES_KING;//+0
|
|
|
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FLUSH, winning.type);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, winning.set[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_SIX, winning.set[2]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_THREE, winning.set[3]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TWO, winning.set[4]);
|
|
}
|
|
|
|
void test_pokerWinnerGet_should_CalculateFullHouse(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_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_ACE;
|
|
poker.community[3] = CARD_SPADES_QUEEN;
|
|
poker.community[4] = CARD_DIAMONDS_TWO;
|
|
player->cardCount = 2;
|
|
player->cards[0] = CARD_SPADES_TWO;
|
|
player->cards[1] = CARD_CLUBS_TWO;
|
|
|
|
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) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_t winning;
|
|
|
|
pokerInit(&poker);
|
|
i = pokerPlayerAdd(&poker);
|
|
player = poker.players + i;
|
|
|
|
poker.communitySize = 5;
|
|
poker.community[0] = CARD_HEARTS_TWO;
|
|
poker.community[1] = CARD_DIAMONDS_TWO;
|
|
poker.community[2] = CARD_SPADES_TWO;
|
|
poker.community[3] = CARD_SPADES_QUEEN;
|
|
poker.community[4] = CARD_SPADES_ACE;
|
|
player->cardCount = 2;
|
|
player->cards[0] = CARD_CLUBS_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_TWO, 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) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_t winning;
|
|
|
|
pokerInit(&poker);
|
|
i = pokerPlayerAdd(&poker);
|
|
player = poker.players + i;
|
|
|
|
poker.communitySize = 5;
|
|
poker.community[0] = CARD_DIAMONDS_ACE;
|
|
poker.community[1] = CARD_HEARTS_SIX;
|
|
poker.community[2] = CARD_HEARTS_THREE;
|
|
poker.community[3] = CARD_SPADES_QUEEN;
|
|
poker.community[4] = CARD_HEARTS_FOUR;
|
|
player->cardCount = 2;
|
|
player->cards[0] = CARD_HEARTS_TWO;
|
|
player->cards[1] = CARD_HEARTS_FIVE;
|
|
|
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_STRAIGHT_FLUSH, winning.type);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_SIX, winning.set[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_FIVE, winning.set[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_FOUR, winning.set[2]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_THREE, winning.set[3]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_TWO, winning.set[4]);
|
|
}
|
|
|
|
void test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush(void) {
|
|
poker_t poker;
|
|
uint8_t i;
|
|
pokerplayer_t *player;
|
|
pokerplayerwinning_t winning;
|
|
|
|
pokerInit(&poker);
|
|
i = pokerPlayerAdd(&poker);
|
|
player = poker.players + i;
|
|
|
|
poker.communitySize = 5;
|
|
poker.community[0] = CARD_DIAMONDS_ACE;
|
|
poker.community[1] = CARD_HEARTS_SIX;
|
|
poker.community[2] = CARD_SPADES_TEN;
|
|
poker.community[3] = CARD_SPADES_QUEEN;
|
|
poker.community[4] = CARD_SPADES_JACK;
|
|
player->cardCount = 2;
|
|
player->cards[0] = CARD_SPADES_KING;
|
|
player->cards[1] = CARD_SPADES_ACE;
|
|
|
|
pokerWinnerGetForPlayer(&poker, player, &winning);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_ROYAL_FLUSH, winning.type);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_ACE, winning.set[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_KING, winning.set[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, winning.set[2]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, winning.set[3]);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, winning.set[4]);
|
|
}
|
|
|
|
void test_pokerWinnerCompare_should_CompareWinningHands(void) {
|
|
poker_t poker;
|
|
uint8_t p0i, p1i;
|
|
pokerplayer_t *p0;
|
|
pokerplayer_t *p1;
|
|
pokerplayerwinning_t w0, w1;
|
|
card_t kicker;
|
|
|
|
// Construct two hands of the same type (pairs of eights)
|
|
pokerInit(&poker);
|
|
p0i = pokerPlayerAdd(&poker);
|
|
p1i = pokerPlayerAdd(&poker);
|
|
p0 = poker.players + p0i;
|
|
p1 = poker.players + p1i;
|
|
|
|
poker.communitySize = 5;
|
|
poker.community[0] = CARD_HEARTS_TWO;
|
|
poker.community[1] = CARD_DIAMONDS_NINE;
|
|
poker.community[2] = CARD_DIAMONDS_FOUR;
|
|
poker.community[3] = CARD_CLUBS_SIX;
|
|
poker.community[4] = CARD_HEARTS_EIGHT;
|
|
|
|
p0->cardCount = 2;
|
|
p0->cards[0] = CARD_CLUBS_EIGHT;
|
|
p0->cards[1] = CARD_CLUBS_KING;//Higher, Kicker
|
|
|
|
p1->cardCount = 2;
|
|
p1->cards[0] = CARD_SPADES_EIGHT;
|
|
p1->cards[1] = CARD_CLUBS_QUEEN;//Low, not
|
|
|
|
// Confirm both hands are pairs.
|
|
pokerWinnerGetForPlayer(&poker, p0, &w0);
|
|
pokerWinnerGetForPlayer(&poker, p1, &w1);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, w0.type);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, w1.type);
|
|
TEST_ASSERT_EQUAL_UINT8(w0.type, w1.type);
|
|
|
|
// Get the kicker, should be the king.
|
|
kicker = pokerWinnerCompare(&w0, &w1);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_KING, kicker);
|
|
|
|
// Change the kickers
|
|
p0->cards[1] = CARD_HEARTS_ACE;
|
|
p1->cards[1] = CARD_CLUBS_KING;
|
|
pokerWinnerGetForPlayer(&poker, p0, &w0);
|
|
pokerWinnerGetForPlayer(&poker, p1, &w1);
|
|
kicker = pokerWinnerCompare(&w0, &w1);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_HEARTS_ACE, kicker);
|
|
|
|
// Low left weight
|
|
p0->cards[1] = CARD_HEARTS_JACK;
|
|
pokerWinnerGetForPlayer(&poker, p0, &w0);
|
|
kicker = pokerWinnerCompare(&w0, &w1);
|
|
TEST_ASSERT_EQUAL_UINT8(0xFF, kicker);
|
|
}
|
|
|
|
void test_pokerWinnerDetermine_should_DecideTheWinnerCorrectly(void) {
|
|
poker_t poker;
|
|
uint8_t p0i, p1i, p2i;
|
|
pokerplayer_t *p0;
|
|
pokerplayer_t *p1;
|
|
pokerplayer_t *p2;
|
|
|
|
// Outputs
|
|
uint8_t winnerCount, participantCount;
|
|
uint8_t winnerPlayers[POKER_PLAYER_COUNT_MAX];
|
|
uint8_t participants[POKER_PLAYER_COUNT_MAX];
|
|
pokerplayerwinning_t winners[POKER_PLAYER_COUNT_MAX];
|
|
|
|
// Set up the players
|
|
pokerInit(&poker);
|
|
p0i = pokerPlayerAdd(&poker);
|
|
p1i = pokerPlayerAdd(&poker);
|
|
p2i = pokerPlayerAdd(&poker);
|
|
|
|
p0 = poker.players + p0i;
|
|
p1 = poker.players + p1i;
|
|
p2 = poker.players + p2i;
|
|
|
|
pokerPotAddPlayer(poker.pots + 0, p0i);
|
|
pokerPotAddPlayer(poker.pots + 0, p1i);
|
|
pokerPotAddPlayer(poker.pots + 0, p2i);
|
|
|
|
pokerPlayerChipsAdd(p0, 10000);
|
|
pokerPlayerChipsAdd(p1, 10000);
|
|
pokerPlayerChipsAdd(p2, 10000);
|
|
|
|
// Set up the community
|
|
poker.communitySize = 5;
|
|
poker.community[0] = CARD_HEARTS_TWO;
|
|
poker.community[1] = CARD_DIAMONDS_NINE;
|
|
poker.community[2] = CARD_DIAMONDS_FOUR;
|
|
poker.community[3] = CARD_DIAMONDS_SIX;
|
|
poker.community[4] = CARD_HEARTS_EIGHT;
|
|
|
|
// Set up the player hands
|
|
p0->cardCount = 2;
|
|
p0->cards[0] = CARD_CLUBS_EIGHT;
|
|
p0->cards[1] = CARD_CLUBS_KING;//Higher, Kicker
|
|
|
|
p1->cardCount = 2;
|
|
p1->cards[0] = CARD_SPADES_EIGHT;
|
|
p1->cards[1] = CARD_CLUBS_QUEEN;//Low, not
|
|
|
|
p2->state |= POKER_PLAYER_STATE_FOLDED;// Start folded
|
|
p2->cardCount = 2;
|
|
p2->cards[0] = CARD_DIAMONDS_TWO;
|
|
p2->cards[1] = CARD_DIAMONDS_KING;
|
|
|
|
// Run first test.
|
|
pokerWinnerDetermineForPot(
|
|
&poker, poker.pots + 0,
|
|
winners, winnerPlayers, &winnerCount,
|
|
participants, &participantCount
|
|
);
|
|
|
|
TEST_ASSERT_EQUAL_UINT8(1, winnerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, participantCount);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[0].type);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[1].type);
|
|
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_KING, winners[0].kicker);
|
|
TEST_ASSERT_EQUAL_UINT8(0, winnerPlayers[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(0, participants[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
|
|
|
// ----- //
|
|
// Test a difference in hands.
|
|
p1->cards[1] = CARD_CLUBS_NINE;// Makes p1 have two pair.
|
|
pokerWinnerDetermineForPot(
|
|
&poker, poker.pots + 0,
|
|
winners, winnerPlayers, &winnerCount,
|
|
participants, &participantCount
|
|
);
|
|
TEST_ASSERT_EQUAL_UINT8(1, winnerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, participantCount);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[0].type);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_TWO_PAIR, winners[1].type);
|
|
TEST_ASSERT_EQUAL_UINT8(1, winnerPlayers[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(0, participants[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
|
|
|
// Unfold p2
|
|
p2->state = flagOff(p2->state, POKER_PLAYER_STATE_FOLDED);
|
|
pokerWinnerDetermineForPot(
|
|
&poker, poker.pots + 0,
|
|
winners, winnerPlayers, &winnerCount,
|
|
participants, &participantCount
|
|
);
|
|
TEST_ASSERT_EQUAL_UINT8(1, winnerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(3, participantCount);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[0].type);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_TWO_PAIR, winners[1].type);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_FLUSH, winners[2].type);
|
|
TEST_ASSERT_EQUAL_UINT8(2, winnerPlayers[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(0, participants[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
|
TEST_ASSERT_EQUAL_UINT8(2, participants[2]);
|
|
|
|
// Create a new pot that P2 isn't participating in.
|
|
pokerPotAdd(&poker);
|
|
pokerPotAddPlayer(poker.pots + 1, p0i);
|
|
pokerPotAddPlayer(poker.pots + 1, p1i);
|
|
pokerWinnerDetermineForPot(
|
|
&poker, poker.pots + 1,
|
|
winners, winnerPlayers, &winnerCount,
|
|
participants, &participantCount
|
|
);
|
|
TEST_ASSERT_EQUAL_UINT8(1, winnerCount);
|
|
TEST_ASSERT_EQUAL_UINT8(2, participantCount);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_PAIR, winners[0].type);
|
|
TEST_ASSERT_EQUAL_UINT8(POKER_WINNING_TYPE_TWO_PAIR, winners[1].type);
|
|
TEST_ASSERT_EQUAL_UINT8(1, winnerPlayers[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(0, participants[0]);
|
|
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
|
}
|
|
|
|
int test_poker() {
|
|
UNITY_BEGIN();
|
|
|
|
RUN_TEST(test_pokerInit_should_InitializePokerGame);
|
|
RUN_TEST(test_pokerResetRound_should_ResetTheRound);
|
|
RUN_TEST(test_pokerResetRound_should_ResetThePlayers);
|
|
RUN_TEST(test_pokerResetBettingRound_should_ResetTheBettingRound);
|
|
RUN_TEST(test_pokerPotAdd_should_AddAPot);
|
|
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
|
|
RUN_TEST(test_pokerNewDealer_should_FindANewDealer);
|
|
RUN_TEST(test_pokerNewDealer_should_SkipOutPlayers);
|
|
RUN_TEST(test_pokerTakeBlinds_should_TakeTheBlinds);
|
|
RUN_TEST(test_pokerPotAddPlayer_should_AddAPlayer);
|
|
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
|
|
RUN_TEST(test_pokerTurn_should_TurnCardsFromTheDeck);
|
|
RUN_TEST(test_pokerBurn_should_SendCardsToTheGrave);
|
|
RUN_TEST(test_pokerGetCallValue_should_CalculateTheCallValue);
|
|
RUN_TEST(test_pokerPlayerDeal_should_DealCardsToThePlayer);
|
|
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
|
|
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);
|
|
RUN_TEST(test_pokerPlayerDealAll_should_DealCardsToEveryone);
|
|
RUN_TEST(test_pokerPlayerDealAll_should_DealMultipleCardsToEveryone);
|
|
RUN_TEST(test_pokerPlayerDealAll_should_NotDealToOutPlayers);
|
|
RUN_TEST(test_pokerPlayerDealAll_should_NotDealToFoldedPlayers);
|
|
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue);
|
|
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet);
|
|
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers);
|
|
RUN_TEST(test_pokerPlayerGetRemainingBetter_should_ReturnRemainingBetters);
|
|
RUN_TEST(test_pokerPlayerGetNextBetter_should_GetTheNextBetter);
|
|
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
|
RUN_TEST(test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound);
|
|
RUN_TEST(
|
|
test_pokerPlayerGetRemainintBetterCount_should_ReturnCountNeedsToBet
|
|
);
|
|
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);
|
|
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_pokerWinnerGet_should_CalculateFullHouse);
|
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateFourOfAKind);
|
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateStraightFlush);
|
|
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateRoyalFlush);
|
|
RUN_TEST(test_pokerWinnerCompare_should_CompareWinningHands);
|
|
RUN_TEST(test_pokerWinnerDetermine_should_DecideTheWinnerCorrectly);
|
|
|
|
return UNITY_END();
|
|
} |