A bit more code cleaning.

This commit is contained in:
2021-07-13 08:59:04 -07:00
parent 6b027e6e4e
commit 4a2112e3ce
11 changed files with 64 additions and 29 deletions

View File

@ -7,6 +7,15 @@
#include "bet.h" #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) { void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips) {
poker->bet.pot += chips; poker->bet.pot += chips;
player->chips -= chips; player->chips -= chips;

View File

@ -6,6 +6,20 @@
#pragma once #pragma once
#include <dawn/dawn.h> #include <dawn/dawn.h>
/**
* 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. * Let a player bet chips into the pot.
* *

View File

@ -13,4 +13,16 @@ bool pokerPlayerIsAlive(pokerplayer_t *player) {
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) { bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) {
return (poker->players + POKER_PLAYER_HUMAN_INDEX) == 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
);
} }

View File

@ -25,3 +25,10 @@ bool pokerPlayerIsAlive(pokerplayer_t *player);
* @returns True if the player is human. * @returns True if the player is human.
*/ */
bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player); 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);

View File

@ -37,7 +37,7 @@ void pokerUpdate(poker_t *poker, engine_t *engine) {
case POKER_ROUND_BET1: case POKER_ROUND_BET1:
case POKER_ROUND_BET2: case POKER_ROUND_BET2:
case POKER_ROUND_BET3: case POKER_ROUND_BET3:
pokerBetUpdate(poker); pokerRoundBetUpdate(poker);
break; break;
default: default:
break; break;

View File

@ -7,7 +7,7 @@
#include "bet.h" #include "bet.h"
void pokerBetPlayerNext(poker_t *poker) { void pokerRoundBetPlayerNext(poker_t *poker) {
// Go to next player, keep contained. // Go to next player, keep contained.
poker->roundBetCurrent = (poker->roundBetCurrent + 1) % POKER_PLAYER_COUNT; poker->roundBetCurrent = (poker->roundBetCurrent + 1) % POKER_PLAYER_COUNT;
@ -23,32 +23,32 @@ void pokerBetPlayerNext(poker_t *poker) {
} }
// Init the next player // 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) // Check the player state (to see if we even can init, e.g. folded/not)
if(!pokerPlayerIsAlive(player)) { if(!pokerPlayerIsAlive(player)) {
pokerBetPlayerNext(poker); pokerRoundBetPlayerNext(poker);
return; return;
} }
printf("Betting round player %u\n", poker->roundBetCurrent); printf("Betting round player %u\n", poker->roundBetCurrent);
if(pokerPlayerIsHuman(poker, player)) { if(pokerPlayerIsHuman(poker, player)) {
pokerBetPlayerNext(poker); pokerRoundBetPlayerNext(poker);
return; 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"); printf("Betting round start\n");
if(poker->round == POKER_ROUND_DEAL) { if(poker->round == POKER_ROUND_DEAL) {
@ -67,10 +67,10 @@ void pokerBetInit(poker_t *poker) {
// Set the inital player // Set the inital player
poker->roundBetCurrent = poker->roundSmallBlind; 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 // Take the current player
pokerBetPlayerUpdate(poker, poker->players + poker->roundBetCurrent); pokerRoundBetPlayerUpdate(poker, poker->players + poker->roundBetCurrent);
} }

View File

@ -11,9 +11,9 @@
#include "winner.h" #include "winner.h"
#include "../player.h" #include "../player.h"
void pokerBetPlayerNext(poker_t *poker); void pokerRoundBetPlayerNext(poker_t *poker);
void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player); void pokerRoundBetPlayerInit(poker_t *poker, pokerplayer_t *player);
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);
void pokerBetUpdate(poker_t *poker); void pokerRoundBetUpdate(poker_t *poker);

View File

@ -28,5 +28,5 @@ void pokerFlopInit(poker_t *poker) {
pokerDealerBurn(&poker->dealer, 1); pokerDealerBurn(&poker->dealer, 1);
pokerDealerTurn(&poker->dealer, count); pokerDealerTurn(&poker->dealer, count);
pokerBetInit(poker); pokerRoundBetInit(poker);
} }

View File

@ -14,8 +14,7 @@ void pokerMatchInit(poker_t *poker, engine_t *engine) {
pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER, 100); pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER, 100);
// Reset the main game state. This does not init the round. // Reset the main game state. This does not init the round.
poker->bet.blindBig = POKER_BET_BLIND_BIG_DEFAULT; pokerBetInit(&poker->bet);
poker->bet.blindSmall = POKER_BET_BLIND_SMALL_DEFAULT;
poker->roundDealer = POKER_PLAYER_COUNT-2; poker->roundDealer = POKER_PLAYER_COUNT-2;
poker->roundTextCounter = 0; poker->roundTextCounter = 0;
poker->round = POKER_ROUND_MATCH; poker->round = POKER_ROUND_MATCH;

View File

@ -16,19 +16,12 @@ void pokerStartInit(poker_t *poker) {
// Prepare the initial game state // Prepare the initial game state
poker->round = POKER_ROUND_DEAL; poker->round = POKER_ROUND_DEAL;
poker->bet.pot = 0; pokerBetReset(&poker->bet);
pokerDealerInit(&poker->dealer); pokerDealerInit(&poker->dealer);
// Reset the players // Reset the players
for(i = 0; i < POKER_PLAYER_COUNT; i++) { for(i = 0; i < POKER_PLAYER_COUNT; i++) {
poker->players[i].cardCount = 0; pokerPlayerReset(poker->players + i);
poker->players[i].currentBet = 0;
// Invert then bitwise AND to turn off.
poker->players[i].state &= ~(
POKER_PLAYER_STATE_FOLDED |
POKER_PLAYER_STATE_SHOWING
);
} }
// Decide on the dealer // Decide on the dealer

View File

@ -8,6 +8,7 @@
#pragma once #pragma once
#include <dawn/dawn.h> #include <dawn/dawn.h>
#include "blinds.h" #include "blinds.h"
#include "../bet.h"
#include "../player.h" #include "../player.h"
void pokerStartInit(poker_t *poker); void pokerStartInit(poker_t *poker);