diff --git a/src/poker/bet.c b/src/poker/bet.c index 4a76f9ea..e5625536 100644 --- a/src/poker/bet.c +++ b/src/poker/bet.c @@ -7,6 +7,15 @@ #include "bet.h" +void pokerBetInit(pokerbet_t *bet) { + bet->blindBig = POKER_BET_BLIND_BIG_DEFAULT; + bet->blindSmall = POKER_BET_BLIND_SMALL_DEFAULT; +} + +void pokerBetReset(pokerbet_t *bet) { + bet->pot = 0; +} + void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips) { poker->bet.pot += chips; player->chips -= chips; diff --git a/src/poker/bet.h b/src/poker/bet.h index 39746c85..72a32c7a 100644 --- a/src/poker/bet.h +++ b/src/poker/bet.h @@ -6,6 +6,20 @@ #pragma once #include +/** + * Initializes/resets the poker bet context. + * + * @param bet Poker bet instance. + */ +void pokerBetInit(pokerbet_t *bet); + +/** + * Resets the bet state (for a new round). + * + * @param bet + */ +void pokerBetReset(pokerbet_t *bet); + /** * Let a player bet chips into the pot. * diff --git a/src/poker/player.c b/src/poker/player.c index b0c7903d..d5ce2ae1 100644 --- a/src/poker/player.c +++ b/src/poker/player.c @@ -13,4 +13,16 @@ bool pokerPlayerIsAlive(pokerplayer_t *player) { bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) { return (poker->players + POKER_PLAYER_HUMAN_INDEX) == player; +} + + +void pokerPlayerReset(pokerplayer_t *player) { + player->cardCount = 0; + player->currentBet = 0; + + // Invert then bitwise AND to turn off. + player->state &= ~( + POKER_PLAYER_STATE_FOLDED | + POKER_PLAYER_STATE_SHOWING + ); } \ No newline at end of file diff --git a/src/poker/player.h b/src/poker/player.h index 86cd0881..f68dde2d 100644 --- a/src/poker/player.h +++ b/src/poker/player.h @@ -25,3 +25,10 @@ bool pokerPlayerIsAlive(pokerplayer_t *player); * @returns True if the player is human. */ bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player); + +/** + * Resets a poker player's state (for a new round). + * + * @param player Player to reset. + */ +void pokerPlayerReset(pokerplayer_t *player); \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index b2d4e832..ba6ac403 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -37,7 +37,7 @@ void pokerUpdate(poker_t *poker, engine_t *engine) { case POKER_ROUND_BET1: case POKER_ROUND_BET2: case POKER_ROUND_BET3: - pokerBetUpdate(poker); + pokerRoundBetUpdate(poker); break; default: break; diff --git a/src/poker/round/bet.c b/src/poker/round/bet.c index e9fefdf3..364c5cb6 100644 --- a/src/poker/round/bet.c +++ b/src/poker/round/bet.c @@ -7,7 +7,7 @@ #include "bet.h" -void pokerBetPlayerNext(poker_t *poker) { +void pokerRoundBetPlayerNext(poker_t *poker) { // Go to next player, keep contained. poker->roundBetCurrent = (poker->roundBetCurrent + 1) % POKER_PLAYER_COUNT; @@ -23,32 +23,32 @@ void pokerBetPlayerNext(poker_t *poker) { } // Init the next player - pokerBetPlayerInit(poker, poker->players + poker->roundBetCurrent); + pokerRoundBetPlayerInit(poker, poker->players + poker->roundBetCurrent); } -void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player) { +void pokerRoundBetPlayerInit(poker_t *poker, pokerplayer_t *player) { // Check the player state (to see if we even can init, e.g. folded/not) if(!pokerPlayerIsAlive(player)) { - pokerBetPlayerNext(poker); + pokerRoundBetPlayerNext(poker); return; } printf("Betting round player %u\n", poker->roundBetCurrent); if(pokerPlayerIsHuman(poker, player)) { - pokerBetPlayerNext(poker); + pokerRoundBetPlayerNext(poker); return; } - pokerBetPlayerNext(poker); + pokerRoundBetPlayerNext(poker); } -void pokerBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) { +void pokerRoundBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) { } -void pokerBetInit(poker_t *poker) { +void pokerRoundBetInit(poker_t *poker) { printf("Betting round start\n"); if(poker->round == POKER_ROUND_DEAL) { @@ -67,10 +67,10 @@ void pokerBetInit(poker_t *poker) { // Set the inital player poker->roundBetCurrent = poker->roundSmallBlind; - pokerBetPlayerInit(poker, poker->players+poker->roundBetCurrent); + pokerRoundBetPlayerInit(poker, poker->players+poker->roundBetCurrent); } -void pokerBetUpdate(poker_t *poker) { +void pokerRoundBetUpdate(poker_t *poker) { // Take the current player - pokerBetPlayerUpdate(poker, poker->players + poker->roundBetCurrent); + pokerRoundBetPlayerUpdate(poker, poker->players + poker->roundBetCurrent); } \ No newline at end of file diff --git a/src/poker/round/bet.h b/src/poker/round/bet.h index febfaf88..9dd9b467 100644 --- a/src/poker/round/bet.h +++ b/src/poker/round/bet.h @@ -11,9 +11,9 @@ #include "winner.h" #include "../player.h" -void pokerBetPlayerNext(poker_t *poker); -void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player); -void pokerBetPlayerUpdate(poker_t *poker, pokerplayer_t *player); +void pokerRoundBetPlayerNext(poker_t *poker); +void pokerRoundBetPlayerInit(poker_t *poker, pokerplayer_t *player); +void pokerRoundBetPlayerUpdate(poker_t *poker, pokerplayer_t *player); -void pokerBetInit(poker_t *poker); -void pokerBetUpdate(poker_t *poker); \ No newline at end of file +void pokerRoundBetInit(poker_t *poker); +void pokerRoundBetUpdate(poker_t *poker); \ No newline at end of file diff --git a/src/poker/round/flop.c b/src/poker/round/flop.c index d2c2db03..d4bf4297 100644 --- a/src/poker/round/flop.c +++ b/src/poker/round/flop.c @@ -28,5 +28,5 @@ void pokerFlopInit(poker_t *poker) { pokerDealerBurn(&poker->dealer, 1); pokerDealerTurn(&poker->dealer, count); - pokerBetInit(poker); + pokerRoundBetInit(poker); } \ No newline at end of file diff --git a/src/poker/round/match.c b/src/poker/round/match.c index 2b1a2e1f..b912b41a 100644 --- a/src/poker/round/match.c +++ b/src/poker/round/match.c @@ -14,8 +14,7 @@ void pokerMatchInit(poker_t *poker, engine_t *engine) { pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER, 100); // Reset the main game state. This does not init the round. - poker->bet.blindBig = POKER_BET_BLIND_BIG_DEFAULT; - poker->bet.blindSmall = POKER_BET_BLIND_SMALL_DEFAULT; + pokerBetInit(&poker->bet); poker->roundDealer = POKER_PLAYER_COUNT-2; poker->roundTextCounter = 0; poker->round = POKER_ROUND_MATCH; diff --git a/src/poker/round/start.c b/src/poker/round/start.c index bd0977b7..f69f9b1a 100644 --- a/src/poker/round/start.c +++ b/src/poker/round/start.c @@ -16,19 +16,12 @@ void pokerStartInit(poker_t *poker) { // Prepare the initial game state poker->round = POKER_ROUND_DEAL; - poker->bet.pot = 0; + pokerBetReset(&poker->bet); pokerDealerInit(&poker->dealer); // Reset the players for(i = 0; i < POKER_PLAYER_COUNT; i++) { - poker->players[i].cardCount = 0; - poker->players[i].currentBet = 0; - - // Invert then bitwise AND to turn off. - poker->players[i].state &= ~( - POKER_PLAYER_STATE_FOLDED | - POKER_PLAYER_STATE_SHOWING - ); + pokerPlayerReset(poker->players + i); } // Decide on the dealer diff --git a/src/poker/round/start.h b/src/poker/round/start.h index 238884bd..20b04e35 100644 --- a/src/poker/round/start.h +++ b/src/poker/round/start.h @@ -8,6 +8,7 @@ #pragma once #include #include "blinds.h" +#include "../bet.h" #include "../player.h" void pokerStartInit(poker_t *poker); \ No newline at end of file