Cleaned some of the betting code.

This commit is contained in:
2021-08-29 22:19:54 -07:00
parent 92e13b8750
commit 5fb4527e1e
3 changed files with 44 additions and 27 deletions

View File

@ -81,42 +81,21 @@ void _pokerGameActionBetOnUpdate(
void _pokerGameActionBetOnEnd(
queue_t *queue, queueaction_t *action, uint8_t i
) {
uint8_t j, k, p;
pokerplayer_t *player;
queueaction_t *next;
pokerdiscussiondata_t discussion;
bool playersPending;
pokergame_t *game = (pokergame_t *)action->data;
// Go to the next better
game->poker.bet.better = (game->poker.bet.better + 1) % POKER_PLAYER_COUNT;
playersPending = false;
// Check if each player needs to action.
k = POKER_BET_ROUND_PLAYER_DEFAULT(&game->poker);
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
p = ((k + j) % POKER_PLAYER_COUNT);
player = game->poker.players + p;
if((player->state & POKER_PLAYER_STATE_FOLDED) != 0) continue;
if(player->state & POKER_PLAYER_STATE_OUT) continue;
if(player->state & POKER_PLAYER_STATE_ROUND_MOVE) {
if(player->currentBet >= game->poker.bet.currentBet && player) continue;
}
// Yes, this player needs to check, raise or fold
game->poker.bet.better = p;
pokerGameActionBetAdd(game);
playersPending = true;
break;
}
// Get which player is remaining to move.
game->poker.bet.better = pokerBetGetRemainingPlayer(&game->poker);
// Restack
pokerGameActionRestackAdd(game);
// Are we waiting on any players?
if(playersPending) return;
if(game->poker.bet.better != 0xFF) {
pokerGameActionBetAdd(game);
return;
}
// Not waiting, restack and do next action.
printf("Not waiting on anything!\n");

View File

@ -34,6 +34,26 @@ void pokerBetResetBetter(poker_t *poker) {
poker->bet.better = POKER_BET_ROUND_PLAYER_DEFAULT(poker);
}
bool pokerBetPlayerCanBet(pokerbet_t *bet, pokerplayer_t *player) {
if((player->state & POKER_PLAYER_STATE_FOLDED) != 0) return false;
if(player->state & POKER_PLAYER_STATE_OUT) return false;
if(player->state & POKER_PLAYER_STATE_ROUND_MOVE) {
if(player->currentBet >= bet->currentBet && player) return false;
}
return true;
}
uint8_t pokerBetGetRemainingPlayer(poker_t *poker) {
uint8_t def, j, pi;
def = POKER_BET_ROUND_PLAYER_DEFAULT(poker);
for(j = 0; j < POKER_PLAYER_COUNT; j++) {
pi = ((def + j) % POKER_PLAYER_COUNT);
if(!pokerBetPlayerCanBet(&poker->bet, poker->players + pi)) continue;
return pi;
}
return 0xFF;
}
void pokerBetTakeBlinds(poker_t *poker) {
pokerBetPlayer(poker, poker->players + poker->roundSmallBlind,
poker->bet.blindSmall

View File

@ -37,6 +37,24 @@ void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips);
*/
void pokerBetResetBetter(poker_t *poker);
/**
* Returns whether or not a player can bet for the current round.
*
* @param bet Game bet state.
* @param player Player to check.
* @return True if the player can bet, otherwise false.
*/
bool pokerBetPlayerCanBet(pokerbet_t *bet, pokerplayer_t *player);
/**
* Returns the index of the first player that remains to bet for the current
* round.
*
* @param poker Poker instance to fetch from.
* @return The player index of the remaining player, otherwise 0xFF.
*/
uint8_t pokerBetGetRemainingPlayer(poker_t *poker);
/**
* Takes the current blinds from the correct players.
*