From edb80a34310dbcf9b0628b6ac59e75b95e705532 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 12 Jul 2021 09:31:22 -0700 Subject: [PATCH] Last commit before another big refactor --- include/dawn/poker/poker.h | 10 +++ src/platform/glfw/glwfwplatform.h | 4 +- src/poker/card.c | 8 ++- src/poker/card.h | 10 ++- src/poker/player.c | 106 +++++++++++++++++++++++------- src/poker/player.h | 14 +++- src/poker/poker.c | 4 +- src/poker/render/look.c | 6 +- src/poker/render/look.h | 2 +- src/poker/round/deal.c | 4 +- src/poker/round/match.c | 10 +-- src/poker/round/match.h | 5 +- src/poker/round/winner.c | 70 +------------------- src/poker/round/winner.h | 2 - 14 files changed, 139 insertions(+), 116 deletions(-) diff --git a/include/dawn/poker/poker.h b/include/dawn/poker/poker.h index da677c28..f4cd12ea 100644 --- a/include/dawn/poker/poker.h +++ b/include/dawn/poker/poker.h @@ -162,6 +162,16 @@ typedef struct { /** Information about the current rendered text */ fonttextinfo_t *talkTextInfo; + /** Match Scene Variables */ + float matchStart; + + + + + + + + texture_t dealerTexture; tileset_t dealerTileset; primitive_t dealerPrimitive; diff --git a/src/platform/glfw/glwfwplatform.h b/src/platform/glfw/glwfwplatform.h index 0b2fa232..a9a75125 100644 --- a/src/platform/glfw/glwfwplatform.h +++ b/src/platform/glfw/glwfwplatform.h @@ -13,8 +13,8 @@ #include "../../game/game.h" #include "../../input/input.h" -#define WINDOW_WIDTH_DEFAULT 480 -#define WINDOW_HEIGHT_DEFAULT 270 +#define WINDOW_WIDTH_DEFAULT 1280 +#define WINDOW_HEIGHT_DEFAULT WINDOW_WIDTH_DEFAULT/16*9 /** The current running game state. */ extern game_t *GAME_STATE; diff --git a/src/poker/card.c b/src/poker/card.c index 0a8b2522..162d07dd 100644 --- a/src/poker/card.c +++ b/src/poker/card.c @@ -54,8 +54,8 @@ int32_t cardContainsNumber(card_t *hand, uint8_t length, uint8_t number) { return -1; } -uint8_t cardCountPairs( - card_t *in, uint8_t inCount, uint8_t number, int32_t out[CARD_SUIT_COUNT] +uint8_t cardCountPairs(card_t *in, uint8_t inCount, uint8_t number, + int32_t out[CARD_SUIT_COUNT] ) { uint8_t i, count; int32_t index; @@ -68,4 +68,8 @@ uint8_t cardCountPairs( } return count; +} + +void cardShuffle(card_t *hand, uint8_t length) { + arrayShuffle(sizeof(card_t), hand, length); } \ No newline at end of file diff --git a/src/poker/card.h b/src/poker/card.h index 0c2f57c9..2cce4b1d 100644 --- a/src/poker/card.h +++ b/src/poker/card.h @@ -83,4 +83,12 @@ int32_t cardContainsNumber(card_t *hand, uint8_t length, uint8_t number); */ uint8_t cardCountPairs( card_t *in, uint8_t inCount, uint8_t number, int32_t out[4] -); \ No newline at end of file +); + +/** + * Shuffles a hand / deck + * + * @param hand Hand to shuffle. + * @param length Length of the hand to shuffle. + */ +void cardShuffle(card_t *hand, uint8_t length); \ No newline at end of file diff --git a/src/poker/player.c b/src/poker/player.c index 9dbd32dd..56328754 100644 --- a/src/poker/player.c +++ b/src/poker/player.c @@ -239,6 +239,38 @@ void pokerPlayerGetWinning( return; } +void pokerPlayerWinningFillRemaining(pokerwinning_t *winning) { + uint8_t i, highest, current; + card_t highestCard, currentCard; + + // Set the kicker + winning->kicker = 0xFF; + + // Fill the remaining cards + while(winning->setSize < POKER_WINNING_SET_SIZE) { + highest = 0xFF; + + for(i = 0; i < winning->fullSize; i++) { + currentCard = winning->full[i]; + if(cardContains(winning->set, winning->setSize, currentCard) != -1) { + continue; + } + + if(highest == 0xFF) { + highestCard = currentCard; + highest = cardGetNumber(highestCard); + } else { + current = cardGetNumber(currentCard); + if(current != CARD_ACE && current < highest) continue; + highestCard = currentCard; + highest = current; + } + } + + winning->set[winning->setSize++] = highestCard; + } + cardHandSort(winning->set, winning->setSize); +} card_t pokerPlayerCompareWinning(pokerwinning_t *left, pokerwinning_t *right) { uint8_t i, number; @@ -281,35 +313,63 @@ card_t pokerPlayerCompareWinning(pokerwinning_t *left, pokerwinning_t *right) { return highCardLeft;//Greater or Equal to. } -void pokerPlayerWinningFillRemaining(pokerwinning_t *winning) { - uint8_t i, highest, current; - card_t highestCard, currentCard; +void pokerPlayerWinnerDetermine(poker_t *poker) { + uint8_t i, j, number, highNumber; + pokerwinning_t *left, *right; + pokerplayer_t *player; + card_t card, highCard; + bool winner; - // Set the kicker - winning->kicker = 0xFF; + poker->winnerCount = 0; - // Fill the remaining cards - while(winning->setSize < POKER_WINNING_SET_SIZE) { - highest = 0xFF; + // Get winning sets + for(i = 0; i < POKER_PLAYER_COUNT; i++) { + left = poker->winnings + i; + left->type = POKER_WINNING_TYPE_NULL; + player = poker->players + i; + if(!pokerPlayerIsAlive(player)) continue; - for(i = 0; i < winning->fullSize; i++) { - currentCard = winning->full[i]; - if(cardContains(winning->set, winning->setSize, currentCard) != -1) { - continue; + // Get the players' full hand. + pokerPlayerGetWinning(poker, player, left); + } + + // Compare against each player + for(i = 0; i < POKER_PLAYER_COUNT; i++) { + left = poker->winnings + i; + if(left->type == POKER_WINNING_TYPE_NULL) continue; + + winner = true; + highNumber = 0xFF; + + for(j = 0; j < POKER_PLAYER_COUNT; j++) { + if(i == j) continue; + right = poker->winnings + j; + if(right->type == POKER_WINNING_TYPE_NULL) continue; + + // Am I the better hand / Is it the better hand? + if(left->type < right->type) continue; + if(left->type > right->type) { + winner = false; + break; } - if(highest == 0xFF) { - highestCard = currentCard; - highest = cardGetNumber(highestCard); - } else { - current = cardGetNumber(currentCard); - if(current != CARD_ACE && current < highest) continue; - highestCard = currentCard; - highest = current; + // Equal, compare hands. + card = pokerPlayerCompareWinning(left, right); + if(card == 0xFF) { + winner = false; + break; + } + + // Determine high card. + number = cardGetNumber(card); + if(highNumber == 0xFF || number == CARD_ACE || number > highNumber) { + highCard = card; + highNumber = number; } } - winning->set[winning->setSize++] = highestCard; + if(!winner) continue; + left->kicker = highCard; + poker->winners[poker->winnerCount++] = i; } - cardHandSort(winning->set, winning->setSize); -} \ No newline at end of file +} diff --git a/src/poker/player.h b/src/poker/player.h index c136a1e2..ed48e628 100644 --- a/src/poker/player.h +++ b/src/poker/player.h @@ -73,6 +73,12 @@ void pokerPlayerGetWinning( poker_t *poker, pokerplayer_t *player, pokerwinning_t *winning ); +/** + * Fills the remaining cards for a given poker player winning hand. + * @param winning Pointer to the poker winning to fill out. + */ +void pokerPlayerWinningFillRemaining(pokerwinning_t *winning); + /** * Compares two winning sets. The returned card is the kicker if the LEFT side * is the winner. If LEFT is not a winner then 0xFF will be returned. @@ -84,7 +90,9 @@ void pokerPlayerGetWinning( card_t pokerPlayerCompareWinning(pokerwinning_t *left, pokerwinning_t *right); /** - * Fills the remaining cards for a given poker player winning hand. - * @param winning Pointer to the poker winning to fill out. + * Determines the winning player for the game. Values will be stored back into + * the poker winning state. + * + * @param poker Poker game instance. */ -void pokerPlayerWinningFillRemaining(pokerwinning_t *winning); \ No newline at end of file +void pokerPlayerWinnerDetermine(poker_t *poker); \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index 10418b68..b2d4e832 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -24,14 +24,14 @@ void pokerInit(poker_t *poker, engine_t *engine) { pokerTalkInit(poker); // Hand over to the deal for the first time. - pokerMatchInit(poker); + pokerMatchInit(poker, engine); } void pokerUpdate(poker_t *poker, engine_t *engine) { // Game Logic switch(poker->round) { case POKER_ROUND_MATCH: - pokerMatchUpdate(poker); + pokerMatchUpdate(poker, engine); break; case POKER_ROUND_BET0: case POKER_ROUND_BET1: diff --git a/src/poker/render/look.c b/src/poker/render/look.c index c61ee2f2..19e36fcf 100644 --- a/src/poker/render/look.c +++ b/src/poker/render/look.c @@ -7,11 +7,11 @@ #include "look.h" -void pokerLookAtPlayer(camera_t *camera, uint8_t seat) { +void pokerLookAtPlayer(camera_t *camera, uint8_t seat, float distance) { float x, z, angle; angle = POKER_SEAT_ANGLE(seat); - x = sin(angle) * 0.8; - z = cos(angle) * 0.8; + x = sin(angle) * (0.8); + z = cos(angle) * (0.8 + distance); cameraLookAt(camera, x, 0.3, z, -x, 0.3, -z diff --git a/src/poker/render/look.h b/src/poker/render/look.h index 4a318c9b..df268b80 100644 --- a/src/poker/render/look.h +++ b/src/poker/render/look.h @@ -14,7 +14,7 @@ * @param camera Camera to adjust. * @param seat Seat to look at. */ -void pokerLookAtPlayer(camera_t *camera, uint8_t seat); +void pokerLookAtPlayer(camera_t *camera, uint8_t seat, float distance); /** * Look at a specific seats' hand. diff --git a/src/poker/round/deal.c b/src/poker/round/deal.c index a8b619ed..85ea37a3 100644 --- a/src/poker/round/deal.c +++ b/src/poker/round/deal.c @@ -10,10 +10,10 @@ void pokerDealInit(poker_t *poker) { poker->round = POKER_ROUND_DEAL; // Hard look at the dealer - pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER); + pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER, 0); // Shuffle the deck - arrayShuffle(sizeof(card_t), poker->deck, CARD_DECK_SIZE); + cardShuffle(poker->deck, CARD_DECK_SIZE); // Deal 2 card to each player pokerPlayerDealAll(poker, POKER_DEAL_CARD_EACH); diff --git a/src/poker/round/match.c b/src/poker/round/match.c index cdb389a9..d435a1da 100644 --- a/src/poker/round/match.c +++ b/src/poker/round/match.c @@ -6,11 +6,12 @@ */ #include "match.h" -void pokerMatchInit(poker_t *poker) { +void pokerMatchInit(poker_t *poker, engine_t *engine) { uint8_t x; // Look at the dealer - pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER); + poker->matchStart = engine->time.current; + pokerLookAtPlayer(&poker->cameraWorld, POKER_SEAT_DEALER, 100); // Reset the main game state. This does not init the round. poker->blindBig = POKER_BLIND_BIG_DEFAULT; @@ -24,8 +25,9 @@ void pokerMatchInit(poker_t *poker) { poker->players[x].chips = POKER_PLAYER_CHIPS_DEFAULT; } printf("Match Start\n"); - pokerStartInit(poker); + // pokerStartInit(poker); } -void pokerMatchUpdate(poker_t *poker) { +void pokerMatchUpdate(poker_t *poker, engine_t *engine) { + float matchDiff = poker->matchStart - engine->time.current; } \ No newline at end of file diff --git a/src/poker/round/match.h b/src/poker/round/match.h index 068a5814..cf38c8bd 100644 --- a/src/poker/round/match.h +++ b/src/poker/round/match.h @@ -14,11 +14,12 @@ /** * Init the poker match round. * @param poker The poker game context. + * @param engine The engine context. */ -void pokerMatchInit(poker_t *poker); +void pokerMatchInit(poker_t *poker, engine_t *engine); /** * Update the poker match round. * @param poker The poker match to update for. */ -void pokerMatchUpdate(poker_t *poker); \ No newline at end of file +void pokerMatchUpdate(poker_t *poker, engine_t *engine); \ No newline at end of file diff --git a/src/poker/round/winner.c b/src/poker/round/winner.c index 100a0531..a1e0cd55 100644 --- a/src/poker/round/winner.c +++ b/src/poker/round/winner.c @@ -6,75 +6,7 @@ */ #include "winner.h" -int32_t _pokerWinnersSorter(void *left, void* right) { - return ((pokerwinning_t *)right)->type - ((pokerwinning_t *)left)->type; -} - -void pokerWinnersSort(pokerwinning_t *winnings, int32_t length) { - arraySort(sizeof(pokerwinning_t), - winnings, length, (arraysort_t *)&_pokerWinnersSorter - ); -} - - void pokerWinnerInit(poker_t *poker) { - uint8_t i, j, number, highNumber; - pokerwinning_t *left, *right; - pokerplayer_t *player; - card_t card, highCard; - bool winner; - - poker->winnerCount = 0; - - for(i = 0; i < POKER_PLAYER_COUNT; i++) { - left = poker->winnings + i; - left->type = POKER_WINNING_TYPE_NULL; - player = poker->players + i; - if(!pokerPlayerIsAlive(player)) continue; - - // Get the players' full hand. - pokerPlayerGetWinning(poker, player, left); - } - - for(i = 0; i < POKER_PLAYER_COUNT; i++) { - left = poker->winnings + i; - if(left->type == POKER_WINNING_TYPE_NULL) continue; - - winner = true; - highNumber = 0xFF; - - for(j = 0; j < POKER_PLAYER_COUNT; j++) { - if(i == j) continue; - - right = poker->winnings + j; - if(right->type == POKER_WINNING_TYPE_NULL) continue; - - // Am I the better hand? - if(left->type < right->type) continue; - if(left->type > right->type) { - // No - winner = false; - break; - } - - // Equal, compare hands. - card = pokerPlayerCompareWinning(left, right); - if(card == 0xFF) { - winner = false; - break; - } - - number = cardGetNumber(card); - if(highNumber == 0xFF || number == CARD_ACE || number > highNumber) { - highCard = card; - highNumber = number; - } - } - - if(!winner) continue; - left->kicker = highCard; - poker->winners[poker->winnerCount++] = i; - } - + pokerPlayerWinnerDetermine(poker); printf("Winner Count %u\n", poker->winnerCount); } \ No newline at end of file diff --git a/src/poker/round/winner.h b/src/poker/round/winner.h index 9f17f0f5..10cb1ebc 100644 --- a/src/poker/round/winner.h +++ b/src/poker/round/winner.h @@ -9,6 +9,4 @@ #include #include "../player.h" -int32_t _pokerWinnersSorter(void *left, void* right); -void pokerWinnersSort(pokerwinning_t *winnings, int32_t length); void pokerWinnerInit(poker_t *poker); \ No newline at end of file