From 169a4e9632c69865e302fff68b37728f88ca9be2 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 11 Oct 2021 21:07:59 -0700 Subject: [PATCH] Cleaning more code. --- src/game/poker/actions/bet.c | 2 ++ src/game/poker/actions/round.c | 4 ++-- src/game/poker/actions/round.h | 1 + src/game/poker/actions/start.c | 14 ++++++++++++++ src/poker/actions/blinds.c | 5 +---- src/poker/actions/round.c | 32 -------------------------------- src/poker/actions/round.h | 24 ------------------------ src/poker/poker.c | 7 +++++++ src/poker/poker.h | 16 ++++++++++++++-- test/poker/poker.c | 3 ++- 10 files changed, 43 insertions(+), 65 deletions(-) delete mode 100644 src/poker/actions/round.c delete mode 100644 src/poker/actions/round.h diff --git a/src/game/poker/actions/bet.c b/src/game/poker/actions/bet.c index a1e35509..d48a29e8 100644 --- a/src/game/poker/actions/bet.c +++ b/src/game/poker/actions/bet.c @@ -35,6 +35,8 @@ void _pokerGameActionBetOnUpdate( if(isHuman) { // turn = game->ui.betTurn; // turnMade = game->ui.betTurnMade; + turn = pokerTurnGetForPlayer(&game->poker, game->poker.better); + turnMade = true; } else { turn = pokerTurnGetForPlayer(&game->poker, game->poker.better); turnMade = true; diff --git a/src/game/poker/actions/round.c b/src/game/poker/actions/round.c index aaba8322..e1579e26 100644 --- a/src/game/poker/actions/round.c +++ b/src/game/poker/actions/round.c @@ -18,7 +18,8 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){ pokergame_t *game = (pokergame_t *)action->data; // Start the round - pokerActionRoundAdd(queue, &game->poker); + pokerResetRound(&game->poker); + pokerNewDealer(&game->poker); // Speak data.poker = game; @@ -42,7 +43,6 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){ // Begin Betting Round. This will queue for one player only and then the round // will take over. - // TODO: finish pokerResetBettingRound(&game->poker); pokerGameActionBetAdd(game); } diff --git a/src/game/poker/actions/round.h b/src/game/poker/actions/round.h index 319044d4..fd198bf3 100644 --- a/src/game/poker/actions/round.h +++ b/src/game/poker/actions/round.h @@ -5,6 +5,7 @@ #pragma once #include "../../../libs.h" +#include "../../../poker/actions/blinds.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 7469fdc7..91041107 100644 --- a/src/game/poker/actions/start.c +++ b/src/game/poker/actions/start.c @@ -15,8 +15,22 @@ void _pokerGameActionStartOnStart( void _pokerGameActionStartOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){ pokerdiscussiondata_t data; + uint8_t j, k; pokergame_t *game = (pokergame_t *)action->data; + //TODO: Init Players betterer. + pokerInit(&game->poker); + pokerSetBlinds( + &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 + ); + } + // Say that. data.poker = game; data.reason = POKER_DISCUSSION_REASON_MATCH_START; diff --git a/src/poker/actions/blinds.c b/src/poker/actions/blinds.c index ae3646ff..74f2c488 100644 --- a/src/poker/actions/blinds.c +++ b/src/poker/actions/blinds.c @@ -11,10 +11,7 @@ void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) { poker_t *poker; poker = (poker_t *)action->data; - // TODO: Fix State - // poker->state = POKER_STATE_TAKING_BLINDS; - // TODO: Fix Blinds - // pokerTakeBlinds(&poker, poker->blindSmall, poker->blindBig); + pokerTakeBlinds(poker, poker->blindSmall, poker->blindBig); printf("Taken Blinds\n"); queueNext(queue); diff --git a/src/poker/actions/round.c b/src/poker/actions/round.c deleted file mode 100644 index e0ef03d4..00000000 --- a/src/poker/actions/round.c +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2021 Dominic Masters - * - * This software is released under the MIT License. - * https://opensource.org/licenses/MIT - */ - -#include "round.h" - -void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action ,uint8_t i){ - poker_t *poker; - poker = (poker_t *)action->data; - - // TODO: Fix State - // poker->state = POKER_STATE_STARTING_ROUND; - - // Prepare the initial game stat - pokerResetRound(poker); - - // Decide on the dealer - pokerNewDealer(poker); - - queueNext(queue); -} - -queueaction_t * pokerActionRoundAdd(queue_t *queue, poker_t *poker) { - queueaction_t *action; - action = queueAdd(queue); - action->data = (void *)poker; - action->onStart = &_pokerActionRoundOnStart; - return action; -} \ No newline at end of file diff --git a/src/poker/actions/round.h b/src/poker/actions/round.h deleted file mode 100644 index 9b6cdc86..00000000 --- a/src/poker/actions/round.h +++ /dev/null @@ -1,24 +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 when the poker round start aciton begins. */ -void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action, uint8_t i); - -/** - * Queues the round action onto a queue. Round action should be queued at the - * start of every poker round. - * - * @param queue Queue to add to. - * @param poker Poker game instance. - * @return The queued action. - */ -queueaction_t * pokerActionRoundAdd(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 fd74e144..ec2fc8e6 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -13,6 +13,12 @@ void pokerInit(poker_t *poker) { poker->playerSmallBlind = 0; poker->playerBigBlind = 0; pokerResetRound(poker); + pokerSetBlinds(poker, 0, 0); +} + +void pokerSetBlinds(poker_t *poker, int32_t blindSmall, int32_t blindBig) { + poker->blindSmall = blindSmall; + poker->blindBig = blindBig; } void pokerResetRound(poker_t *poker) { @@ -31,6 +37,7 @@ void pokerResetRound(poker_t *poker) { player = poker->players + i; player->cardCount = 0; player->currentBet = 0; + player->timesRaised = 0; player->state &= ~( POKER_PLAYER_STATE_FOLDED | POKER_PLAYER_STATE_HAS_BET_THIS_ROUND | diff --git a/src/poker/poker.h b/src/poker/poker.h index f1c36bd6..4c01c5a3 100644 --- a/src/poker/poker.h +++ b/src/poker/poker.h @@ -80,10 +80,8 @@ /** How many chips each player has by defautl */ #define POKER_BET_PLAYER_CHIPS_DEFAULT 1200 - /** The default blind cost for the big blind. */ #define POKER_BET_BLIND_BIG_DEFAULT 600 - /** The default blind cost for the small blind. (Defaults half big blind) */ #define POKER_BET_BLIND_SMALL_DEFAULT (POKER_BET_BLIND_BIG_DEFAULT/2) @@ -173,6 +171,11 @@ typedef struct { /** Which player is the current active better ? */ uint8_t better; + + /** Size of the small blind */ + int32_t blindSmall; + /** Size of the big blind */ + int32_t blindBig; } poker_t; @@ -183,6 +186,15 @@ typedef struct { */ void pokerInit(poker_t *poker); +/** + * Set the game's current blinds. + * + * @param poker Poker game instance. + * @param blindSmall Small blind value. + * @param blindBig Big blind value. + */ +void pokerSetBlinds(poker_t *poker, int32_t blindSmall, int32_t blindBig); + /** * Reset the poker game instance for the new round. * diff --git a/test/poker/poker.c b/test/poker/poker.c index 2adcb80d..b4e29854 100644 --- a/test/poker/poker.c +++ b/test/poker/poker.c @@ -54,9 +54,9 @@ void test_pokerResetRound_should_ResetThePlayers(void) { for(i = 0; i < poker.playerCount; i++) { TEST_ASSERT_EQUAL_UINT8(0, poker.players[i].cardCount); + TEST_ASSERT_EQUAL_UINT8(0, poker.players[i].timesRaised); TEST_ASSERT_EQUAL_INT32(0, poker.players[i].currentBet); TEST_ASSERT_EQUAL_INT32(100, poker.players[i].chips); - TEST_ASSERT_EQUAL_INT32(100, poker.players[i].chips); TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_FOLDED, poker.players[i].state); TEST_ASSERT_BITS_LOW( POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, poker.players[i].state @@ -288,6 +288,7 @@ void test_pokerPlayerAdd_should_ResetThePlayer(void) { TEST_ASSERT_EQUAL_INT32(0, player->chips); TEST_ASSERT_EQUAL_INT32(0, player->currentBet); TEST_ASSERT_EQUAL_UINT8(0, player->cardCount); + TEST_ASSERT_EQUAL_UINT8(0, poker.players[i].timesRaised); TEST_ASSERT_EQUAL_UINT8(POKER_PLAYER_STATE_OUT, player->state); }