Added resetting betting round command
This commit is contained in:
@ -43,9 +43,7 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
|
||||
// will take over.
|
||||
|
||||
// TODO: finish
|
||||
// pokerBetResetBetter(
|
||||
// &game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
||||
// );
|
||||
pokerResetBettingRound(&game->poker);
|
||||
pokerGameActionBetAdd(game);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ void pokerResetRound(poker_t *poker) {
|
||||
poker->potCount = 0;
|
||||
pokerPotAdd(poker);
|
||||
|
||||
pokerResetBettingRound(poker);
|
||||
|
||||
for(i = 0; i < poker->playerCount; i++) {
|
||||
player = poker->players + i;
|
||||
player->cardCount = 0;
|
||||
@ -37,6 +39,28 @@ void pokerResetRound(poker_t *poker) {
|
||||
}
|
||||
}
|
||||
|
||||
void pokerResetBettingRound(poker_t *poker) {
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
|
||||
// Reset the round betting state.
|
||||
for(i = 0; i < poker->playerCount; i++) {
|
||||
player = poker->players + i;
|
||||
player->state =flagOff(player->state,POKER_PLAYER_STATE_HAS_BET_THIS_ROUND);
|
||||
}
|
||||
|
||||
// Now reset to the first player that needs to bet.
|
||||
if(poker->playerCount > 0) {
|
||||
poker->better = (poker->playerBigBlind + 1) % poker->playerCount;
|
||||
} else {
|
||||
poker->better = 0x00;
|
||||
}
|
||||
|
||||
// Then we check who's remaining. We do this because the default better may
|
||||
// have folded already.
|
||||
poker->better = pokerPlayerGetRemainingBetter(poker);
|
||||
}
|
||||
|
||||
void pokerNewDealer(poker_t *poker) {
|
||||
uint8_t i, j, k;
|
||||
pokerplayer_t *player;
|
||||
@ -113,6 +137,7 @@ void pokerBurn(poker_t *poker, uint8_t count) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Player Functions
|
||||
uint8_t pokerPlayerAdd(poker_t *poker) {
|
||||
pokerplayer_t *player;
|
||||
|
@ -166,6 +166,9 @@ typedef struct {
|
||||
uint8_t playerSmallBlind;
|
||||
/** Index of the big blind player */
|
||||
uint8_t playerBigBlind;
|
||||
|
||||
/** Which player is the current active better ? */
|
||||
uint8_t better;
|
||||
} poker_t;
|
||||
|
||||
|
||||
@ -183,6 +186,13 @@ void pokerInit(poker_t *poker);
|
||||
*/
|
||||
void pokerResetRound(poker_t *poker);
|
||||
|
||||
/**
|
||||
* Reset the poker betting round.
|
||||
*
|
||||
* @param poker Poker game instance to reset for.
|
||||
*/
|
||||
void pokerResetBettingRound(poker_t *poker);
|
||||
|
||||
/**
|
||||
* Cycles to the next dealer. This will also select the new small and big blind
|
||||
* players.
|
||||
|
@ -42,6 +42,7 @@ void test_pokerResetRound_should_ResetThePlayers(void) {
|
||||
pokerPlayerAdd(&poker);
|
||||
pokerPlayerAdd(&poker);
|
||||
|
||||
|
||||
for(i = 0; i < poker.playerCount; i++) {
|
||||
poker.players[i].cardCount = 32;
|
||||
poker.players[i].chips = 100;
|
||||
@ -55,6 +56,7 @@ void test_pokerResetRound_should_ResetThePlayers(void) {
|
||||
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
|
||||
@ -63,6 +65,31 @@ void test_pokerResetRound_should_ResetThePlayers(void) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
@ -1446,6 +1473,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_pokerResetBettingRound_should_ResetTheBettingRound);
|
||||
RUN_TEST(test_pokerPotAdd_should_AddAPot);
|
||||
RUN_TEST(test_pokerPotAdd_should_ResetThePot);
|
||||
RUN_TEST(test_pokerNewDealer_should_FindANewDealer);
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
int main() {
|
||||
return (
|
||||
test_card() ||
|
||||
test_poker()
|
||||
) || 0;
|
||||
!test_card() &&
|
||||
!test_poker()
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user