Fixed Winner logic
This commit is contained in:
@ -8,6 +8,8 @@
|
|||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
void engineInit(engine_t *engine) {
|
void engineInit(engine_t *engine) {
|
||||||
|
randSeed(123);
|
||||||
|
|
||||||
epochInit(&engine->time);
|
epochInit(&engine->time);
|
||||||
renderInit();
|
renderInit();
|
||||||
inputInit(&engine->input);
|
inputInit(&engine->input);
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../libs.h"
|
#include "../libs.h"
|
||||||
|
#include "../util/rand.h"
|
||||||
#include "../input/input.h"
|
#include "../input/input.h"
|
||||||
#include "../epoch/epoch.h"
|
#include "../epoch/epoch.h"
|
||||||
#include "../display/render.h"
|
#include "../display/render.h"
|
||||||
|
@ -34,7 +34,7 @@ void _pokerGameActionBetOnUpdate(
|
|||||||
isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
|
isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX;
|
||||||
|
|
||||||
// Handle as an AI
|
// Handle as an AI
|
||||||
if(isHuman) {
|
if(isHuman && false) {
|
||||||
turn = game->ui.betTurn;
|
turn = game->ui.betTurn;
|
||||||
turnMade = game->ui.betTurnMade;
|
turnMade = game->ui.betTurnMade;
|
||||||
} else {
|
} else {
|
||||||
@ -90,6 +90,7 @@ void _pokerGameActionBetOnEnd(
|
|||||||
pokerdiscussiondata_t discussion;
|
pokerdiscussiondata_t discussion;
|
||||||
pokergame_t *game = (pokergame_t *)action->data;
|
pokergame_t *game = (pokergame_t *)action->data;
|
||||||
|
|
||||||
|
|
||||||
// Get which player is remaining to move.
|
// Get which player is remaining to move.
|
||||||
game->poker.bet.better = pokerBetGetRemainingPlayer(
|
game->poker.bet.better = pokerBetGetRemainingPlayer(
|
||||||
&game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
&game->poker.bet, game->poker.players, game->poker.roundSmallBlind
|
||||||
@ -109,6 +110,9 @@ void _pokerGameActionBetOnEnd(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prep convo
|
||||||
|
discussion.poker = game;
|
||||||
|
|
||||||
// Not waiting, restack and do next action.
|
// Not waiting, restack and do next action.
|
||||||
printf("Not waiting on anything!\n");
|
printf("Not waiting on anything!\n");
|
||||||
|
|
||||||
@ -116,7 +120,6 @@ void _pokerGameActionBetOnEnd(
|
|||||||
next = pokerActionNextFlopAdd(queue, &game->poker);
|
next = pokerActionNextFlopAdd(queue, &game->poker);
|
||||||
if(next != NULL) {
|
if(next != NULL) {
|
||||||
discussion.reason = POKER_DISCUSSION_REASON_FLOP;
|
discussion.reason = POKER_DISCUSSION_REASON_FLOP;
|
||||||
discussion.poker = game;
|
|
||||||
pokerDiscussionQueue(&discussion);
|
pokerDiscussionQueue(&discussion);
|
||||||
|
|
||||||
pokerBetResetBetter(
|
pokerBetResetBetter(
|
||||||
@ -128,8 +131,13 @@ void _pokerGameActionBetOnEnd(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Queue a restack */
|
// Done betting
|
||||||
printf("All betting is done, reveal\n");
|
printf("All betting is done, reveal\n");
|
||||||
|
discussion.reason = POKER_DISCUSSION_REASON_BETTING_DONE;
|
||||||
|
discussion.poker = game;
|
||||||
|
pokerDiscussionQueue(&discussion);
|
||||||
|
pokerGameActionRestackAdd(game);
|
||||||
|
pokerGameActionWinnerAdd(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
|
queueaction_t * pokerGameActionBetAdd(pokergame_t *game) {
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../../../libs.h"
|
#include "../../../libs.h"
|
||||||
#include "action.h"
|
#include "../../../poker/actions/flop.h"
|
||||||
#include "restack.h"
|
|
||||||
#include "../../../input/input.h"
|
|
||||||
#include "../../../poker/turn.h"
|
#include "../../../poker/turn.h"
|
||||||
#include "../../../poker/bet.h"
|
#include "../../../poker/bet.h"
|
||||||
#include "../../../poker/actions/flop.h"
|
|
||||||
#include "../pokerdiscussion.h"
|
#include "../pokerdiscussion.h"
|
||||||
|
#include "action.h"
|
||||||
|
#include "restack.h"
|
||||||
|
#include "winner.h"
|
||||||
|
|
||||||
/** Callback when the bet action is updated. */
|
/** Callback when the bet action is updated. */
|
||||||
void _pokerGameActionBetOnUpdate(
|
void _pokerGameActionBetOnUpdate(
|
||||||
|
32
src/game/poker/actions/winner.c
Normal file
32
src/game/poker/actions/winner.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "winner.h"
|
||||||
|
|
||||||
|
void _pokerGameActionWinnerOnStart(
|
||||||
|
queue_t *queue, queueaction_t *action, uint8_t i
|
||||||
|
) {
|
||||||
|
pokergame_t *game = (pokergame_t *)action->data;
|
||||||
|
printf("Winner start action");
|
||||||
|
pokerWinnerCalculate(
|
||||||
|
&game->poker.winner,
|
||||||
|
&game->poker.dealer,
|
||||||
|
game->poker.players
|
||||||
|
);
|
||||||
|
|
||||||
|
printf("Winner Count %u\n", game->poker.winner.winnerCount);
|
||||||
|
for(uint8_t i = 0; i < game->poker.winner.winnerCount; i++) {
|
||||||
|
uint8_t winner = game->poker.winner.winners[i];
|
||||||
|
printf("Winner %u\n", winner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
queueaction_t * pokerGameActionWinnerAdd(pokergame_t *game) {
|
||||||
|
queueaction_t *action = pokerGameActionAdd(game);
|
||||||
|
action->onStart = &_pokerGameActionWinnerOnStart;
|
||||||
|
return action;
|
||||||
|
}
|
25
src/game/poker/actions/winner.h
Normal file
25
src/game/poker/actions/winner.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "../../../libs.h"
|
||||||
|
#include "../../../poker/winner.h"
|
||||||
|
#include "../pokerdiscussion.h"
|
||||||
|
#include "action.h"
|
||||||
|
|
||||||
|
/** Callback to fire when the winner starts */
|
||||||
|
void _pokerGameActionWinnerOnStart(
|
||||||
|
queue_t *queue, queueaction_t *action, uint8_t i
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queue a winning game action.
|
||||||
|
*
|
||||||
|
* @param game Game to queue for.
|
||||||
|
* @return The queued winning action.
|
||||||
|
*/
|
||||||
|
queueaction_t * pokerGameActionWinnerAdd(pokergame_t *game);
|
@ -96,6 +96,8 @@ void pokerDiscussionGet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pokerDiscussionQueue(pokerdiscussiondata_t *data) {
|
void pokerDiscussionQueue(pokerdiscussiondata_t *data) {
|
||||||
|
return;
|
||||||
|
|
||||||
pokerdiscussion_t discussion;
|
pokerdiscussion_t discussion;
|
||||||
uint8_t i, player;
|
uint8_t i, player;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#define POKER_DISCUSSION_REASON_PLAYER_RAISING 0x07
|
#define POKER_DISCUSSION_REASON_PLAYER_RAISING 0x07
|
||||||
#define POKER_DISCUSSION_REASON_FLOP 0x08
|
#define POKER_DISCUSSION_REASON_FLOP 0x08
|
||||||
#define POKER_DISCUSSION_REASON_DEAL 0x09
|
#define POKER_DISCUSSION_REASON_DEAL 0x09
|
||||||
|
#define POKER_DISCUSSION_REASON_BETTING_DONE 0x0A
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
pokergame_t *poker;
|
pokergame_t *poker;
|
||||||
|
@ -116,6 +116,13 @@ void pokerUiRender(
|
|||||||
imageRender(&ui->card, &assets->shader, i * 64.0f, j * 100.0f);
|
imageRender(&ui->card, &assets->shader, i * 64.0f, j * 100.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(j = 0; j < poker->dealer.cardsFacing; j++) {
|
||||||
|
pokerUiSetImageToCard(
|
||||||
|
&ui->card, &assets->cardTexture, poker->dealer.cards[j]
|
||||||
|
);
|
||||||
|
imageRender(&ui->card, &assets->shader, 200, j * 100.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Betting UI
|
// Betting UI
|
||||||
|
@ -258,10 +258,18 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ
|
|||||||
card = left->set[i];
|
card = left->set[i];
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
if(highNumberLeft != 0xFF && number < highNumberLeft) continue;// Quick check
|
if(highNumberLeft != 0xFF && number < highNumberLeft) continue;// Quick check
|
||||||
index = cardContainsNumber(right->set, right->setSize, number);
|
|
||||||
if(index != -1) continue;// In other?
|
|
||||||
|
|
||||||
if(highNumberLeft == 0xFF||number == CARD_ACE||highNumberRight < number) {
|
// Check if this number is within the other hand or not
|
||||||
|
index = cardContainsNumber(right->set, right->setSize, number);
|
||||||
|
if(index != -1) {
|
||||||
|
// This number IS within the other hand, let's check that the EXACT card
|
||||||
|
// is a match/isn't a match.
|
||||||
|
index = cardContains(right->set, right->setSize, card);
|
||||||
|
if(index != -1) continue;// Exact card match
|
||||||
|
// Not exact card match.. ?
|
||||||
|
}
|
||||||
|
|
||||||
|
if(highNumberLeft == 0xFF||number == CARD_ACE||highNumberLeft < number) {
|
||||||
highNumberLeft = number;
|
highNumberLeft = number;
|
||||||
highCardLeft = card;
|
highCardLeft = card;
|
||||||
}
|
}
|
||||||
@ -271,8 +279,12 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ
|
|||||||
card = right->set[i];
|
card = right->set[i];
|
||||||
number = cardGetNumber(card);
|
number = cardGetNumber(card);
|
||||||
if(highNumberRight != 0xFF && number < highNumberRight) continue;
|
if(highNumberRight != 0xFF && number < highNumberRight) continue;
|
||||||
|
|
||||||
index = cardContainsNumber(left->set, left->setSize, number);
|
index = cardContainsNumber(left->set, left->setSize, number);
|
||||||
if(index != -1) continue;
|
if(index != -1) {
|
||||||
|
index = cardContains(left->set, left->setSize, card);
|
||||||
|
if(index != -1) continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(highNumberRight == 0xFF||number == CARD_ACE||highNumberRight < number) {
|
if(highNumberRight == 0xFF||number == CARD_ACE||highNumberRight < number) {
|
||||||
highNumberRight = number;
|
highNumberRight = number;
|
||||||
@ -280,6 +292,11 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(highCardLeft == 0xFF && highCardRight == 0xFF) {
|
||||||
|
printf("Here\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(highCardLeft == 0xFF) return 0xFF;
|
||||||
if(highNumberLeft < highNumberRight) return 0xFF;
|
if(highNumberLeft < highNumberRight) return 0xFF;
|
||||||
return highCardLeft;//Greater or Equal to.
|
return highCardLeft;//Greater or Equal to.
|
||||||
}
|
}
|
||||||
@ -294,6 +311,7 @@ void pokerWinnerCalculate(
|
|||||||
bool isWinner;
|
bool isWinner;
|
||||||
|
|
||||||
winner->winnerCount = 0;
|
winner->winnerCount = 0;
|
||||||
|
highCard = 0xFF;
|
||||||
|
|
||||||
// Get winning sets
|
// Get winning sets
|
||||||
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
|
||||||
|
@ -9,6 +9,12 @@
|
|||||||
#include "../libs.h"
|
#include "../libs.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed the random number generator
|
||||||
|
* @param seed Seed to use for the seeded random number generator.
|
||||||
|
*/
|
||||||
|
#define randSeed(seed) (srand(seed))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a random int32_t.
|
* Generates a random int32_t.
|
||||||
* @returns A random int32_t number.
|
* @returns A random int32_t number.
|
||||||
|
Reference in New Issue
Block a user