A bit more code cleaning.
This commit is contained in:
@ -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;
|
||||
|
@ -6,6 +6,20 @@
|
||||
#pragma once
|
||||
#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.
|
||||
*
|
||||
|
@ -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
|
||||
);
|
||||
}
|
@ -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);
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
void pokerRoundBetInit(poker_t *poker);
|
||||
void pokerRoundBetUpdate(poker_t *poker);
|
@ -28,5 +28,5 @@ void pokerFlopInit(poker_t *poker) {
|
||||
pokerDealerBurn(&poker->dealer, 1);
|
||||
pokerDealerTurn(&poker->dealer, count);
|
||||
|
||||
pokerBetInit(poker);
|
||||
pokerRoundBetInit(poker);
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#include "blinds.h"
|
||||
#include "../bet.h"
|
||||
#include "../player.h"
|
||||
|
||||
void pokerStartInit(poker_t *poker);
|
Reference in New Issue
Block a user