Still working on updating code to new poker code.
This commit is contained in:
@ -1,68 +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){
|
|
||||||
uint8_t j, indexDealer, indexSmallBlind, indexBigBlind;
|
|
||||||
bool foundDealer, foundSmallBlind;
|
|
||||||
pokerplayer_t *player;
|
|
||||||
poker_t *poker;
|
|
||||||
|
|
||||||
poker = (poker_t *)action->data;
|
|
||||||
|
|
||||||
// Update game state.
|
|
||||||
poker->state = POKER_STATE_STARTING_ROUND;
|
|
||||||
|
|
||||||
// Prepare the initial game state
|
|
||||||
pokerBetReset(&poker->bet);
|
|
||||||
pokerDealerInit(&poker->dealer);
|
|
||||||
|
|
||||||
// Reset the players
|
|
||||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
|
||||||
pokerPlayerReset(poker->players + i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decide on the dealer
|
|
||||||
poker->roundDealer = (poker->roundDealer+1) % POKER_PLAYER_COUNT;
|
|
||||||
|
|
||||||
// Find (and kill) the players.
|
|
||||||
j = poker->roundDealer;
|
|
||||||
foundDealer = false;
|
|
||||||
foundSmallBlind = false;
|
|
||||||
while(true) {
|
|
||||||
player = poker->players + j;
|
|
||||||
|
|
||||||
if(!pokerPlayerIsInRound(player)) continue;
|
|
||||||
if(!foundDealer) {
|
|
||||||
indexDealer = j;
|
|
||||||
foundDealer = true;
|
|
||||||
} else if(!foundSmallBlind) {
|
|
||||||
indexSmallBlind = j;
|
|
||||||
foundSmallBlind = true;
|
|
||||||
} else {
|
|
||||||
indexBigBlind = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
j = (j + 1) % POKER_PLAYER_COUNT;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update players for the round.
|
|
||||||
poker->roundDealer = indexDealer;
|
|
||||||
poker->roundBigBlind = indexBigBlind;
|
|
||||||
poker->roundSmallBlind = indexSmallBlind;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -13,46 +13,47 @@ void _pokerGameActionBetOnStart(
|
|||||||
bool isHuman;
|
bool isHuman;
|
||||||
pokergame_t *game = (pokergame_t *)action->data;
|
pokergame_t *game = (pokergame_t *)action->data;
|
||||||
|
|
||||||
|
//TODO: Fix this whole filee
|
||||||
// Reset the UI state.
|
// Reset the UI state.
|
||||||
isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
|
// isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
|
||||||
if(isHuman) pokerUiBetShow(&game->ui);
|
// if(isHuman) pokerUiBetShow(&game->ui);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _pokerGameActionBetOnUpdate(
|
void _pokerGameActionBetOnUpdate(
|
||||||
queue_t *queue, queueaction_t *action, uint8_t i
|
queue_t *queue, queueaction_t *action, uint8_t i
|
||||||
) {
|
) {
|
||||||
// Restack
|
// Restack
|
||||||
bool isHuman;
|
// bool isHuman;
|
||||||
bool turnMade = false;
|
// bool turnMade = false;
|
||||||
pokerturn_t turn;
|
// pokerturn_t turn;
|
||||||
pokergame_t *game = (pokergame_t *)action->data;
|
// pokergame_t *game = (pokergame_t *)action->data;
|
||||||
pokerplayer_t *player;
|
// pokerplayer_t *player;
|
||||||
pokerdiscussiondata_t discussion;
|
// pokerdiscussiondata_t discussion;
|
||||||
|
|
||||||
// Are they human?
|
// // Are they human?
|
||||||
player = game->poker.players + game->poker.bet.better;
|
// player = game->poker.players + game->poker.bet.better;
|
||||||
isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
|
// isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
|
||||||
|
|
||||||
// Handle as an AI
|
// // Handle as an AI
|
||||||
if(isHuman) {
|
// if(isHuman) {
|
||||||
turn = game->ui.betTurn;
|
// turn = game->ui.betTurn;
|
||||||
turnMade = game->ui.betTurnMade;
|
// turnMade = game->ui.betTurnMade;
|
||||||
} else {
|
// } else {
|
||||||
turn = pokerTurnGet(&game->poker, game->poker.bet.better);
|
// turn = pokerTurnGet(&game->poker, game->poker.bet.better);
|
||||||
turnMade = true;
|
// turnMade = true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Now decide if we should do something.
|
// // Now decide if we should do something.
|
||||||
if(!turnMade) return;
|
// if(!turnMade) return;
|
||||||
|
|
||||||
// Perform the action
|
// // Perform the action
|
||||||
pokerTurnAction(&game->poker, player, &turn);
|
// pokerTurnAction(&game->poker, player, &turn);
|
||||||
|
|
||||||
// Speak
|
// // Speak
|
||||||
discussion.reason = pokerDiscussionGetTypeFromTurnType(turn.type);
|
// discussion.reason = pokerDiscussionGetTypeFromTurnType(turn.type);
|
||||||
discussion.poker = game;
|
// discussion.poker = game;
|
||||||
discussion.playerCause = game->poker.bet.better;
|
// discussion.playerCause = game->poker.bet.better;
|
||||||
pokerDiscussionQueue(&discussion);
|
// pokerDiscussionQueue(&discussion);
|
||||||
|
|
||||||
// Next.
|
// Next.
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
@ -63,20 +64,20 @@ void _pokerGameActionBetOnEnd(
|
|||||||
) {
|
) {
|
||||||
pokergame_t *game = (pokergame_t *)action->data;
|
pokergame_t *game = (pokergame_t *)action->data;
|
||||||
|
|
||||||
// Get which player is remaining to move.
|
// // Get which player is remaining to move.
|
||||||
game->poker.bet.better = pokerBetGetRemainingPlayer(
|
// game->poker.bet.better = pokerBetGetRemainingPlayer(
|
||||||
&game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
// &game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
||||||
);
|
// );
|
||||||
|
|
||||||
// Restack
|
// // Restack
|
||||||
pokerGameActionRestackAdd(game);
|
// pokerGameActionRestackAdd(game);
|
||||||
|
|
||||||
// Are we waiting on any players?
|
// // Are we waiting on any players?
|
||||||
if(game->poker.bet.better != 0xFF) {
|
// if(game->poker.bet.better != 0xFF) {
|
||||||
pokerGameActionLookAdd(game, game->poker.bet.better);
|
// pokerGameActionLookAdd(game, game->poker.bet.better);
|
||||||
pokerGameActionBetAdd(game);
|
// pokerGameActionBetAdd(game);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Not waiting, do next action.
|
// Not waiting, do next action.
|
||||||
pokerGameActionFlopAdd(game);
|
pokerGameActionFlopAdd(game);
|
||||||
|
@ -18,9 +18,9 @@ void _pokerGameActionFlopOnStart(
|
|||||||
discussion.poker = game;
|
discussion.poker = game;
|
||||||
|
|
||||||
// Get how many players are left in the round.
|
// Get how many players are left in the round.
|
||||||
if(pokerPlayerGetCountInRound(game->poker.players) > 1) {// Still more than 1
|
if(pokerInRoundGetCount(game->poker.players) > 1) {// Still more than 1
|
||||||
// Add the actual flop action.
|
// Add the actual flop action.
|
||||||
next = pokerActionNextFlopAdd(queue, &game->poker);
|
// next = pokerActionNextFlopAdd(queue, &game->poker);
|
||||||
|
|
||||||
// Reset all the players
|
// Reset all the players
|
||||||
|
|
||||||
@ -30,23 +30,21 @@ void _pokerGameActionFlopOnStart(
|
|||||||
discussion.reason = POKER_DISCUSSION_REASON_FLOP;
|
discussion.reason = POKER_DISCUSSION_REASON_FLOP;
|
||||||
pokerDiscussionQueue(&discussion);
|
pokerDiscussionQueue(&discussion);
|
||||||
|
|
||||||
// Reset the better to the betting round initial.
|
// //TODO: Get the next player here.
|
||||||
pokerBetResetBetter(
|
// pokerPlayerGetRemainingBetter(&poker);
|
||||||
&game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
|
||||||
);
|
|
||||||
|
|
||||||
// Now, get the count of players left to bet. If "everyone is all in" then
|
// // Now, get the count of players left to bet. If "everyone is all in" then
|
||||||
// this will be 0 and no actual betting needs to happen.
|
// // this will be 0 and no actual betting needs to happen.
|
||||||
if(pokerBetGetRemainingPlayerCount(
|
// if(pokerBetGetRemainingPlayerCount(
|
||||||
&game->poker.bet, game->poker.players
|
// &game->poker.bet, game->poker.players
|
||||||
) > 1) {
|
// ) > 1) {
|
||||||
// Begin betting.
|
// // Begin betting.
|
||||||
pokerGameActionLookAdd(game, game->poker.bet.better);
|
// pokerGameActionLookAdd(game, game->poker.bet.better);
|
||||||
pokerGameActionBetAdd(game);
|
// pokerGameActionBetAdd(game);
|
||||||
} else {
|
// } else {
|
||||||
//No actual players to bet, so add the following flop instead.
|
// //No actual players to bet, so add the following flop instead.
|
||||||
pokerGameActionFlopAdd(game);
|
// pokerGameActionFlopAdd(game);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Do next action.
|
// Do next action.
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
|
@ -41,9 +41,11 @@ 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
|
// Begin Betting Round. This will queue for one player only and then the round
|
||||||
// will take over.
|
// will take over.
|
||||||
pokerBetResetBetter(
|
|
||||||
&game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
// TODO: finish
|
||||||
);
|
// pokerBetResetBetter(
|
||||||
|
// &game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
||||||
|
// );
|
||||||
pokerGameActionBetAdd(game);
|
pokerGameActionBetAdd(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,6 @@ void _pokerGameActionStartOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
|
|||||||
pokerdiscussiondata_t data;
|
pokerdiscussiondata_t data;
|
||||||
pokergame_t *game = (pokergame_t *)action->data;
|
pokergame_t *game = (pokergame_t *)action->data;
|
||||||
|
|
||||||
// Begin the match
|
|
||||||
pokerInit(&game->poker);
|
|
||||||
|
|
||||||
// Say that.
|
// Say that.
|
||||||
data.poker = game;
|
data.poker = game;
|
||||||
data.reason = POKER_DISCUSSION_REASON_MATCH_START;
|
data.reason = POKER_DISCUSSION_REASON_MATCH_START;
|
||||||
|
@ -14,14 +14,15 @@ void _pokerGameActionWinnerOnStart(
|
|||||||
pokergame_t *game = (pokergame_t *)action->data;
|
pokergame_t *game = (pokergame_t *)action->data;
|
||||||
|
|
||||||
// Calculate the winners
|
// Calculate the winners
|
||||||
pokerWinnerCalculate(
|
// TODO: Calculate Winners
|
||||||
&game->poker.winner,
|
// pokerWinnerCalculate(
|
||||||
&game->poker.dealer,
|
// &game->poker.winner,
|
||||||
game->poker.players
|
// &game->poker.dealer,
|
||||||
);
|
// game->poker.players
|
||||||
|
// );
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
pokerGameWin(&game->poker);
|
// pokerGameWin(&game->poker);
|
||||||
|
|
||||||
// Say stuff
|
// Say stuff
|
||||||
discussion.reason = POKER_DISCUSSION_REASON_BETTING_DONE;
|
discussion.reason = POKER_DISCUSSION_REASON_BETTING_DONE;
|
||||||
|
@ -10,13 +10,12 @@
|
|||||||
void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) {
|
void _pokerActionBlindsOnStart(queue_t *queue,queueaction_t *action,uint8_t i) {
|
||||||
poker_t *poker;
|
poker_t *poker;
|
||||||
poker = (poker_t *)action->data;
|
poker = (poker_t *)action->data;
|
||||||
poker->state = POKER_STATE_TAKING_BLINDS;
|
|
||||||
pokerBetTakeBlinds(
|
// TODO: Fix State
|
||||||
&poker->bet,
|
// poker->state = POKER_STATE_TAKING_BLINDS;
|
||||||
poker->players,
|
// TODO: Fix Blinds
|
||||||
poker->roundSmallBlind,
|
// pokerTakeBlinds(&poker, poker->blindSmall, poker->blindBig);
|
||||||
poker->roundBigBlind
|
|
||||||
);
|
|
||||||
printf("Taken Blinds\n");
|
printf("Taken Blinds\n");
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
}
|
}
|
@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../bet.h"
|
|
||||||
#include "../poker.h"
|
#include "../poker.h"
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../display/animation/queue.h"
|
#include "../../display/animation/queue.h"
|
@ -11,13 +11,13 @@ void _pokerActionDealOnStart(queue_t *queue, queueaction_t *action, uint8_t i) {
|
|||||||
poker_t *poker;
|
poker_t *poker;
|
||||||
poker = (poker_t *)action->data;
|
poker = (poker_t *)action->data;
|
||||||
|
|
||||||
|
|
||||||
// Shuffle the deck
|
// Shuffle the deck
|
||||||
poker->state = POKER_STATE_DEALING;
|
// TODO: State yknow
|
||||||
cardShuffle(poker->dealer.deck, CARD_DECK_SIZE);
|
// poker->state = POKER_STATE_DEALING;
|
||||||
|
cardShuffle(poker->deck, CARD_DECK_SIZE);
|
||||||
|
|
||||||
// Deal 2 card to each player
|
// Deal 2 card to each player
|
||||||
pokerDealerDealAll(&poker->dealer, poker->players, POKER_DEAL_CARD_EACH);
|
pokerPlayerDealAll(poker, POKER_PLAYER_HAND_SIZE_MAX);
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../display/animation/queue.h"
|
#include "../../display/animation/queue.h"
|
||||||
#include "../dealer.h"
|
|
||||||
#include "../poker.h"
|
#include "../poker.h"
|
||||||
|
|
||||||
/** Callback for the deal action */
|
/** Callback for the deal action */
|
@ -11,10 +11,10 @@ void _pokerActionFlopDo(queue_t *queue, queueaction_t *action, uint8_t count) {
|
|||||||
poker_t *poker;
|
poker_t *poker;
|
||||||
poker = (poker_t *)action->data;
|
poker = (poker_t *)action->data;
|
||||||
|
|
||||||
poker->state = POKER_STATE_CARDS_FLOPPING;
|
// TODO: Fix State
|
||||||
|
// poker->state = POKER_STATE_CARDS_FLOPPING;
|
||||||
pokerDealerBurn(&poker->dealer, POKER_FLOP_BURN_COUNT);
|
pokerBurn(&poker, POKER_FLOP_BURN_COUNT);
|
||||||
pokerDealerTurn(&poker->dealer, count);
|
pokerTurn(&poker, count);
|
||||||
|
|
||||||
printf("Turned %u cards\n", count);
|
printf("Turned %u cards\n", count);
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
@ -57,17 +57,19 @@ queueaction_t * pokerActionRiverAdd(queue_t *queue, poker_t *poker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
queueaction_t * pokerActionNextFlopAdd(queue_t *queue, poker_t *poker) {
|
queueaction_t * pokerActionNextFlopAdd(queue_t *queue, poker_t *poker) {
|
||||||
switch(poker->dealer.cardsFacing) {
|
// switch(poker->dealer.cardsFacing) {
|
||||||
case 0:
|
// case 0:
|
||||||
return pokerActionFlopAdd(queue, poker);
|
// return pokerActionFlopAdd(queue, poker);
|
||||||
|
|
||||||
case POKER_FLOP_CARD_COUNT:
|
// case POKER_FLOP_CARD_COUNT:
|
||||||
return pokerActionTurnAdd(queue, poker);
|
// return pokerActionTurnAdd(queue, poker);
|
||||||
|
|
||||||
case POKER_FLOP_CARD_COUNT+POKER_TURN_CARD_COUNT:
|
// case POKER_FLOP_CARD_COUNT+POKER_TURN_CARD_COUNT:
|
||||||
return pokerActionRiverAdd(queue, poker);
|
// return pokerActionRiverAdd(queue, poker);
|
||||||
|
|
||||||
default:
|
// default:
|
||||||
return NULL;
|
// return NULL;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
@ -8,9 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../display/animation/queue.h"
|
#include "../../display/animation/queue.h"
|
||||||
#include "../dealer.h"
|
|
||||||
#include "../poker.h"
|
#include "../poker.h"
|
||||||
#include "../turn.h"
|
|
||||||
|
|
||||||
/** How many cards the dealer should burn before dealing the flop */
|
/** How many cards the dealer should burn before dealing the flop */
|
||||||
#define POKER_FLOP_BURN_COUNT 1
|
#define POKER_FLOP_BURN_COUNT 1
|
@ -13,17 +13,14 @@ void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i){
|
|||||||
|
|
||||||
poker = (poker_t *)action->data;
|
poker = (poker_t *)action->data;
|
||||||
|
|
||||||
poker->state = POKER_STATE_STARTING_MATCH;
|
// TODO: Fix state
|
||||||
|
// poker->state = POKER_STATE_STARTING_MATCH;
|
||||||
|
|
||||||
// Reset the main game state. This does not init the round.
|
// Reset the main game state. This will also init the round.
|
||||||
pokerBetInit(&poker->bet);
|
pokerInit(&poker);
|
||||||
poker->roundDealer = POKER_PLAYER_COUNT-2;
|
|
||||||
|
//TODO: Add Players here
|
||||||
|
|
||||||
// Reset the players
|
|
||||||
for(x = 0; x < POKER_PLAYER_COUNT; x++) {
|
|
||||||
poker->players[x].state = 0x00;
|
|
||||||
poker->players[x].chips = POKER_BET_PLAYER_CHIPS_DEFAULT;
|
|
||||||
}
|
|
||||||
queueNext(queue);
|
queueNext(queue);
|
||||||
}
|
}
|
||||||
|
|
@ -6,7 +6,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../display/animation/queue.h"
|
#include "../../display/animation/queue.h"
|
||||||
#include "../bet.h"
|
|
||||||
#include "../poker.h"
|
#include "../poker.h"
|
||||||
|
|
||||||
/** Callback for when the poker match aciton starts */
|
/** Callback for when the poker match aciton starts */
|
36
src/poker/actions/round.c
Normal file
36
src/poker/actions/round.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* 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){
|
||||||
|
uint8_t j, indexDealer, indexSmallBlind, indexBigBlind;
|
||||||
|
bool foundDealer, foundSmallBlind;
|
||||||
|
pokerplayer_t *player;
|
||||||
|
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;
|
||||||
|
}
|
@ -8,9 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../libs.h"
|
#include "../../libs.h"
|
||||||
#include "../../display/animation/queue.h"
|
#include "../../display/animation/queue.h"
|
||||||
#include "../dealer.h"
|
|
||||||
#include "../bet.h"
|
|
||||||
#include "../player.h"
|
|
||||||
#include "../poker.h"
|
#include "../poker.h"
|
||||||
|
|
||||||
/** Callback for when the poker round start aciton begins. */
|
/** Callback for when the poker round start aciton begins. */
|
@ -192,6 +192,22 @@ int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player) {
|
|||||||
return pokerGetCallValue(poker) - player->currentBet;
|
return pokerGetCallValue(poker) - player->currentBet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t pokerInRoundGetCount(poker_t *poker) {
|
||||||
|
uint8_t i, count;
|
||||||
|
pokerplayer_t *player;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for(i = 0; i < poker->playerCount; i++) {
|
||||||
|
player = poker->players + i;
|
||||||
|
if(player->state & (POKER_PLAYER_STATE_FOLDED | POKER_PLAYER_STATE_OUT)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
// Betting
|
// Betting
|
||||||
void pokerPlayerBetPot(
|
void pokerPlayerBetPot(
|
||||||
poker_t *poker, pokerpot_t *pot, uint8_t playerIndex, int32_t chips
|
poker_t *poker, pokerpot_t *pot, uint8_t playerIndex, int32_t chips
|
||||||
|
@ -85,6 +85,11 @@
|
|||||||
/** The default blind cost for the small blind. (Defaults half big blind) */
|
/** The default blind cost for the small blind. (Defaults half big blind) */
|
||||||
#define POKER_BET_BLIND_SMALL_DEFAULT (POKER_BET_BLIND_BIG_DEFAULT/2)
|
#define POKER_BET_BLIND_SMALL_DEFAULT (POKER_BET_BLIND_BIG_DEFAULT/2)
|
||||||
|
|
||||||
|
/** How many cards are dealt for the flop, turn and river */
|
||||||
|
#define POKER_FLOP_CARD_COUNT 3
|
||||||
|
#define POKER_TURN_CARD_COUNT 1
|
||||||
|
#define POKER_RIVER_CARD_COUNT 1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** Count of chips the player has */
|
/** Count of chips the player has */
|
||||||
int32_t chips;
|
int32_t chips;
|
||||||
@ -317,6 +322,13 @@ uint8_t pokerPlayerGetNextBetter(poker_t *poker, uint8_t current);
|
|||||||
*/
|
*/
|
||||||
int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player);
|
int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the count of players still currently left in the round.
|
||||||
|
*
|
||||||
|
* @param poker Poker game instance.
|
||||||
|
* @return The count of players in the round.
|
||||||
|
*/
|
||||||
|
uint8_t pokerInRoundGetCount(poker_t *poker);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let a player bet chips into the pot.
|
* Let a player bet chips into the pot.
|
||||||
|
@ -60,10 +60,6 @@ void test_pokerResetRound_should_ResetThePlayers(void) {
|
|||||||
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, poker.players[i].state
|
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, poker.players[i].state
|
||||||
);
|
);
|
||||||
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_SHOWING, poker.players[i].state);
|
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_SHOWING, poker.players[i].state);
|
||||||
TEST_ASSERT_EQUAL_UINT8(
|
|
||||||
0xFF - POKER_PLAYER_STATE_FOLDED - POKER_PLAYER_STATE_HAS_BET_THIS_ROUND,
|
|
||||||
poker.players[i].state
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -677,6 +673,32 @@ void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
|
|||||||
TEST_ASSERT_EQUAL_INT32(0, pokerPlayerGetCallBet(&poker,poker.players+p2));
|
TEST_ASSERT_EQUAL_INT32(0, pokerPlayerGetCallBet(&poker,poker.players+p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_pokerInRoundGetCount(void) {
|
||||||
|
poker_t poker;
|
||||||
|
uint8_t p0, p1, p2;
|
||||||
|
|
||||||
|
pokerInit(&poker);
|
||||||
|
p0 = pokerPlayerAdd(&poker);
|
||||||
|
p1 = pokerPlayerAdd(&poker);
|
||||||
|
p2 = pokerPlayerAdd(&poker);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker));
|
||||||
|
|
||||||
|
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x01, pokerInRoundGetCount(&poker));
|
||||||
|
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x02, pokerInRoundGetCount(&poker));
|
||||||
|
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x03, pokerInRoundGetCount(&poker));
|
||||||
|
|
||||||
|
poker.players[0].state |= POKER_PLAYER_STATE_FOLDED;
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x02, pokerInRoundGetCount(&poker));
|
||||||
|
poker.players[1].state |= POKER_PLAYER_STATE_FOLDED;
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x01, pokerInRoundGetCount(&poker));
|
||||||
|
poker.players[2].state |= POKER_PLAYER_STATE_OUT;
|
||||||
|
TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker));
|
||||||
|
}
|
||||||
|
|
||||||
void test_pokerPlayerBetPot_should_AddChipsToThePot(void) {
|
void test_pokerPlayerBetPot_should_AddChipsToThePot(void) {
|
||||||
poker_t poker;
|
poker_t poker;
|
||||||
pokerpot_t *pot;
|
pokerpot_t *pot;
|
||||||
@ -1418,7 +1440,6 @@ void test_pokerWinnerDetermine_should_DecideTheWinnerCorrectly(void) {
|
|||||||
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
TEST_ASSERT_EQUAL_UINT8(1, participants[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int test_poker() {
|
int test_poker() {
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
|
||||||
@ -1448,6 +1469,7 @@ int test_poker() {
|
|||||||
RUN_TEST(test_pokerPlayerGetRemainingBetter_should_ReturnRemainingBetters);
|
RUN_TEST(test_pokerPlayerGetRemainingBetter_should_ReturnRemainingBetters);
|
||||||
RUN_TEST(test_pokerPlayerGetNextBetter_should_GetTheNextBetter);
|
RUN_TEST(test_pokerPlayerGetNextBetter_should_GetTheNextBetter);
|
||||||
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
||||||
|
RUN_TEST(test_pokerInRoundGetCount);
|
||||||
RUN_TEST(test_pokerPlayerBetPot_should_AddChipsToThePot);
|
RUN_TEST(test_pokerPlayerBetPot_should_AddChipsToThePot);
|
||||||
RUN_TEST(test_pokerPlayerBetPot_should_UpdatePlayerState);
|
RUN_TEST(test_pokerPlayerBetPot_should_UpdatePlayerState);
|
||||||
RUN_TEST(test_pokerPlayerBet_should_BetToTheActivePot);
|
RUN_TEST(test_pokerPlayerBet_should_BetToTheActivePot);
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <unity.h>
|
#include <unity.h>
|
||||||
#include <poker2/poker.h>
|
#include <poker/poker.h>
|
||||||
|
|
||||||
int test_poker2();
|
int test_poker();
|
@ -6,11 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "poker/card.h"
|
#include "poker/card.h"
|
||||||
#include "poker2/poker.h"
|
#include "poker/poker.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
return (
|
return (
|
||||||
test_card() ||
|
test_card() ||
|
||||||
test_poker2()
|
test_poker()
|
||||||
) || 0;
|
) || 0;
|
||||||
}
|
}
|
Reference in New Issue
Block a user