Added basic betting, turns, and added queue restacking

This commit is contained in:
2021-08-13 09:32:15 -07:00
parent 82fe9a7e3c
commit eddc5bfafd
14 changed files with 217 additions and 8 deletions

View File

@ -7,8 +7,102 @@
#include "bet.h"
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
void _pokerGameActionBetOnStart(
queue_t *queue, queueaction_t *action, uint8_t i
) {
}
void _pokerGameActionBetOnUpdate(
queue_t *queue, queueaction_t *action, uint8_t i
) {
bool isHuman;
bool turnMade = false;
pokerturn_t turn;
pokergame_t *game = (pokergame_t *)action->data;
pokerplayer_t *player;
// As of right now the queue should basically be empty besides this item, so
// let's restack
queueRestack(queue);
// Are they human?
player = game->poker.players + game->poker.bet.better;
isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
// Handle as an AI
if(isHuman) {
turn.type = POKER_TURN_TYPE_OUT;
turnMade = true;
} else {
turn = pokerTurnGet(&game->poker, game->poker.bet.better);
turnMade = true;
}
// Now decide if we should do something.
if(!turnMade) return;
// What happened?
char *debugAction;
switch(turn.type) {
// Player bets
case POKER_TURN_TYPE_BET:
debugAction = "betting";
pokerBetPlayer(&game->poker, player, turn.chips);
break;
// Player folds
case POKER_TURN_TYPE_FOLD:
debugAction = "folding";
player->state |= POKER_PLAYER_STATE_FOLDED;
break;
// Player may be out
default:
debugAction = "doing nothing";
break;
}
printf("Player %i is %s.\n", game->poker.bet.better, debugAction);
queueNext(queue);
}
void _pokerGameActionBetOnEnd(
queue_t *queue, queueaction_t *action, uint8_t i
) {
uint8_t j;
pokerplayer_t *player;
pokergame_t *game = (pokergame_t *)action->data;
bool playersPending;
// Go to the next better
game->poker.bet.better = (game->poker.bet.better + 1) % POKER_PLAYER_COUNT;
playersPending = false;
// Check if each player needs to action.
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
player = game->poker.players + j;
if(player->state & POKER_PLAYER_STATE_FOLDED) continue;
if(player->state & POKER_PLAYER_STATE_OUT) continue;
if(player->currentBet >= game->poker.bet.currentBet) continue;
// Yes, this player needs to check, raise or fold
pokerGameActionBetAdd(game);
playersPending = true;
break;
}
// Are we waiting on any players?
if(playersPending) return;
// No! Begin the next flop.
printf("Not waiting on anything\n");
}
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onStart = &_pokerGameActionBetOnStart;
action->onUpdate = &_pokerGameActionBetOnUpdate;
action->onEnd = &_pokerGameActionBetOnEnd;
return action;
}

View File

@ -8,5 +8,7 @@
#pragma once
#include <dawn/dawn.h>
#include "action.h"
#include "../../../poker/turn.h"
#include "../../../poker/bet.h"
queueaction_t * pokerGameActionBetAdd(pokergame_t *game);

View File

@ -35,7 +35,10 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
// Deal
pokerActionDealAdd(queue, &game->poker);
// Begin Betting Round
// Begin Betting Round. This will queue for one player only and then the round
// will take over.
pokerBetResetBetter(&game->poker);
pokerGameActionBetAdd(game);
}
queueaction_t * pokerGameActionRoundAdd(pokergame_t *game) {

View File

@ -6,9 +6,11 @@
#pragma once
#include <dawn/dawn.h>
#include "action.h"
#include "../../../poker/bet.h"
#include "../../../poker/actions/round.h"
#include "../../../poker/actions/blinds.h"
#include "../../../poker/actions/deal.h"
#include "bet.h"
void _pokerGameActionRoundOnStart(
queue_t *queue, queueaction_t *action, uint8_t i