Cleaning more.
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
|
||||
#pragma once
|
||||
#include "../../../libs.h"
|
||||
#include "../../../poker/player.h"
|
||||
#include "../../../poker/dealer.h"
|
||||
#include "action.h"
|
||||
#include "../pokerdiscussion.h"
|
||||
#include "bet.h"
|
||||
|
@ -54,11 +54,18 @@ void pokerBetForPlayer(poker_t *poker, uint8_t playerIndex, int32_t chips) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t pokerBetGetCurrentCallValue(poker_t *poker) {
|
||||
uint8_t i;
|
||||
int32_t call;
|
||||
call = 0;
|
||||
for(i = 0; i < poker->playerCount; i++) {
|
||||
call = mathMax(call, poker->players[i].currentBet);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
|
||||
//eh
|
||||
int32_t pokerPlayerGetCallBet(poker_t *poker, pokerplayer_t *player) {
|
||||
return pokerGetCallValue(poker) - player->currentBet;
|
||||
return pokerBetGetCurrentCallValue(poker) - player->currentBet;
|
||||
}
|
@ -68,3 +68,11 @@ void pokerBet(
|
||||
* @param chips The amount of chips the player is betting.
|
||||
*/
|
||||
void pokerBetForPlayer(poker_t *poker, uint8_t playerIndex, int32_t chips);
|
||||
|
||||
/**
|
||||
* Gets the amount of chips necessary to call the current bet.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @return Chips necessary to call the current bet.
|
||||
*/
|
||||
int32_t pokerBetGetCurrentCallValue(poker_t *poker);
|
@ -34,10 +34,26 @@ bool pokerPlayerDoesNeedToBetThisRound(poker_t *poker, uint8_t playerIndex) {
|
||||
if(player->state & POKER_PLAYER_STATE_FOLDED) return false;
|
||||
if(player->chips <= 0) return false;
|
||||
if(!(player->state & POKER_PLAYER_STATE_HAS_BET_THIS_ROUND)) return true;
|
||||
if(player->currentBet < pokerGetCallValue(poker)) return true;
|
||||
if(player->currentBet < pokerBetGetCurrentCallValue(poker)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool pokerPlayerCanCheck(poker_t *poker, pokerplayer_t *player) {
|
||||
return pokerGetCallValue(poker) <= player->currentBet;
|
||||
}
|
||||
return pokerBetGetCurrentCallValue(poker) <= player->currentBet;
|
||||
}
|
||||
|
||||
void pokerPlayerGetFullHand(
|
||||
poker_t *poker, pokerplayer_t *player, card_t *cards
|
||||
) {
|
||||
uint8_t i;
|
||||
|
||||
// Add the dealer hand
|
||||
for(i = 0; i < poker->communitySize; i++) {
|
||||
cards[i] = poker->community[i];
|
||||
}
|
||||
|
||||
// Add the player hand
|
||||
for(i = 0; i < player->cardCount; i++) {
|
||||
cards[i+poker->communitySize] = player->cards[i];
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,15 @@ bool pokerPlayerDoesNeedToBetThisRound(poker_t *poker, uint8_t playerIndex);
|
||||
* @param player Player to check.
|
||||
* @return True if the player can check, false if they need to call first.
|
||||
*/
|
||||
bool pokerPlayerCanCheck(poker_t *poker, pokerplayer_t *player);
|
||||
bool pokerPlayerCanCheck(poker_t *poker, pokerplayer_t *player);
|
||||
|
||||
/**
|
||||
* Returns the full hand for a given player including the cards on the bench.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @param player Poker player to get the hand for.
|
||||
* @param cards Array to store the cards.
|
||||
*/
|
||||
void pokerPlayerGetFullHand(
|
||||
poker_t *poker, pokerplayer_t *player, card_t *cards
|
||||
);
|
@ -69,28 +69,11 @@ void pokerResetBettingRound(poker_t *poker) {
|
||||
poker->better = pokerBetGetRemainingPlayer(poker);
|
||||
}
|
||||
|
||||
void pokerTakeBlinds(poker_t *poker, int32_t small, int32_t big) {
|
||||
pokerBetForPlayer(poker, poker->playerSmallBlind, small);
|
||||
pokerBetForPlayer(poker, poker->playerBigBlind, big);
|
||||
pokerResetBettingRound(poker);
|
||||
void pokerTakeBlinds(poker_t *poker) {
|
||||
pokerBetForPlayer(poker, poker->playerSmallBlind, poker->blindSmall);
|
||||
pokerBetForPlayer(poker, poker->playerBigBlind, poker->blindBig);
|
||||
}
|
||||
|
||||
int32_t pokerGetCallValue(poker_t *poker) {
|
||||
uint8_t i;
|
||||
int32_t call;
|
||||
call = 0;
|
||||
for(i = 0; i < poker->playerCount; i++) {
|
||||
call = mathMax(call, poker->players[i].currentBet);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
// Pot functions
|
||||
|
||||
// Dealer Functions
|
||||
|
||||
// Player Functions
|
||||
|
||||
uint8_t pokerInRoundGetCount(poker_t *poker) {
|
||||
uint8_t i, count;
|
||||
pokerplayer_t *player;
|
||||
@ -121,21 +104,4 @@ int32_t pokerPlayerGetPotChipsSum(poker_t *poker, uint8_t playerIndex) {
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// Winning
|
||||
void pokerHandGetFull(
|
||||
poker_t *poker, pokerplayer_t *player, card_t cards[POKER_WINNING_FULL_SIZE]
|
||||
) {
|
||||
uint8_t i;
|
||||
|
||||
// Add the dealer hand
|
||||
for(i = 0; i < poker->communitySize; i++) {
|
||||
cards[i] = poker->community[i];
|
||||
}
|
||||
|
||||
// Add the player hand
|
||||
for(i = 0; i < player->cardCount; i++) {
|
||||
cards[i+poker->communitySize] = player->cards[i];
|
||||
}
|
||||
}
|
||||
}
|
@ -55,18 +55,9 @@ void pokerResetBettingRound(poker_t *poker);
|
||||
* Take the blinds from the blind players.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @param small Small blind amount.
|
||||
* @param big Big blind amount.
|
||||
*/
|
||||
void pokerTakeBlinds(poker_t *poker, int32_t small, int32_t big);
|
||||
void pokerTakeBlinds(poker_t *poker);
|
||||
|
||||
/**
|
||||
* Gets the amount of chips necessary to call the current bet.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @return Chips necessary to call the current bet.
|
||||
*/
|
||||
int32_t pokerGetCallValue(poker_t *poker);
|
||||
|
||||
/**
|
||||
* Gets the count of players still currently left in the round.
|
||||
@ -86,18 +77,6 @@ uint8_t pokerInRoundGetCount(poker_t *poker);
|
||||
*/
|
||||
int32_t pokerPlayerGetPotChipsSum(poker_t *poker, uint8_t playerIndex);
|
||||
|
||||
/**
|
||||
* Returns the full hand for a given player including the best cards on the
|
||||
* bench.
|
||||
*
|
||||
* @param poker Poker game instance.
|
||||
* @param player Poker player to get the hand for.
|
||||
* @param cards Array to store the cards.
|
||||
*/
|
||||
void pokerHandGetFull(
|
||||
poker_t *poker, pokerplayer_t *player, card_t cards[POKER_WINNING_FULL_SIZE]
|
||||
);
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dealer
|
||||
|
||||
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Betting
|
||||
|
@ -31,7 +31,7 @@ pokerturn_t pokerTurnBet(poker_t *poker, uint8_t playerIndex, int32_t chips) {
|
||||
} else {
|
||||
turn.chips = chips;
|
||||
turn.type = POKER_TURN_TYPE_BET;
|
||||
i = pokerGetCallValue(poker);
|
||||
i = pokerBetGetCurrentCallValue(poker);
|
||||
|
||||
if(chips == (i - player->currentBet)) {
|
||||
turn.type = POKER_TURN_TYPE_CALL;
|
||||
|
@ -52,7 +52,7 @@ void pokerWinnerGetForPlayer(
|
||||
|
||||
// Get the full poker hand (should be a 7 card hand, but MAY not be)
|
||||
winning->fullSize = poker->communitySize + player->cardCount;
|
||||
pokerHandGetFull(poker, player, winning->full);
|
||||
pokerPlayerGetFullHand(poker, player, winning->full);
|
||||
cardHandSort(winning->full, winning->fullSize);
|
||||
|
||||
// Reset the winning status.
|
||||
|
@ -6,9 +6,10 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "card.h"
|
||||
#include "fuck.h"
|
||||
#include "../libs.h"
|
||||
#include "player.h"
|
||||
|
||||
/**
|
||||
* Fills the remaining cards for a given poker player winning hand. Essentially
|
||||
|
@ -383,7 +383,7 @@ void test_pokerDealerBurn_should_SendCardsToTheGrave(void) {
|
||||
|
||||
}
|
||||
|
||||
void test_pokerGetCallValue_should_CalculateTheCallValue(void) {
|
||||
void test_pokerBetGetCurrentCallValue_should_CalculateTheCallValue(void) {
|
||||
poker_t poker;
|
||||
uint8_t first, second;
|
||||
pokerInit(&poker);
|
||||
@ -392,21 +392,21 @@ void test_pokerGetCallValue_should_CalculateTheCallValue(void) {
|
||||
pokerPlayerChipsAdd(poker.players + first, 10000);
|
||||
pokerPlayerChipsAdd(poker.players + second, 10000);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(0, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(0, pokerBetGetCurrentCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, first, 100);
|
||||
TEST_ASSERT_EQUAL_INT32(100, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(100, pokerBetGetCurrentCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, second, 150);
|
||||
TEST_ASSERT_EQUAL_INT32(150, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(150, pokerBetGetCurrentCallValue(&poker));
|
||||
|
||||
pokerPotAdd(&poker);
|
||||
TEST_ASSERT_EQUAL_INT32(150, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(150, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(0, poker.pots[1].chips);
|
||||
pokerBetForPlayer(&poker, second, 50);
|
||||
TEST_ASSERT_EQUAL_INT32(200, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(200, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(50, poker.pots[1].chips);
|
||||
}
|
||||
|
||||
void test_pokerGetCallValue_should_SkipOutPlayers(void) {
|
||||
void test_pokerBetGetCurrentCallValue_should_SkipOutPlayers(void) {
|
||||
poker_t poker;
|
||||
uint8_t i;
|
||||
pokerInit(&poker);
|
||||
@ -423,11 +423,11 @@ void test_pokerGetCallValue_should_SkipOutPlayers(void) {
|
||||
pokerPlayerChipsAdd(poker.players + i, 10000);
|
||||
pokerBetForPlayer(&poker, i, 200);
|
||||
|
||||
TEST_ASSERT_EQUAL_INT32(500, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(500, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.players[1].state |= POKER_PLAYER_STATE_OUT;
|
||||
TEST_ASSERT_EQUAL_INT32(300, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(300, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.players[0].state |= POKER_PLAYER_STATE_OUT;
|
||||
TEST_ASSERT_EQUAL_INT32(200, pokerGetCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL_INT32(200, pokerBetGetCurrentCallValue(&poker));
|
||||
}
|
||||
|
||||
void test_pokerDeal_should_DealCardsToThePlayer(void) {
|
||||
@ -670,20 +670,20 @@ void test_pokerBetGetRemainingPlayer_should_ReturnRemainingBetters(void) {
|
||||
TEST_ASSERT_EQUAL(0x04, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 2
|
||||
pokerBetForPlayer(&poker, 0x04, pokerGetCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, 0x04, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL(0x00, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 3
|
||||
pokerBetForPlayer(&poker, 0x00, pokerGetCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, 0x00, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL(0x01, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 4 / Small Blind
|
||||
pokerBetForPlayer(&poker, 0x01, pokerGetCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, 0x01, pokerBetGetCurrentCallValue(&poker));
|
||||
TEST_ASSERT_EQUAL(0x02, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
// Blind + 5 / Big Blind
|
||||
pokerBetForPlayer(
|
||||
&poker, 0x02, pokerGetCallValue(&poker) - poker.players[0x01].currentBet
|
||||
&poker, 0x02, pokerBetGetCurrentCallValue(&poker) - poker.players[0x01].currentBet
|
||||
);
|
||||
TEST_ASSERT_EQUAL(0x03, pokerBetGetRemainingPlayer(&poker));
|
||||
|
||||
@ -724,24 +724,24 @@ void test_pokerBetGetNextPlayer_should_GetTheNextBetter(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0x04, poker.better);
|
||||
|
||||
// Blind+2
|
||||
pokerBetForPlayer(&poker, poker.better, pokerGetCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, poker.better);
|
||||
|
||||
// BLind+3
|
||||
pokerBetForPlayer(&poker, poker.better, pokerGetCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x01, poker.better);
|
||||
|
||||
// Dealer
|
||||
pokerBetForPlayer(&poker, poker.better, pokerGetCallValue(&poker));
|
||||
pokerBetForPlayer(&poker, poker.better, pokerBetGetCurrentCallValue(&poker));
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x02, poker.better);
|
||||
|
||||
// Small blind
|
||||
pokerBetForPlayer(
|
||||
&poker, poker.better,
|
||||
pokerGetCallValue(&poker) - poker.players[0x02].currentBet
|
||||
pokerBetGetCurrentCallValue(&poker) - poker.players[0x02].currentBet
|
||||
);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x03, poker.better);
|
||||
@ -749,7 +749,7 @@ void test_pokerBetGetNextPlayer_should_GetTheNextBetter(void) {
|
||||
// Big Blind
|
||||
pokerBetForPlayer(
|
||||
&poker, poker.better,
|
||||
pokerGetCallValue(&poker) - poker.players[0x03].currentBet
|
||||
pokerBetGetCurrentCallValue(&poker) - poker.players[0x03].currentBet
|
||||
);
|
||||
poker.better = pokerBetGetNextPlayer(&poker);
|
||||
TEST_ASSERT_EQUAL_UINT8(0xFF, poker.better);
|
||||
@ -1025,7 +1025,7 @@ void test_pokerTurnBet_should_ReturnARaiseAction(void) {
|
||||
TEST_ASSERT_EQUAL_FLOAT(1.0f, turn.confidence);
|
||||
}
|
||||
|
||||
void test_pokerHandGetFull_should_ReturnTheFullHand(void) {
|
||||
void test_pokerPlayerGetFullHand_should_ReturnTheFullHand(void) {
|
||||
poker_t poker;
|
||||
pokerplayer_t *player;
|
||||
uint8_t i;
|
||||
@ -1046,7 +1046,7 @@ void test_pokerHandGetFull_should_ReturnTheFullHand(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_NINE, poker.community[3]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, poker.community[4]);
|
||||
|
||||
pokerHandGetFull(&poker, player, cards);
|
||||
pokerPlayerGetFullHand(&poker, player, cards);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_QUEEN, cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_JACK, cards[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_TEN, cards[2]);
|
||||
@ -1063,7 +1063,7 @@ void test_pokerHandGetFull_should_ReturnTheFullHand(void) {
|
||||
player->cards[0] = CARD_DIAMONDS_KING;
|
||||
player->cards[1] = CARD_HEARTS_QUEEN;
|
||||
|
||||
pokerHandGetFull(&poker, player, cards);
|
||||
pokerPlayerGetFullHand(&poker, player, cards);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_CLUBS_THREE, cards[0]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_DIAMONDS_TWO, cards[1]);
|
||||
TEST_ASSERT_EQUAL_UINT8(CARD_SPADES_EIGHT, cards[2]);
|
||||
@ -1602,7 +1602,7 @@ int test_poker() {
|
||||
RUN_TEST(test_pokerPlayerAdd_should_ResetThePlayer);
|
||||
RUN_TEST(test_pokerDealerTurn_should_TurnCardsFromTheDeck);
|
||||
RUN_TEST(test_pokerDealerBurn_should_SendCardsToTheGrave);
|
||||
RUN_TEST(test_pokerGetCallValue_should_CalculateTheCallValue);
|
||||
RUN_TEST(test_pokerBetGetCurrentCallValue_should_CalculateTheCallValue);
|
||||
RUN_TEST(test_pokerDeal_should_DealCardsToThePlayer);
|
||||
RUN_TEST(test_pokerPlayerChipsAdd_should_AddChipsToThePlayer);
|
||||
RUN_TEST(test_pokerPlayerChipsAdd_should_TurnOutStateOff);
|
||||
@ -1627,7 +1627,7 @@ int test_poker() {
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnAnAllInAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnACallAction);
|
||||
RUN_TEST(test_pokerTurnBet_should_ReturnARaiseAction);
|
||||
RUN_TEST(test_pokerHandGetFull_should_ReturnTheFullHand);
|
||||
RUN_TEST(test_pokerPlayerGetFullHand_should_ReturnTheFullHand);
|
||||
RUN_TEST(test_pokerWinnerFillRemaining_should_FillTheRestOfTheArray);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculateHighCard);
|
||||
RUN_TEST(test_pokerWinnerGetForPlayer_should_CalculatePair);
|
||||
|
Reference in New Issue
Block a user