Cleaning more code.

This commit is contained in:
2021-10-11 21:07:59 -07:00
parent 8bbfcf7c43
commit 169a4e9632
10 changed files with 43 additions and 65 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -5,6 +5,7 @@
#pragma once
#include "../../../libs.h"
#include "../../../poker/actions/blinds.h"
#include "action.h"
#include "../pokerdiscussion.h"
#include "bet.h"

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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 |

View File

@ -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.
*

View File

@ -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);
}