Split the bet tests out.
This commit is contained in:
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -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);
|
@ -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;
|
||||
}
|
@ -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);
|
@ -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
|
||||
|
@ -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.
|
||||
|
186
test/poker/bet.c
Normal file
186
test/poker/bet.c
Normal file
@ -0,0 +1,186 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "bet.h"
|
||||
|
||||
void test_pokerBetGetNextPlayer_should_GetTheNextBetter(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2, p3, p4;
|
||||
pokerInit(&poker);
|
||||
|
||||
p0 = pokerPlayerAdd(&poker);
|
||||
p1 = pokerPlayerAdd(&poker);
|
||||
p2 = pokerPlayerAdd(&poker);
|
||||
p3 = pokerPlayerAdd(&poker);
|
||||
p4 = pokerPlayerAdd(&poker);
|
||||
|
||||
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p3, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p4, 10000);
|
||||
pokerDealerNew(&poker);
|
||||
|
||||
// Start at blind+1
|
||||
poker.better = poker.playerBigBlind;
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x04, poker.better);
|
||||
|
||||
// Blind+2
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, poker.better);
|
||||
|
||||
// BLind+3
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, poker.better);
|
||||
|
||||
// Dealer
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, poker.better);
|
||||
|
||||
// Small blind
|
||||
pokerBetForPlayer(
|
||||
&poker, poker.better,
|
||||
pokerBetGetCurrentCallValue(&poker) - poker.players[0x02].currentBet
|
||||
);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x03, poker.better);
|
||||
|
||||
// Big Blind
|
||||
pokerBetForPlayer(
|
||||
&poker, poker.better,
|
||||
pokerBetGetCurrentCallValue(&poker) - poker.players[0x03].currentBet
|
||||
);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0xFF, poker.better);
|
||||
|
||||
// Raise
|
||||
poker.better = poker.playerBigBlind;
|
||||
pokerBetForPlayer(&poker, poker.better, 100);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x04, poker.better);
|
||||
|
||||
// Raise
|
||||
pokerBetForPlayer(&poker, poker.better, 100);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, poker.better);
|
||||
}
|
||||
|
||||
void test_pokerBetGetRemainingBetterCount_should_ReturnCountNeedsToBet(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, pokerBetGetRemainingBetterCount(&poker));
|
||||
|
||||
pokerPlayerChipsAdd(poker.players + p0, 1000);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, pokerBetGetRemainingBetterCount(&poker));
|
||||
pokerPlayerChipsAdd(poker.players + p2, 1000);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, pokerBetGetRemainingBetterCount(&poker));
|
||||
pokerPlayerChipsAdd(poker.players + p1, 1000);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x03, pokerBetGetRemainingBetterCount(&poker));
|
||||
|
||||
poker.players[0].state |= POKER_PLAYER_STATE_FOLDED;
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, pokerBetGetRemainingBetterCount(&poker));
|
||||
poker.players[1].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, pokerBetGetRemainingBetterCount(&poker));
|
||||
poker.players[2].chips = 0;
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, pokerBetGetRemainingBetterCount(&poker));
|
||||
}
|
||||
|
||||
void test_pokerBet_should_AddChipsToThePot(void) {
|
||||
poker_t poker;
|
||||
pokerpot_t *pot;
|
||||
pokerplayer_t *player;
|
||||
uint8_t i;
|
||||
|
||||
pokerInit(&poker);
|
||||
pot = poker.pots;
|
||||
i = pokerPlayerAdd(&poker);
|
||||
player = poker.players + i;
|
||||
pokerPlayerChipsAdd(player, 1000);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->call);
|
||||
TEST_ASSERT_EQUAL_INT32(1000, player->chips);
|
||||
|
||||
pokerBet(&poker, pot, i, 100);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->call);
|
||||
TEST_ASSERT_EQUAL_INT32(900, player->chips);
|
||||
|
||||
pokerBet(&poker, pot, i, 100);
|
||||
TEST_ASSERT_EQUAL_INT32(200, pot->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->call);
|
||||
TEST_ASSERT_EQUAL_INT32(800, player->chips);
|
||||
}
|
||||
|
||||
void test_pokerBet_should_UpdatePlayerState(void) {
|
||||
poker_t poker;
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
|
||||
pokerInit(&poker);
|
||||
i = pokerPlayerAdd(&poker);
|
||||
player = poker.players + i;
|
||||
pokerPlayerChipsAdd(player, 1000);
|
||||
|
||||
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, player->state);
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->currentBet);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, player->timesRaised);
|
||||
|
||||
pokerBet(&poker, poker.pots, i, 100);
|
||||
TEST_ASSERT_BITS_HIGH(POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, player->state);
|
||||
TEST_ASSERT_EQUAL_INT32(100, player->currentBet);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, player->timesRaised);
|
||||
|
||||
pokerBet(&poker, poker.pots, i, 250);
|
||||
TEST_ASSERT_EQUAL_INT32(350, player->currentBet);
|
||||
TEST_ASSERT_EQUAL_UINT8(2, player->timesRaised);
|
||||
}
|
||||
|
||||
void test_pokerBetForPlayer_should_BetToTheActivePot(void) {
|
||||
poker_t poker;
|
||||
pokerpot_t *pot;
|
||||
uint8_t i, j;
|
||||
|
||||
pokerInit(&poker);
|
||||
i = pokerPlayerAdd(&poker);
|
||||
pokerPlayerChipsAdd(poker.players+i, 1000);
|
||||
pot = poker.pots;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
||||
pokerBetForPlayer(&poker, i, 100);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
||||
|
||||
j = pokerPotAdd(&poker);
|
||||
pokerBetForPlayer(&poker, i, 50);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
||||
pot = poker.pots + j;
|
||||
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
|
||||
}
|
||||
|
||||
|
||||
int test_bet_h() {
|
||||
UNITY_BEGIN();
|
||||
|
||||
// RUN_TEST(test_pokerBetGetRemainingPlayer_should_ReturnRemainingBetters);
|
||||
RUN_TEST(test_pokerBetGetNextPlayer_should_GetTheNextBetter);
|
||||
RUN_TEST(test_pokerBetGetRemainingBetterCount_should_ReturnCountNeedsToBet);
|
||||
RUN_TEST(test_pokerBet_should_AddChipsToThePot);
|
||||
RUN_TEST(test_pokerBet_should_UpdatePlayerState);
|
||||
RUN_TEST(test_pokerBetForPlayer_should_BetToTheActivePot);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
10
test/poker/bet.h
Normal file
10
test/poker/bet.h
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright (c) 2021 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include <unity.h>
|
||||
#include <poker/bet.h>
|
||||
|
||||
int test_bet_h();
|
@ -220,7 +220,7 @@ void test_pokerTakeBlinds_should_TakeTheBlinds(void) {
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 3)->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 4)->chips);
|
||||
|
||||
pokerTakeBlinds(&poker, 100, 200);
|
||||
pokerTakeBlinds(&poker);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 0)->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 1)->chips);
|
||||
@ -229,7 +229,7 @@ void test_pokerTakeBlinds_should_TakeTheBlinds(void) {
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 4)->chips);
|
||||
|
||||
pokerDealerNew(&poker);
|
||||
pokerTakeBlinds(&poker, 100, 200);
|
||||
pokerTakeBlinds(&poker);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 0)->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(1000, (poker.players + 1)->chips);
|
||||
@ -257,6 +257,7 @@ void test_pokerPotAdd_should_ResetThePot(void) {
|
||||
pot = poker.pots + i;
|
||||
TEST_ASSERT_EQUAL_UINT8(0, pot->playerCount);
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->call);
|
||||
}
|
||||
|
||||
void test_pokerPotHasPlayer_should_DetermineIfPlayerInThePot(void) {
|
||||
@ -647,125 +648,6 @@ void test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers(void) {
|
||||
TEST_ASSERT_EQUAL(false, pokerPlayerDoesNeedToBetThisRound(&poker, second));
|
||||
}
|
||||
|
||||
void test_pokerBetGetRemainingPlayer_should_ReturnRemainingBetters(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2, p3, p4;
|
||||
pokerInit(&poker);
|
||||
|
||||
|
||||
p0 = pokerPlayerAdd(&poker);
|
||||
p1 = pokerPlayerAdd(&poker);
|
||||
p2 = pokerPlayerAdd(&poker);
|
||||
p3 = pokerPlayerAdd(&poker);
|
||||
p4 = pokerPlayerAdd(&poker);
|
||||
|
||||
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p3, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p4, 10000);
|
||||
pokerDealerNew(&poker);
|
||||
|
||||
// Blind + 1
|
||||
TEST_ASSERT_EQUAL(0x04, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 2
|
||||
pokerBetForPlayer(&poker, 0x04, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL(0x00, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 3
|
||||
pokerBetForPlayer(&poker, 0x00, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL(0x01, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 4 / Small Blind
|
||||
pokerBetForPlayer(&poker, 0x01, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL(0x02, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 5 / Big Blind
|
||||
pokerBetForPlayer(
|
||||
&poker, 0x02, pokerBetGetCurrentCallValue(&poker) - poker.players[0x01].currentBet
|
||||
);
|
||||
TEST_ASSERT_EQUAL(0x03, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// No remaining players.
|
||||
pokerBetForPlayer(&poker, 0x03, 0);
|
||||
TEST_ASSERT_EQUAL(0xFF, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Raise
|
||||
pokerBetForPlayer(&poker, 0x03, 100);
|
||||
TEST_ASSERT_EQUAL(0x04, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Raise
|
||||
pokerBetForPlayer(&poker, 0x04, 100);
|
||||
TEST_ASSERT_EQUAL(0x00, pokerBetGetRemainingPlayer(&poker));
|
||||
}
|
||||
|
||||
void test_pokerBetGetNextPlayer_should_GetTheNextBetter(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2, p3, p4;
|
||||
pokerInit(&poker);
|
||||
|
||||
p0 = pokerPlayerAdd(&poker);
|
||||
p1 = pokerPlayerAdd(&poker);
|
||||
p2 = pokerPlayerAdd(&poker);
|
||||
p3 = pokerPlayerAdd(&poker);
|
||||
p4 = pokerPlayerAdd(&poker);
|
||||
|
||||
pokerPlayerChipsAdd(poker.players + p0, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p1, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p2, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p3, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + p4, 10000);
|
||||
pokerDealerNew(&poker);
|
||||
|
||||
// Start at blind+1
|
||||
poker.better = poker.playerBigBlind;
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x04, poker.better);
|
||||
|
||||
// Blind+2
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, poker.better);
|
||||
|
||||
// BLind+3
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, poker.better);
|
||||
|
||||
// Dealer
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, poker.better);
|
||||
|
||||
// Small blind
|
||||
pokerBetForPlayer(
|
||||
&poker, poker.better,
|
||||
pokerBetGetCurrentCallValue(&poker) - poker.players[0x02].currentBet
|
||||
);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x03, poker.better);
|
||||
|
||||
// Big Blind
|
||||
pokerBetForPlayer(
|
||||
&poker, poker.better,
|
||||
pokerBetGetCurrentCallValue(&poker) - poker.players[0x03].currentBet
|
||||
);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0xFF, poker.better);
|
||||
|
||||
// Raise
|
||||
poker.better = poker.playerBigBlind;
|
||||
pokerBetForPlayer(&poker, poker.better, 100);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x04, poker.better);
|
||||
|
||||
// Raise
|
||||
pokerBetForPlayer(&poker, poker.better, 100);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, poker.better);
|
||||
}
|
||||
|
||||
void test_pokerPlayerGetCallBet_should_GetCallBet(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2;
|
||||
@ -817,94 +699,6 @@ void test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, pokerInRoundGetCount(&poker));
|
||||
}
|
||||
|
||||
void test_pokerBetGetRemainingPlayerCount_should_ReturnCountNeedsToBet(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, pokerBetGetRemainingPlayerCount(&poker));
|
||||
|
||||
pokerPlayerChipsAdd(poker.players + p0, 1000);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, pokerBetGetRemainingPlayerCount(&poker));
|
||||
pokerPlayerChipsAdd(poker.players + p2, 1000);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, pokerBetGetRemainingPlayerCount(&poker));
|
||||
pokerPlayerChipsAdd(poker.players + p1, 1000);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x03, pokerBetGetRemainingPlayerCount(&poker));
|
||||
|
||||
poker.players[0].state |= POKER_PLAYER_STATE_FOLDED;
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, pokerBetGetRemainingPlayerCount(&poker));
|
||||
poker.players[1].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, pokerBetGetRemainingPlayerCount(&poker));
|
||||
poker.players[2].chips = 0;
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, pokerBetGetRemainingPlayerCount(&poker));
|
||||
}
|
||||
|
||||
void test_pokerBet_should_AddChipsToThePot(void) {
|
||||
poker_t poker;
|
||||
pokerpot_t *pot;
|
||||
pokerplayer_t *player;
|
||||
uint8_t i;
|
||||
|
||||
pokerInit(&poker);
|
||||
pot = poker.pots;
|
||||
i = pokerPlayerAdd(&poker);
|
||||
player = poker.players + i;
|
||||
pokerPlayerChipsAdd(player, 1000);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(1000, player->chips);
|
||||
|
||||
pokerBet(&poker, pot, i, 100);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
||||
TEST_ASSERT_EQUAL_INT32(900, player->chips);
|
||||
}
|
||||
|
||||
void test_pokerBet_should_UpdatePlayerState(void) {
|
||||
poker_t poker;
|
||||
uint8_t i;
|
||||
pokerplayer_t *player;
|
||||
|
||||
pokerInit(&poker);
|
||||
i = pokerPlayerAdd(&poker);
|
||||
player = poker.players + i;
|
||||
pokerPlayerChipsAdd(player, 1000);
|
||||
|
||||
TEST_ASSERT_BITS_LOW(POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, player->state);
|
||||
TEST_ASSERT_EQUAL_INT32(0, player->currentBet);
|
||||
|
||||
pokerBet(&poker, poker.pots, i, 100);
|
||||
TEST_ASSERT_BITS_HIGH(POKER_PLAYER_STATE_HAS_BET_THIS_ROUND, player->state);
|
||||
TEST_ASSERT_EQUAL_INT32(100, player->currentBet);
|
||||
|
||||
pokerBet(&poker, poker.pots, i, 250);
|
||||
TEST_ASSERT_EQUAL_INT32(350, player->currentBet);
|
||||
}
|
||||
|
||||
void test_pokerBetForPlayer_should_BetToTheActivePot(void) {
|
||||
poker_t poker;
|
||||
pokerpot_t *pot;
|
||||
uint8_t i, j;
|
||||
|
||||
pokerInit(&poker);
|
||||
i = pokerPlayerAdd(&poker);
|
||||
pokerPlayerChipsAdd(poker.players+i, 1000);
|
||||
pot = poker.pots;
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, pot->chips);
|
||||
pokerBetForPlayer(&poker, i, 100);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
||||
|
||||
j = pokerPotAdd(&poker);
|
||||
pokerBetForPlayer(&poker, i, 50);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pot->chips);
|
||||
pot = poker.pots + j;
|
||||
TEST_ASSERT_EQUAL_INT32(50, pot->chips);
|
||||
}
|
||||
|
||||
void test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet(void) {
|
||||
poker_t poker;
|
||||
uint8_t p0, p1, p2;
|
||||
@ -1613,14 +1407,8 @@ int test_poker() {
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckCallValue);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_CheckWhetherHasBetYet);
|
||||
RUN_TEST(test_pokerPlayerDoesNeedToBetThisRound_should_IgnoreFoldedPlayers);
|
||||
RUN_TEST(test_pokerBetGetRemainingPlayer_should_ReturnRemainingBetters);
|
||||
RUN_TEST(test_pokerBetGetNextPlayer_should_GetTheNextBetter);
|
||||
RUN_TEST(test_pokerPlayerGetCallBet_should_GetCallBet);
|
||||
RUN_TEST(test_pokerInRoundGetCount_should_ReturnCountOfPlayersInRound);
|
||||
RUN_TEST(test_pokerBetGetRemainingPlayerCount_should_ReturnCountNeedsToBet);
|
||||
RUN_TEST(test_pokerBet_should_AddChipsToThePot);
|
||||
RUN_TEST(test_pokerBet_should_UpdatePlayerState);
|
||||
RUN_TEST(test_pokerBetForPlayer_should_BetToTheActivePot);
|
||||
RUN_TEST(test_pokerPlayerCanCheck_should_CompareThePotAndPlayerBet);
|
||||
RUN_TEST(test_pokerTurnFold_should_ReturnAFoldAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnACheckAction);
|
||||
|
10
test/tests.c
10
test/tests.c
@ -8,8 +8,10 @@
|
||||
#include "tests.h"
|
||||
|
||||
int32_t main() {
|
||||
return (
|
||||
test_card() ||
|
||||
test_poker()
|
||||
);
|
||||
return test_bet_h();
|
||||
// return (
|
||||
// test_bet
|
||||
// test_card() ||
|
||||
// test_poker()
|
||||
// );
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "poker/bet.h"
|
||||
#include "poker/card.h"
|
||||
#include "poker/poker.h"
|
||||
|
||||
|
Reference in New Issue
Block a user