Made betting work correctly.

This commit is contained in:
2021-08-29 22:03:18 -07:00
parent 954b676f07
commit 063c7b12ed
8 changed files with 72 additions and 11 deletions

View File

@ -72,6 +72,7 @@
// Utility Objects // Utility Objects
#include "util/array.h" #include "util/array.h"
#include "util/flags.h"
#include "util/list.h" #include "util/list.h"
#include "util/math.h" #include "util/math.h"
#include "util/rand.h" #include "util/rand.h"

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "../libs.h" #include "../libs.h"
#include "player.h"
/** How many chips each player has by defautl */ /** How many chips each player has by defautl */
#define POKER_BET_PLAYER_CHIPS_DEFAULT 10000 #define POKER_BET_PLAYER_CHIPS_DEFAULT 10000
@ -17,6 +18,16 @@
/** 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)
/**
* The default betting player for the round.
*
* @param poker Pointer to the poker instance.
* @return The Poker round default betting player.
*/
#define POKER_BET_ROUND_PLAYER_DEFAULT(poker) ( \
((poker)->roundSmallBlind + 1) % POKER_PLAYER_COUNT \
)
typedef struct { typedef struct {
/** Blinds */ /** Blinds */
int32_t blindSmall, blindBig; int32_t blindSmall, blindBig;

View File

@ -7,6 +7,7 @@
#pragma once #pragma once
#include "../libs.h" #include "../libs.h"
#include "../util/flags.h"
#include "bet.h" #include "bet.h"
#include "card.h" #include "card.h"
@ -21,18 +22,20 @@
// Player States // Player States
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/** State for whether or not a player has folded */ /** State for whether or not a player has folded */
#define POKER_PLAYER_STATE_FOLDED 0x01 #define POKER_PLAYER_STATE_FOLDED flagDefine(0)
/** State for whether or not a player is showing their hand */ /** State for whether or not a player is showing their hand */
#define POKER_PLAYER_STATE_SHOWING 0x02 #define POKER_PLAYER_STATE_SHOWING flagDefine(1)
/** State for whether or not the player is out */ /** State for whether or not the player is out */
#define POKER_PLAYER_STATE_OUT 0x04 #define POKER_PLAYER_STATE_OUT flagDefine(2)
/** Flag that is reset at the start of each round, and set when move occurs. */
#define POKER_PLAYER_STATE_ROUND_MOVE flagDefine(3)
/** The index that the player who is the human... is */ /** The index that the player who is the human... is */
#define POKER_PLAYER_HUMAN_INDEX 0x02 #define POKER_PLAYER_HUMAN_INDEX 0x02
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Player Definition // Player Definition
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

26
include/dawn/util/flags.h Normal file
View File

@ -0,0 +1,26 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
/**
* Create a flag definition.
*
* @param n The flag number.
* @return The bitwise flag for that number.
*/
#define flagDefine(n) (1 << n)
/**
* Turns a flag off in a state.
*
* @param state State to update.
* @param flag Flag to turn off.
* @return The updated state.
*/
#define flagOff(state, flag) (state & ~flag)

View File

@ -10,13 +10,14 @@
#include "../display/animation/timeline.h" #include "../display/animation/timeline.h"
#include "../display/gui/font.h" #include "../display/gui/font.h"
#include "../ui/frame.h" #include "../ui/frame.h"
#include "../util/flags.h"
/** Amount of characters scrolled, per second */ /** Amount of characters scrolled, per second */
#define VN_TEXTBOX_SCROLL_SPEED 60 #define VN_TEXTBOX_SCROLL_SPEED 60
#define VN_TEXTBOX_FONT_SIZE 16.0 #define VN_TEXTBOX_FONT_SIZE 16.0
#define VN_TEXTBOX_STATE_CLOSED 0x01 #define VN_TEXTBOX_STATE_CLOSED flagDefine(0)
typedef struct { typedef struct {
/** Stores the maximum width that this textbox can take up */ /** Stores the maximum width that this textbox can take up */

View File

@ -65,6 +65,9 @@ void _pokerGameActionBetOnUpdate(
break; break;
} }
// Mark as move made.
player->state |= POKER_PLAYER_STATE_ROUND_MOVE;
// Speak // Speak
discussion.poker = game; discussion.poker = game;
discussion.playerCause = game->poker.bet.better; discussion.playerCause = game->poker.bet.better;
@ -78,7 +81,7 @@ void _pokerGameActionBetOnUpdate(
void _pokerGameActionBetOnEnd( void _pokerGameActionBetOnEnd(
queue_t *queue, queueaction_t *action, uint8_t i queue_t *queue, queueaction_t *action, uint8_t i
) { ) {
uint8_t j; uint8_t j, k, p;
pokerplayer_t *player; pokerplayer_t *player;
queueaction_t *next; queueaction_t *next;
pokerdiscussiondata_t discussion; pokerdiscussiondata_t discussion;
@ -90,18 +93,28 @@ void _pokerGameActionBetOnEnd(
playersPending = false; playersPending = false;
// Check if each player needs to action. // Check if each player needs to action.
k = POKER_BET_ROUND_PLAYER_DEFAULT(&game->poker);
for(j = 0; j < POKER_PLAYER_COUNT; j++) { for(j = 0; j < POKER_PLAYER_COUNT; j++) {
player = game->poker.players + j; p = ((k + j) % POKER_PLAYER_COUNT);
if(player->state & POKER_PLAYER_STATE_FOLDED) continue; 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_OUT) continue;
if(player->currentBet >= game->poker.bet.currentBet) 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 // Yes, this player needs to check, raise or fold
game->poker.bet.better = p;
pokerGameActionBetAdd(game); pokerGameActionBetAdd(game);
playersPending = true; playersPending = true;
break; break;
} }
// Restack
pokerGameActionRestackAdd(game);
// Are we waiting on any players? // Are we waiting on any players?
if(playersPending) return; if(playersPending) return;

View File

@ -12,7 +12,7 @@ void _pokerGameActionRestackOnStart(
) { ) {
pokergame_t *game = (pokergame_t *)action->data; pokergame_t *game = (pokergame_t *)action->data;
printf("Restacking\n"); printf("Restacking\n");
// pokerGameQueueRestack(game); pokerGameQueueRestack(game);
queueNext(queue); queueNext(queue);
} }

View File

@ -25,7 +25,13 @@ void pokerBetPlayer(poker_t *poker, pokerplayer_t *player, int32_t chips) {
} }
void pokerBetResetBetter(poker_t *poker) { void pokerBetResetBetter(poker_t *poker) {
poker->bet.better = (poker->roundSmallBlind + 1) % POKER_PLAYER_COUNT; uint8_t i;
pokerplayer_t *player;
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
player = poker->players + i;
player->state = flagOff(player->state, POKER_PLAYER_STATE_ROUND_MOVE);
}
poker->bet.better = POKER_BET_ROUND_PLAYER_DEFAULT(poker);
} }
void pokerBetTakeBlinds(poker_t *poker) { void pokerBetTakeBlinds(poker_t *poker) {