From af03b89e5035ffd984a1634f128854e49b77dd39 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 12 Oct 2021 09:25:42 -0700 Subject: [PATCH] More code cleaning. --- src/game/poker/actions/flop.c | 27 ++++++++++--- src/game/poker/actions/flop.h | 1 - src/game/poker/actions/round.c | 12 ++---- src/game/poker/actions/round.h | 2 - src/game/poker/actions/start.c | 8 ++-- src/poker/actions/blinds.c | 26 ------------ src/poker/actions/blinds.h | 23 ----------- src/poker/actions/deal.c | 30 -------------- src/poker/actions/deal.h | 23 ----------- src/poker/actions/flop.c | 73 ---------------------------------- src/poker/actions/flop.h | 66 ------------------------------ src/poker/poker.c | 1 + src/poker/poker.h | 2 + 13 files changed, 32 insertions(+), 262 deletions(-) delete mode 100644 src/poker/actions/blinds.c delete mode 100644 src/poker/actions/blinds.h delete mode 100644 src/poker/actions/deal.c delete mode 100644 src/poker/actions/deal.h delete mode 100644 src/poker/actions/flop.c delete mode 100644 src/poker/actions/flop.h diff --git a/src/game/poker/actions/flop.c b/src/game/poker/actions/flop.c index c1debf37..8d6b6f80 100644 --- a/src/game/poker/actions/flop.c +++ b/src/game/poker/actions/flop.c @@ -12,21 +12,38 @@ void _pokerGameActionFlopOnStart( ) { pokergame_t *game = (pokergame_t *)action->data; pokerdiscussiondata_t discussion; - queueaction_t *next; + bool hasDoneFlop; // Prep convo discussion.poker = game; // Get how many players are left in the round. if(pokerInRoundGetCount(&game->poker) > 1) {// Still more than 1 - // Add the actual flop action. - next = pokerActionNextFlopAdd(queue, &game->poker); - // Reset all the players pokerResetBettingRound(&game->poker); + // Do actual flop action + hasDoneFlop = true; + switch(game->poker.communitySize) { + case 0x00: + pokerBurn(&game->poker, POKER_FLOP_BURN_COUNT); + pokerTurn(&game->poker, POKER_FLOP_CARD_COUNT); + break; + case POKER_FLOP_CARD_COUNT: + pokerBurn(&game->poker, POKER_FLOP_BURN_COUNT); + pokerTurn(&game->poker, POKER_TURN_CARD_COUNT); + break; + case POKER_FLOP_CARD_COUNT+POKER_TURN_CARD_COUNT: + pokerBurn(&game->poker, POKER_FLOP_BURN_COUNT); + pokerTurn(&game->poker, POKER_RIVER_CARD_COUNT); + break; + default: + hasDoneFlop = false; + break; + } + // Is there any flop "left to do" ? - if(next != NULL) { + if(hasDoneFlop) { // Talk about it. discussion.reason = POKER_DISCUSSION_REASON_FLOP; pokerDiscussionQueue(&discussion); diff --git a/src/game/poker/actions/flop.h b/src/game/poker/actions/flop.h index b424802e..eed35b47 100644 --- a/src/game/poker/actions/flop.h +++ b/src/game/poker/actions/flop.h @@ -12,7 +12,6 @@ #include "restack.h" #include "winner.h" #include "bet.h" -#include "../../../poker/actions/flop.h" /** Callback that is fired when the flop action starts */ void _pokerGameActionFlopOnStart( diff --git a/src/game/poker/actions/round.c b/src/game/poker/actions/round.c index e1579e26..2391c20c 100644 --- a/src/game/poker/actions/round.c +++ b/src/game/poker/actions/round.c @@ -20,30 +20,26 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){ // Start the round pokerResetRound(&game->poker); pokerNewDealer(&game->poker); + pokerTakeBlinds(&game->poker, game->poker.blindSmall, game->poker.blindBig); // Speak data.poker = game; data.reason = POKER_DISCUSSION_REASON_ROUND_START; pokerDiscussionQueue(&data); - // Take the blinds. - pokerActionBlindsAdd(queue, &game->poker); - // Speak data.reason = POKER_DISCUSSION_REASON_BLINDS_TAKEN; pokerDiscussionQueue(&data); // Deal - pokerActionDealAdd(queue, &game->poker); + cardShuffle(&game->poker.deck, CARD_DECK_SIZE); + pokerPlayerDealAll(&game->poker, POKER_PLAYER_HAND_SIZE_MAX); // Speak data.reason = POKER_DISCUSSION_REASON_DEAL; pokerDiscussionQueue(&data); - // Begin Betting Round. This will queue for one player only and then the round - // will take over. - - pokerResetBettingRound(&game->poker); + // Begin Betting Round pokerGameActionBetAdd(game); } diff --git a/src/game/poker/actions/round.h b/src/game/poker/actions/round.h index 3f20eb7e..319044d4 100644 --- a/src/game/poker/actions/round.h +++ b/src/game/poker/actions/round.h @@ -5,8 +5,6 @@ #pragma once #include "../../../libs.h" -#include "../../../poker/actions/blinds.h" -#include "../../../poker/actions/deal.h" #include "action.h" #include "../pokerdiscussion.h" #include "bet.h" diff --git a/src/game/poker/actions/start.c b/src/game/poker/actions/start.c index 91041107..5c2f3096 100644 --- a/src/game/poker/actions/start.c +++ b/src/game/poker/actions/start.c @@ -24,12 +24,10 @@ void _pokerGameActionStartOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){ &game->poker, POKER_BET_BLIND_SMALL_DEFAULT, POKER_BET_BLIND_BIG_DEFAULT ); for(j = 0; j < POKER_PLAYER_COUNT_MAX; j++) { - k = pokerPlayerAdd(&game->poker); - pokerPlayerChipsAdd( - game->poker.players + k, - POKER_BET_PLAYER_CHIPS_DEFAULT - ); + k = pokerPlayerAdd(&game->poker); + pokerPlayerChipsAdd(game->poker.players+k, POKER_BET_PLAYER_CHIPS_DEFAULT); } + pokerSetDealer(&game->poker, game->poker.playerCount/2); // Say that. data.poker = game; diff --git a/src/poker/actions/blinds.c b/src/poker/actions/blinds.c deleted file mode 100644 index dd0e6d25..00000000 --- a/src/poker/actions/blinds.c +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "blinds.h" - -void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) { - poker_t *poker; - poker = (poker_t *)action->data; - - pokerTakeBlinds(poker, poker->blindSmall, poker->blindBig); - - printf("Taken Blinds\n"); - queueNext(queue); -} - -queueaction_t * pokerActionBlindsAdd(queue_t *queue, poker_t *poker) { - queueaction_t *action; - action = queueAdd(queue); - action->data = (void *)poker; - action->onStart = &_pokerActionBlindsOnStart; - return action; -} \ No newline at end of file diff --git a/src/poker/actions/blinds.h b/src/poker/actions/blinds.h deleted file mode 100644 index b98ec22b..00000000 --- a/src/poker/actions/blinds.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "../poker.h" -#include "../../libs.h" -#include "../../display/animation/queue.h" - -/** Callback for the blinds action */ -void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i); - -/** - * Adds a blinds action onto the specified queue. - * - * @param queue Queue to add to. - * @param poker Poker game instance to deal. - * @return The queued action. - */ -queueaction_t * pokerActionBlindsAdd(queue_t *queue, poker_t *poker); diff --git a/src/poker/actions/deal.c b/src/poker/actions/deal.c deleted file mode 100644 index 2f3e01c7..00000000 --- a/src/poker/actions/deal.c +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "deal.h" - -void _pokerActionDealOnStart(queue_t *queue, queueaction_t *action, uint8_t i) { - poker_t *poker; - poker = (poker_t *)action->data; - - // Shuffle the deck - // TODO: State yknow - // poker->state = POKER_STATE_DEALING; - cardShuffle(poker->deck, CARD_DECK_SIZE); - - // Deal 2 card to each player - pokerPlayerDealAll(poker, POKER_PLAYER_HAND_SIZE_MAX); - queueNext(queue); -} - -queueaction_t * pokerActionDealAdd(queue_t *queue, poker_t *poker) { - queueaction_t *action; - action = queueAdd(queue); - action->data = (void *)poker; - action->onStart = &_pokerActionDealOnStart; - return action; -} \ No newline at end of file diff --git a/src/poker/actions/deal.h b/src/poker/actions/deal.h deleted file mode 100644 index 1ff53977..00000000 --- a/src/poker/actions/deal.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "../../libs.h" -#include "../../display/animation/queue.h" -#include "../poker.h" - -/** Callback for the deal action */ -void _pokerActionDealOnStart(queue_t *queue, queueaction_t *action, uint8_t i); - -/** - * Adds a deal action onto the specified queue. - * - * @param queue Queue to add to. - * @param poker Poker game instance to deal. - * @return The queued action. - */ -queueaction_t * pokerActionDealAdd(queue_t *queue, poker_t *poker); \ No newline at end of file diff --git a/src/poker/actions/flop.c b/src/poker/actions/flop.c deleted file mode 100644 index 9592aee3..00000000 --- a/src/poker/actions/flop.c +++ /dev/null @@ -1,73 +0,0 @@ -/** - * 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; - - pokerBurn(poker, POKER_FLOP_BURN_COUNT); - pokerTurn(poker, 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->communitySize) { - 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; - } - - return NULL; -} \ No newline at end of file diff --git a/src/poker/actions/flop.h b/src/poker/actions/flop.h deleted file mode 100644 index ddf726ca..00000000 --- a/src/poker/actions/flop.h +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#pragma once -#include "../../libs.h" -#include "../../display/animation/queue.h" -#include "../poker.h" - -/** How many cards the dealer should burn before dealing the flop */ -#define POKER_FLOP_BURN_COUNT 1 - -/** - * Shorthand action callback parser. Takes the queue, action and the intended - * turn count to complete the action. - * - * @param queue Queue that fired the action. - * @param action Action that was fired. - * @param count Count of cards to turn over from the deck. - */ -void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count); - -/** Callbacks for River, Turn and Flop Actions */ -void _pokerActionFlopOnStart(queue_t *queue, queueaction_t *action, uint8_t i); -void _pokerActionTurnOnStart(queue_t *queue, queueaction_t *action, uint8_t i); -void _pokerActionRiverOnStart(queue_t *queue, queueaction_t *action, uint8_t i); - -/** - * Queues a flop action onto the queue. - * - * @param queue Queue to add to. - * @param poker Poker game instance to flop. - * @return The queued action. - */ -queueaction_t * pokerActionFlopAdd(queue_t *queue, poker_t *poker); - -/** - * Queues a turn action onto the queue. - * - * @param queue Queue to add to. - * @param poker Poker game instance to turn. - * @return The queued action. - */ -queueaction_t * pokerActionTurnAdd(queue_t *queue, poker_t *poker); - -/** - * Queues a river action onto the queue. - * - * @param queue Queue to add to. - * @param poker Poker game instance to river. - * @return The queued action. - */ -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); \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index 13b69bb4..2077d9bf 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -103,6 +103,7 @@ void pokerSetDealer(poker_t *poker, uint8_t dealer) { void pokerTakeBlinds(poker_t *poker, int32_t small, int32_t big) { pokerPlayerBet(poker, poker->playerSmallBlind, small); pokerPlayerBet(poker, poker->playerBigBlind, big); + pokerResetBettingRound(poker); } int32_t pokerGetCallValue(poker_t *poker) { diff --git a/src/poker/poker.h b/src/poker/poker.h index 1e32ebd3..0a64559e 100644 --- a/src/poker/poker.h +++ b/src/poker/poker.h @@ -89,6 +89,8 @@ #define POKER_FLOP_CARD_COUNT 3 #define POKER_TURN_CARD_COUNT 1 #define POKER_RIVER_CARD_COUNT 1 +/** How many cards the dealer should burn before dealing the flop */ +#define POKER_FLOP_BURN_COUNT 1 typedef struct { /** Count of chips the player has */