Writing more poker logic.

This commit is contained in:
2021-10-03 12:54:35 -07:00
parent c024ee745d
commit 1833fd6baa
3 changed files with 152 additions and 4 deletions

View File

@ -34,6 +34,37 @@ void test_pokerResetRound_should_ResetTheRound(void) {
TEST_ASSERT_EQUAL_UINT8(1, poker.potCount);
}
void test_pokerResetRound_should_ResetThePlayers(void) {
poker2_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_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_EQUAL_UINT8(
0xFF - POKER_PLAYER_STATE_FOLDED - POKER_PLAYER_STATE_HAS_BET_THIS_ROUND,
poker.players[i].state
);
}
}
void test_pokerNewDealer_should_FindANewDealer(void) {
poker2_t poker;
pokerInit(&poker);
@ -191,8 +222,9 @@ void test_pokerPlayerAdd_should_ResetThePlayer(void) {
player = poker.players + pokerPlayerAdd(&poker);
TEST_ASSERT_EQUAL_INT32(0, player->chips);
TEST_ASSERT_EQUAL_UINT8(POKER_PLAYER_STATE_OUT, player->state);
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) {
@ -236,6 +268,53 @@ void test_pokerBurn_should_SendCardsToTheGrave(void) {
}
void test_pokerGetCallValue_should_CalculateTheCallValue(void) {
poker2_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) {
poker2_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) {
poker2_t poker;
uint8_t playerIndex;
@ -383,6 +462,30 @@ void test_pokerPlayerDealAll_should_NotDealToFoldedPlayers(void) {
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, poker.players[2].cards[1]);
}
void test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue(void) {
poker2_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_pokerPlayerBetPot_should_AddChipsToThePot(void) {
poker2_t poker;
poker2pot_t *pot;
@ -414,8 +517,14 @@ void test_pokerPlayerBetPot_should_UpdatePlayerState(void) {
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) {
@ -444,6 +553,7 @@ int test_poker() {
RUN_TEST(test_pokerInit_should_InitializePokerGame);
RUN_TEST(test_pokerResetRound_should_ResetTheRound);
RUN_TEST(test_pokerResetRound_should_ResetThePlayers);
RUN_TEST(test_pokerPotAdd_should_AddAPot);
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
RUN_TEST(test_pokerNewDealer_should_FindANewDealer);
@ -453,6 +563,7 @@ int test_poker() {
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);
@ -460,6 +571,7 @@ int test_poker() {
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_pokerPlayerBetPot_should_AddChipsToThePot);
RUN_TEST(test_pokerPlayerBetPot_should_UpdatePlayerState);
RUN_TEST(test_pokerPlayerBet_should_BetToTheActivePot);