Last commit before another big refactor

This commit is contained in:
2021-07-12 09:31:22 -07:00
parent 1b2bf0c434
commit 25ab7cc101
20 changed files with 5475 additions and 116 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 155 KiB

File diff suppressed because one or more lines are too long

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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]
);
);
/**
* 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);

View File

@ -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);
}
}

View File

@ -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);
void pokerPlayerWinnerDetermine(poker_t *poker);

View File

@ -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:

View File

@ -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

View File

@ -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.

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
void pokerMatchUpdate(poker_t *poker, engine_t *engine);

View File

@ -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);
}

View File

@ -9,6 +9,4 @@
#include <dawn/dawn.h>
#include "../player.h"
int32_t _pokerWinnersSorter(void *left, void* right);
void pokerWinnersSort(pokerwinning_t *winnings, int32_t length);
void pokerWinnerInit(poker_t *poker);