Just getting the betting cycle done.

This commit is contained in:
2021-08-13 10:09:37 -07:00
parent eddc5bfafd
commit 98b50f5987
8 changed files with 59 additions and 25 deletions

View File

@ -13,20 +13,6 @@
#include "card.h" #include "card.h"
#include "winner.h" #include "winner.h"
/** Rounds that the game can be in */
#define POKER_ROUND_MATCH 0x00
#define POKER_ROUND_START 0x01
#define POKER_ROUND_BLINDS 0x02
#define POKER_ROUND_DEAL 0x03
#define POKER_ROUND_BET0 0x04
#define POKER_ROUND_FLOP 0X05
#define POKER_ROUND_BET1 0x06
#define POKER_ROUND_TURN 0x07
#define POKER_ROUND_BET2 0x08
#define POKER_ROUND_RIVER 0x09
#define POKER_ROUND_BET3 0x0A
#define POKER_ROUND_WINNER 0x0B
/** How many cards to deal each player during the deal round */ /** How many cards to deal each player during the deal round */
#define POKER_DEAL_CARD_EACH 2 #define POKER_DEAL_CARD_EACH 2
@ -51,6 +37,7 @@ typedef struct {
/** Which player is the small blind for this round */ /** Which player is the small blind for this round */
uint8_t roundSmallBlind; uint8_t roundSmallBlind;
/** Which player is the big blind for this round */ /** Which player is the big blind for this round */
uint8_t roundBigBlind; uint8_t roundBigBlind;
} poker_t; } poker_t;

View File

