125 lines
3.1 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "bet.h"
void _pokerGameActionBetOnUpdate(
queue_t *queue, queueaction_t *action, uint8_t i
) {
// Restack
bool isHuman;
bool turnMade = false;
pokerturn_t turn;
pokergame_t *game = (pokergame_t *)action->data;
pokerplayer_t *player;
pokerdiscussiondata_t discussion;
// 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_FOLD;
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";
//TODO: Is it a BET or a CALL?
discussion.reason = POKER_DISCUSSION_REASON_PLAYER_RAISING;
pokerBetPlayer(&game->poker, player, turn.chips);
break;
// Player folds
case POKER_TURN_TYPE_FOLD:
debugAction = "folding";
discussion.reason = POKER_DISCUSSION_REASON_PLAYER_FOLDING;
player->state |= POKER_PLAYER_STATE_FOLDED;
break;
// Player checks
case POKER_TURN_TYPE_CHECK:
discussion.reason = POKER_DISCUSSION_REASON_PLAYER_CHECKING;
debugAction = "checking";
break;
// Player may be out
default:
discussion.reason = POKER_DISCUSSION_REASON_TEST;
debugAction = "doing nothing";
break;
}
// Mark as move made.
player->state |= POKER_PLAYER_STATE_ROUND_MOVE;
// Speak
discussion.poker = game;
discussion.playerCause = game->poker.bet.better;
pokerDiscussionQueue(&discussion);
// Next.
printf("Player %i is %s.\n", game->poker.bet.better, debugAction);
queueNext(queue);
}
void _pokerGameActionBetOnEnd(
queue_t *queue, queueaction_t *action, uint8_t i
) {
queueaction_t *next;
pokerdiscussiondata_t discussion;
pokergame_t *game = (pokergame_t *)action->data;
// Get which player is remaining to move.
game->poker.bet.better = pokerBetGetRemainingPlayer(&game->poker);
// Restack
pokerGameActionRestackAdd(game);
// Are we waiting on any players?
if(game->poker.bet.better != 0xFF) {
pokerGameActionBetAdd(game);
return;
}
// Not waiting, restack and do next action.
printf("Not waiting on anything!\n");
// No! Begin the next flop.
next = pokerActionNextFlopAdd(queue, &game->poker);
if(next != NULL) {
discussion.reason = POKER_DISCUSSION_REASON_FLOP;
discussion.poker = game;
pokerDiscussionQueue(&discussion);
pokerBetResetBetter(&game->poker);
pokerGameActionRestackAdd(game);
pokerGameActionBetAdd(game);
return;
}
/** Queue a restack */
printf("All betting is done, reveal\n");
}
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
queueaction_t *action = pokerGameActionAdd(game);
action->onUpdate = &_pokerGameActionBetOnUpdate;
action->onEnd = &_pokerGameActionBetOnEnd;
return action;
}