Even more tests again.

This commit is contained in:
2021-10-04 00:45:39 -07:00
parent 0370444a34
commit a9a7d40df8
3 changed files with 174 additions and 1 deletions

View File

@ -189,6 +189,10 @@ uint8_t pokerPlayerGetNextBetter(poker2_t *poker, uint8_t current) {
return 0xFF;
}
int32_t pokerPlayerGetCallBet(poker2_t *poker, poker2player_t *player) {
return pokerGetCallValue(poker) - player->currentBet;
}
// Betting
void pokerPlayerBetPot(
poker2_t *poker, poker2pot_t *pot, uint8_t playerIndex, int32_t chips
@ -206,4 +210,38 @@ void pokerPlayerBet(poker2_t *poker, uint8_t playerIndex, int32_t chips) {
pokerPlayerBetPot(
poker, poker->pots + (poker->potCount - 1), playerIndex, chips
);
}
poker2turn_t pokerTurnFold(poker2_t *poker, uint8_t player) {
return (poker2turn_t){
.chips = 0,
.confidence = 1,
.type = POKER_TURN_TYPE_FOLD
};
}
poker2turn_t pokerTurnBet(poker2_t *poker, uint8_t playerIndex, int32_t chips) {
poker2turn_t turn;
poker2player_t *player;
int32_t i;
player = poker->players + playerIndex;
turn.confidence = 1;
if(chips == 0) {
turn.type = POKER_TURN_TYPE_CHECK;
turn.chips = 0;
} else if(player->chips <= chips) {
turn.chips = player->chips;
turn.type = POKER_TURN_TYPE_ALL_IN;
} else {
turn.chips = chips;
turn.type = POKER_TURN_TYPE_BET;
i = pokerGetCallValue(poker);
if(chips == (i - player->currentBet)) {
turn.type = POKER_TURN_TYPE_CALL;
}
}
return turn;
}

View File

@ -23,6 +23,14 @@
#define POKER_COMMUNITY_SIZE_MAX 5
#define POKER_POT_COUNT_MAX POKER_PLAYER_COUNT_MAX
#define POKER_TURN_TYPE_OUT 0x00
#define POKER_TURN_TYPE_FOLD 0x01
#define POKER_TURN_TYPE_BET 0x02
#define POKER_TURN_TYPE_CALL 0x03
#define POKER_TURN_TYPE_ALL_IN 0x04
#define POKER_TURN_TYPE_CALL_ALL_IN 0x04
#define POKER_TURN_TYPE_CHECK 0x05
typedef struct {
int32_t chips;
card_t cards[POKER_PLAYER_HAND_SIZE_MAX];
@ -37,6 +45,12 @@ typedef struct {
uint8_t playerCount;
} poker2pot_t;
typedef struct {
uint8_t type;
int32_t chips;
float confidence;
} poker2turn_t;
typedef struct {
card_t deck[CARD_DECK_SIZE];
uint8_t deckSize;
@ -83,7 +97,14 @@ void pokerPlayerDealAll(poker2_t *poker, uint8_t count);
bool pokerPlayerDoesNeedToBetThisRound(poker2_t *poker, uint8_t playerIndex);
uint8_t pokerPlayerGetRemainingBetter(poker2_t *poker);
uint8_t pokerPlayerGetNextBetter(poker2_t *poker, uint8_t current);
int32_t pokerPlayerGetCallBet(poker2_t *poker, poker2player_t *player);
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);
void pokerPlayerBet(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);
poker2turn_t pokerTurnFold(poker2_t *poker, uint8_t player);
poker2turn_t pokerTurnBet(poker2_t *poker, uint8_t playerIndex, int32_t chips);

View File

@ -649,6 +649,31 @@ void test_pokerPlayerGetNextBetter_should_GetTheNextBetter(void) {
TEST_ASSERT_EQUAL_UINT8(0x00, better);
}
void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
poker2_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_pokerPlayerBetPot_should_AddChipsToThePot(void) {
poker2_t poker;
poker2pot_t *pot;
@ -711,6 +736,88 @@ void test_pokerPlayerBet_should_BetToTheActivePot(void) {
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
}
void test_pokerTurnFold_should_ReturnAFoldAction(void) {
poker2_t poker;
poker2turn_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) {
poker2_t poker;
poker2turn_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) {
poker2_t poker;
poker2turn_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) {
poker2_t poker;
poker2turn_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) {
poker2_t poker;
poker2turn_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);
}
int test_poker() {
UNITY_BEGIN();
@ -739,9 +846,16 @@ int test_poker() {
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_pokerPlayerBetPot_should_AddChipsToThePot);
RUN_TEST(test_pokerPlayerBetPot_should_UpdatePlayerState);
RUN_TEST(test_pokerPlayerBet_should_BetToTheActivePot);
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);
return UNITY_END();
}