@ -11,6 +11,7 @@
#define POKER_TURN_TYPE_OUT 0x00 #define POKER_TURN_TYPE_OUT 0x00
#define POKER_TURN_TYPE_FOLD 0x01 #define POKER_TURN_TYPE_FOLD 0x01
#define POKER_TURN_TYPE_BET 0x02 #define POKER_TURN_TYPE_BET 0x02
#define POKER_TURN_TYPE_CHECK 0x03
typedef struct { typedef struct {
uint8_t type; uint8_t type;

View File

@ -45,7 +45,9 @@ void queueDispose(queue_t *queue);
/** /**
* Restacks the queue. The restack process essentially rewinds the queue so that * Restacks the queue. The restack process essentially rewinds the queue so that
* the current items move back to position 0, and allows you to add more items * the current items move back to position 0, and allows you to add more items
* to the queue again. * to the queue again. Because the memory does shift, and the indexes do change
* a lot of your pointers will break, make sure you re-reference all your
* pointers.
* *
* @param queue Queue to restack. * @param queue Queue to restack.
*/ */

View File

@ -7,11 +7,6 @@
#include "bet.h" #include "bet.h"
void _pokerGameActionBetOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
}
void _pokerGameActionBetOnUpdate( void _pokerGameActionBetOnUpdate(
queue_t *queue, queueaction_t *action, uint8_t i queue_t *queue, queueaction_t *action, uint8_t i
) { ) {
@ -32,7 +27,7 @@ void _pokerGameActionBetOnUpdate(
// Handle as an AI // Handle as an AI
if(isHuman) { if(isHuman) {
turn.type = POKER_TURN_TYPE_OUT; turn.type = POKER_TURN_TYPE_FOLD;
turnMade = true; turnMade = true;
} else { } else {
turn = pokerTurnGet(&game->poker, game->poker.bet.better); turn = pokerTurnGet(&game->poker, game->poker.bet.better);
@ -56,6 +51,11 @@ void _pokerGameActionBetOnUpdate(
debugAction = "folding"; debugAction = "folding";
player->state |= POKER_PLAYER_STATE_FOLDED; player->state |= POKER_PLAYER_STATE_FOLDED;
break; break;
// Player checks
case POKER_TURN_TYPE_CHECK:
debugAction = "checking";
break;
// Player may be out // Player may be out
default: default:
@ -72,6 +72,7 @@ void _pokerGameActionBetOnEnd(
) { ) {
uint8_t j; uint8_t j;
pokerplayer_t *player; pokerplayer_t *player;
queueaction_t *next;
pokergame_t *game = (pokergame_t *)action->data; pokergame_t *game = (pokergame_t *)action->data;
bool playersPending; bool playersPending;
@ -95,13 +96,22 @@ void _pokerGameActionBetOnEnd(
// Are we waiting on any players? // Are we waiting on any players?
if(playersPending) return; if(playersPending) return;
printf("Not waiting on anything!\n");
// No! Begin the next flop. // No! Begin the next flop.
printf("Not waiting on anything\n"); next = pokerActionNextFlopAdd(queue, &game->poker);
if(next != NULL) {
pokerBetResetBetter(&game->poker);
pokerGameActionBetAdd(game);
return;
}
printf("All betting is done, reveal");
} }
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) { queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game); queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionBetOnStart;
action->onUpdate = &_pokerGameActionBetOnUpdate; action->onUpdate = &_pokerGameActionBetOnUpdate;
action->onEnd = &_pokerGameActionBetOnEnd; action->onEnd = &_pokerGameActionBetOnEnd;
return action; return action;

View File

@ -10,5 +10,6 @@
#include "action.h" #include "action.h"
#include "../../../poker/turn.h" #include "../../../poker/turn.h"
#include "../../../poker/bet.h" #include "../../../poker/bet.h"
#include "../../../poker/actions/flop.h"
queueaction_t * pokerGameActionBetAdd(pokergame_t *game); queueaction_t * pokerGameActionBetAdd(pokergame_t *game);

View File

@ -52,4 +52,20 @@ queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker) {
action->data = (void *)poker; action->data = (void *)poker;
action->onStart = &_pokerActionRiverOnStart; action->onStart = &_pokerActionRiverOnStart;
return action; return action;
}
queueaction_t * pokerActionNextFlopAdd(queue_t *queue, poker_t *poker) {
switch(poker->dealer.cardsFacing) {
case 0:
return pokerActionFlopAdd(queue, poker);
case POKER_FLOP_CARD_COUNT:
return pokerActionTurnAdd(queue, poker);
case POKER_FLOP_CARD_COUNT+POKER_TURN_CARD_COUNT:
return pokerActionRiverAdd(queue, poker);
default:
return NULL;
}
} }

View File

@ -50,4 +50,14 @@ queueaction_t * pokerActionTurnAdd(queue_t *queue, poker_t *poker);
* @param poker Poker game instance to river. * @param poker Poker game instance to river.
* @return The queued action. * @return The queued action.
*/ */
queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker); queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker);
/**
* Queues the next type of flop action onto the queue. This will automatically
* select River, Flop or Turn depending on what's happened already.
*
* @param queue Queue to add to.
* @param poker Poker game instance
* @return The queued action.
*/
queueaction_t * pokerActionNextFlopAdd(queue_t *queue, poker_t *poker);

View File

@ -10,6 +10,7 @@
pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) { pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
pokerturn_t turn; pokerturn_t turn;
pokerplayer_t *player; pokerplayer_t *player;
bool canCheck;
player = poker->players + playerIndex; player = poker->players + playerIndex;
@ -18,10 +19,16 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
if(player->state & POKER_PLAYER_STATE_FOLDED) return turn; if(player->state & POKER_PLAYER_STATE_FOLDED) return turn;
if(player->state & POKER_PLAYER_STATE_OUT) return turn; if(player->state & POKER_PLAYER_STATE_OUT) return turn;
canCheck = player->currentBet >= poker->bet.currentBet;
if(canCheck) {
turn.type = POKER_TURN_TYPE_CHECK;
return turn;
}
// I have nfi // I have nfi
turn.type = POKER_TURN_TYPE_BET; turn.type = POKER_TURN_TYPE_BET;
turn.chips = 1; turn.chips = poker->bet.currentBet - player->currentBet;
turn.confidence = 1; turn.confidence = 1;
return turn; return turn;