71 lines
1.9 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "flop.h"
void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count) {
poker_t *poker;
poker = (poker_t *)action->data;
pokerDealerBurn(&poker->dealer, 1);
pokerDealerTurn(&poker->dealer, count);
printf("Turned %u cards\n", count);
queueNext(queue);
}
void _pokerActionFlopOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
_pokerActionFlopDo(queue, action, POKER_FLOP_CARD_COUNT);
}
void _pokerActionTurnOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
_pokerActionFlopDo(queue, action, POKER_TURN_CARD_COUNT);
}
void _pokerActionRiverOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
_pokerActionFlopDo(queue, action, POKER_RIVER_CARD_COUNT);
}
queueaction_t * pokerActionFlopAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionFlopOnStart;
return action;
}
queueaction_t * pokerActionTurnAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionTurnOnStart;
return action;
}
queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker) {
queueaction_t *action;
action = queueAdd(queue);
action->data = (void *)poker;
action->onStart = &_pokerActionRiverOnStart;
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;
}
}