From ce960523853db02eb4a8a28d0597f63b06acaa29 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 5 Jun 2021 10:03:04 -0700 Subject: [PATCH] Working on poker logic --- include/dawn/poker/player.h | 3 +++ include/dawn/poker/poker.h | 1 - src/poker/player.c | 8 ++++++++ src/poker/player.h | 21 ++++++++++++++++++++- src/poker/render/frame.c | 4 ++++ src/poker/round/bet.c | 15 +++++++++++---- src/poker/round/bet.h | 1 + src/poker/round/deal.c | 1 + src/poker/round/match.c | 2 +- src/poker/round/start.c | 6 +++--- src/poker/round/start.h | 1 + src/poker/round/winner.c | 7 +++++++ 12 files changed, 60 insertions(+), 10 deletions(-) diff --git a/include/dawn/poker/player.h b/include/dawn/poker/player.h index a85375ca..36e3464e 100644 --- a/include/dawn/poker/player.h +++ b/include/dawn/poker/player.h @@ -24,6 +24,9 @@ /** State for whether or not the player is out */ #define POKER_PLAYER_STATE_OUT 0x04 +/** The index that the player who is the human... is */ +#define POKER_PLAYER_HUMAN_INDEX 0x02 + /** Poker Player State */ typedef struct { /** Cards in the players' hand */ diff --git a/include/dawn/poker/poker.h b/include/dawn/poker/poker.h index 7ad40958..330a0186 100644 --- a/include/dawn/poker/poker.h +++ b/include/dawn/poker/poker.h @@ -137,5 +137,4 @@ typedef struct { texture_t cardTexture; tileset_t cardTileset; primitive_t cardPrimitive; - } poker_t; \ No newline at end of file diff --git a/src/poker/player.c b/src/poker/player.c index 4b6c9721..1d83f1da 100644 --- a/src/poker/player.c +++ b/src/poker/player.c @@ -11,4 +11,12 @@ void pokerPlayerBet(poker_t *poker, pokerplayer_t *player, int32_t chips) { poker->pot += chips; player->chips -= chips; player->currentBet += chips; +} + +bool pokerPlayerIsAlive(pokerplayer_t *player) { + return !(player->state & (POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT)); +} + +bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player) { + return (poker->players + POKER_PLAYER_HUMAN_INDEX) == player; } \ No newline at end of file diff --git a/src/poker/player.h b/src/poker/player.h index d4c6845c..10b87750 100644 --- a/src/poker/player.h +++ b/src/poker/player.h @@ -14,4 +14,23 @@ * @param player Poker player instance. * @param chips Chips to bet. */ -void pokerPlayerBet(poker_t *poker, pokerplayer_t *player, int32_t chips); \ No newline at end of file +void pokerPlayerBet(poker_t *poker, pokerplayer_t *player, int32_t chips); + +/** + * Returns true if the player is still alive and in the current game/ + * Defined as: Not out, not folded. + * + * @param player Player to check + * @returns True if alive/in teh current game. + */ +bool pokerPlayerIsAlive(pokerplayer_t *player); + + +/** + * Returns true if the player provided is human or not. + * + * @param poker Poker game instance. + * @param player Player instance. + * @returns True if the player is human. + */ +bool pokerPlayerIsHuman(poker_t *poker, pokerplayer_t *player); \ No newline at end of file diff --git a/src/poker/render/frame.c b/src/poker/render/frame.c index 0e05704e..95304e9b 100644 --- a/src/poker/render/frame.c +++ b/src/poker/render/frame.c @@ -38,4 +38,8 @@ void pokerFrameGui(poker_t *poker, render_t *render) { ); cameraLookAt(&poker->cameraGui, 0, 0, 5, 0, 0, 0); shaderUseCamera(&poker->shader, &poker->cameraGui); +} + +void pokerFrameRender(poker_t *poker, render_t *render) { + } \ No newline at end of file diff --git a/src/poker/round/bet.c b/src/poker/round/bet.c index 5380b11c..1cd4482d 100644 --- a/src/poker/round/bet.c +++ b/src/poker/round/bet.c @@ -26,20 +26,27 @@ void pokerBetPlayerNext(poker_t *poker) { pokerBetPlayerInit(poker, poker->players + poker->roundBetCurrent); } -void pokerBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) { - pokerBetPlayerNext(poker); -} void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player) { // Check the player state (to see if we even can init, e.g. folded/not) - if(player->state & (POKER_PLAYER_STATE_FOLDED|POKER_PLAYER_STATE_OUT)) { + if(!pokerPlayerIsAlive(player)) { pokerBetPlayerNext(poker); return; } printf("Betting round player %u\n", poker->roundBetCurrent); + if(pokerPlayerIsHuman(poker, player)) { + return; + } + + pokerBetPlayerNext(poker); } +void pokerBetPlayerUpdate(poker_t *poker, pokerplayer_t *player) { + +} + + void pokerBetInit(poker_t *poker) { printf("Betting round start\n"); diff --git a/src/poker/round/bet.h b/src/poker/round/bet.h index e4429d2b..febfaf88 100644 --- a/src/poker/round/bet.h +++ b/src/poker/round/bet.h @@ -9,6 +9,7 @@ #include #include "flop.h" #include "winner.h" +#include "../player.h" void pokerBetPlayerNext(poker_t *poker); void pokerBetPlayerInit(poker_t *poker, pokerplayer_t *player); diff --git a/src/poker/round/deal.c b/src/poker/round/deal.c index bf3d7e9e..a29c5154 100644 --- a/src/poker/round/deal.c +++ b/src/poker/round/deal.c @@ -29,6 +29,7 @@ void pokerDealInit(poker_t *poker) { for(y = 0; y < POKER_DEAL_CARD_EACH; y++) { for(x = 0; x < POKER_PLAYER_COUNT; x++) { player = poker->players + x; + if(!pokerPlayerIsAlive(player)) continue; cardDeal( poker->deck, &poker->deckSize, player->cards, &player->cardCount diff --git a/src/poker/round/match.c b/src/poker/round/match.c index 760934a8..cdb389a9 100644 --- a/src/poker/round/match.c +++ b/src/poker/round/match.c @@ -15,7 +15,7 @@ void pokerMatchInit(poker_t *poker) { // Reset the main game state. This does not init the round. poker->blindBig = POKER_BLIND_BIG_DEFAULT; poker->blindSmall = POKER_BLIND_SMALL_DEFAULT; - poker->roundDealer = 0x00; + poker->roundDealer = POKER_PLAYER_COUNT-2; poker->roundTextCounter = 0; poker->round = POKER_ROUND_MATCH; diff --git a/src/poker/round/start.c b/src/poker/round/start.c index 43f670d2..0391bd38 100644 --- a/src/poker/round/start.c +++ b/src/poker/round/start.c @@ -35,7 +35,7 @@ void pokerStartInit(poker_t *poker) { } // Decide on the dealer - poker->roundDealer++; + poker->roundDealer = (poker->roundDealer+1) % POKER_PLAYER_COUNT; // Find the players. i = poker->roundDealer; @@ -43,8 +43,7 @@ void pokerStartInit(poker_t *poker) { foundSmallBlind = false; while(true) { player = poker->players + i; - if(player->state & POKER_PLAYER_STATE_FOLDED) continue; - if(player->state & POKER_PLAYER_STATE_OUT) continue; + if(!pokerPlayerIsAlive(player)) continue; if(!foundDealer) { indexDealer = i; foundDealer = true; @@ -59,6 +58,7 @@ void pokerStartInit(poker_t *poker) { } // Update players for the round. + poker->roundDealer = indexDealer; poker->roundBigBlind = indexBigBlind; poker->roundSmallBlind = indexSmallBlind; diff --git a/src/poker/round/start.h b/src/poker/round/start.h index 052a338a..238884bd 100644 --- a/src/poker/round/start.h +++ b/src/poker/round/start.h @@ -8,5 +8,6 @@ #pragma once #include #include "blinds.h" +#include "../player.h" void pokerStartInit(poker_t *poker); \ No newline at end of file diff --git a/src/poker/round/winner.c b/src/poker/round/winner.c index d999928a..6aeaff78 100644 --- a/src/poker/round/winner.c +++ b/src/poker/round/winner.c @@ -9,6 +9,13 @@ #include "winner.h" void pokerWinnerInit(poker_t *poker) { + uint8_t i; + poker->round = POKER_ROUND_WINNER; printf("Winner Winner Chicken Dinner\n"); + + // Bruh Moment + for(i = 0; i < POKER_PLAYER_COUNT; i++) { + + } } \ No newline at end of file