Split the bet tests out.

This commit is contained in:
2021-10-14 22:40:33 -07:00
parent d79929762a
commit 466cb1e2b9
17 changed files with 266 additions and 301 deletions

View File

@ -50,9 +50,9 @@ void _pokerGameActionFlopOnStart(
// 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.
if(pokerBetGetRemainingPlayerCount(&game->poker) > 0x01) {
if(pokerBetGetRemainingBetterCount(&game->poker) > 0x01) {
// Begin betting.
game->poker.better = pokerBetGetRemainingPlayer(&game->poker);
game->poker.better = pokerBetGetNextPlayer(&game->poker);
pokerGameActionLookAdd(game, game->poker.better);
pokerGameActionBetAdd(game);
} else {

View File

@ -20,7 +20,7 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
// Start the round
pokerResetRound(&game->poker);
pokerDealerNew(&game->poker);
pokerTakeBlinds(&game->poker, game->poker.blindSmall, game->poker.blindBig);
pokerTakeBlinds(&game->poker);
// Speak
data.poker = game;
@ -33,7 +33,7 @@ void _pokerGameActionRoundOnEnd(queue_t *queue,queueaction_t *action,uint8_t i){
// Deal
cardShuffle(game->poker.deck, CARD_DECK_SIZE);
pokerPlayerDealAll(&game->poker, POKER_PLAYER_HAND_SIZE_MAX);
pokerDealAllPlayers(&game->poker, POKER_PLAYER_HAND_SIZE_MAX);
// Speak
data.reason = POKER_DISCUSSION_REASON_DEAL;

View File

@ -7,6 +7,7 @@
#include "../../../libs.h"
#include "../../../poker/player.h"
#include "../../../poker/dealer.h"
#include "../../../poker/poker.h"
#include "action.h"
#include "../pokerdiscussion.h"
#include "bet.h"

View File

@ -7,16 +7,6 @@
#include "bet.h"
uint8_t pokerBetGetRemainingPlayer(poker_t *poker) {
uint8_t i, j;
for(i = 0; i < poker->playerCount; i++) {
j = (i + poker->playerBigBlind + 1) % poker->playerCount;
if(pokerPlayerDoesNeedToBetThisRound(poker, j)) return j;
}
return 0xFF;
}
uint8_t pokerBetGetNextPlayer(poker_t *poker) {
uint8_t i, j;
for(i = 0; i < poker->playerCount; i++) {
@ -26,7 +16,7 @@ uint8_t pokerBetGetNextPlayer(poker_t *poker) {
return 0xFF;
}
uint8_t pokerBetGetRemainingPlayerCount(poker_t *poker) {
uint8_t pokerBetGetRemainingBetterCount(poker_t *poker) {
uint8_t i, count;
count = 0;
for(i = 0; i < poker->playerCount; i++) {
@ -41,11 +31,16 @@ void pokerBet(
) {
pokerplayer_t *player;
player = poker->players + playerIndex;
player->chips -= chips;
player->currentBet += chips;
pot->chips += chips;
player->state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
pot->call = mathMax(pot->call, chips);
pokerPotAddPlayer(pot, playerIndex);
player->state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
if(chips > 0) player->timesRaised++;
}
void pokerBetForPlayer(poker_t *poker, uint8_t playerIndex, int32_t chips) {

View File

@ -10,15 +10,6 @@
#include "fuck.h"
#include "poker.h"
/**
* Returns the index of the first player that remains to bet for the current
* round.
*
* @param poker Poker game instance.
* @return The player index of the remaining player, otherwise 0xFF.
*/
uint8_t pokerBetGetRemainingPlayer(poker_t *poker);
/**
* Returns the index of the first player that remains to bet for the current
* round. This is based on whatever current better player index you provide.
@ -29,24 +20,13 @@ uint8_t pokerBetGetRemainingPlayer(poker_t *poker);
*/
uint8_t pokerBetGetNextPlayer(poker_t *poker);
/**
* Get the bet necessary for a specific player to make a call. This takes the
* players current bet and the bet necessary to call into the pot and will
* return the difference.
*
* @param poker Poker game instance.
* @param player Player instance to get the call value for.
* @return The count of chips needed to call into the current active pot.
*/
int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player);
/**
* Returns the count of players remaining to bet.
*
* @param poker Poker game instance.
* @return Count of players left to bet.
*/
uint8_t pokerBetGetRemainingPlayerCount(poker_t *poker);
uint8_t pokerBetGetRemainingBetterCount(poker_t *poker);
/**
* Let a player bet chips into the pot.
@ -75,4 +55,15 @@ void pokerBetForPlayer(poker_t *poker, uint8_t playerIndex, int32_t chips);
* @param poker Poker game instance.
* @return Chips necessary to call the current bet.
*/
int32_t pokerBetGetCurrentCallValue(poker_t *poker);
int32_t pokerBetGetCurrentCallValue(poker_t *poker);
/**
* Get the bet necessary for a specific player to make a call. This takes the
* players current bet and the bet necessary to call into the pot and will
* return the difference.
*
* @param poker Poker game instance.
* @param player Player instance to get the call value for.
* @return The count of chips needed to call into the current active pot.
*/
int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player);

View File

@ -106,6 +106,7 @@ typedef struct {
/** Current bet that the player has done. */
int32_t currentBet;
/** Count of times that the player has raised their bet */
uint8_t timesRaised;
} pokerplayer_t;
@ -129,6 +130,8 @@ typedef struct {
typedef struct {
/** Current pot of chips */
int32_t chips;
/** Current call value for this pot */
int32_t call;
/** Players who are participating in the pot */
uint8_t players[POKER_PLAYER_COUNT_MAX];
uint8_t playerCount;

View File

@ -66,7 +66,7 @@ void pokerResetBettingRound(poker_t *poker) {
// Then we check who's remaining. We do this because the default better may
// have folded already.
poker->better = pokerBetGetRemainingPlayer(poker);
poker->better = pokerBetGetNextPlayer(poker);
}
void pokerTakeBlinds(poker_t *poker) {
@ -87,21 +87,5 @@ uint8_t pokerInRoundGetCount(poker_t *poker) {
count++;
}
return count;
}
// Betting
int32_t pokerPlayerGetPotChipsSum(poker_t *poker, uint8_t playerIndex) {
int32_t count;
uint8_t i;
pokerpot_t *pot;
count = 0;
for(i = 0; i < poker->potCount; i++) {
pot = poker->pots + i;
if(!pokerPotHasPlayer(pot, playerIndex)) continue;
count += pot->chips;
}
return count;
}

View File

@ -65,27 +65,4 @@ void pokerTakeBlinds(poker_t *poker);
* @param poker Poker game instance.
* @return The count of players in the round.
*/
uint8_t pokerInRoundGetCount(poker_t *poker);
/**
* Returns the sum of chips in the pot(s) that the specified player is in. This
* does not consider the pot, player or hand, just the pure sum of chips.
*
* @param poker Poker game instance.
* @param playerIndex Player Index to get the sum of chips from.
* @return The sum of chips from the pots the player is within.
*/
int32_t pokerPlayerGetPotChipsSum(poker_t *poker, uint8_t playerIndex);
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dealer
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Betting
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Pots
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Clearly fucking player related
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Turn
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Winning
uint8_t pokerInRoundGetCount(poker_t *poker);

View File

@ -13,6 +13,7 @@ uint8_t pokerPotAdd(poker_t *poker) {
pot = poker->pots + i;
pot->chips = 0;
pot->playerCount = 0;
pot->call = 0;
return i;
}
@ -26,3 +27,18 @@ void pokerPotAddPlayer(pokerpot_t *pot, uint8_t playerIndex) {
if(pokerPotHasPlayer(pot, playerIndex)) return;
pot->players[pot->playerCount++] = playerIndex;
}
int32_t pokerPotGetSumOfChipsForPlayer(poker_t *poker, uint8_t playerIndex) {
int32_t count;
uint8_t i;
pokerpot_t *pot;
count = 0;
for(i = 0; i < poker->potCount; i++) {
pot = poker->pots + i;
if(!pokerPotHasPlayer(pot, playerIndex)) continue;
count += pot->chips;
}
return count;
}

View File

@ -34,4 +34,14 @@ bool pokerPotHasPlayer(pokerpot_t *pot, uint8_t playerIndex);
* @param pot Pot to add to.
* @param playerIndex Players' index to add to the pot.
*/
void pokerPotAddPlayer(pokerpot_t *pot, uint8_t playerIndex);
void pokerPotAddPlayer(pokerpot_t *pot, uint8_t playerIndex);
/**
* Returns the sum of chips in the pot(s) that the specified player is in. This
* does not consider the pot, player or hand, just the pure sum of chips.
*
* @param poker Poker game instance.
* @param playerIndex Player Index to get the sum of chips from.
* @return The sum of chips from the pots the player is within.
*/
int32_t pokerPotGetSumOfChipsForPlayer(poker_t *poker, uint8_t playerIndex);

View File

@ -107,10 +107,10 @@ pokerturn_t pokerTurnGetForPlayer(poker_t *poker, uint8_t playerIndex) {
// Do they need chips to call, or is it possible to check?
if(callBet > 0) {
potOdds = (float)callBet / (
(float)callBet + (float)pokerPlayerGetPotChipsSum(poker, playerIndex)
(float)callBet + (float)pokerPotGetSumOfChipsForPlayer(poker, playerIndex)
);
} else {
potOdds = 1.0f / (float)pokerBetGetRemainingPlayerCount(poker);
potOdds = 1.0f / (float)pokerBetGetRemainingBetterCount(poker);
}
// Now determine the expected ROI

View File

@ -9,6 +9,7 @@
#include "../libs.h"
#include "fuck.h"
#include "poker.h"
#include "pot.h"
/**
* Return a turn action for the given player to fold.