From ad50ff54f6d310b520ba88f93b42807e98def8ae Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 21 Sep 2021 20:55:42 -0700 Subject: [PATCH] Working on winning logic. --- src/game/poker/actions/bet.c | 2 +- src/game/poker/actions/winner.c | 3 +++ src/game/poker/actions/winner.h | 1 + src/game/poker/pokerdiscussion.c | 2 -- src/poker/turn.c | 23 ++++++++++++++++++++++- src/poker/turn.h | 13 ++++++++++++- src/poker/winner.c | 27 ++++++++++++++++++++++++--- 7 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/game/poker/actions/bet.c b/src/game/poker/actions/bet.c index 0eed7a1e..7ccb853e 100644 --- a/src/game/poker/actions/bet.c +++ b/src/game/poker/actions/bet.c @@ -34,7 +34,7 @@ void _pokerGameActionBetOnUpdate( isHuman = game->poker.bet.better == POKER_PLAYER_HUMAN_INDEX; // Handle as an AI - if(isHuman && false) { + if(isHuman) { turn = game->ui.betTurn; turnMade = game->ui.betTurnMade; } else { diff --git a/src/game/poker/actions/winner.c b/src/game/poker/actions/winner.c index b0002914..c98369ca 100644 --- a/src/game/poker/actions/winner.c +++ b/src/game/poker/actions/winner.c @@ -23,6 +23,9 @@ void _pokerGameActionWinnerOnStart( uint8_t winner = game->poker.winner.winners[i]; printf("Winner %u\n", winner); } + + pokerGameActionRoundAdd(game); + queueNext(queue); } queueaction_t * pokerGameActionWinnerAdd(pokergame_t *game) { diff --git a/src/game/poker/actions/winner.h b/src/game/poker/actions/winner.h index de9069d6..4d7827bf 100644 --- a/src/game/poker/actions/winner.h +++ b/src/game/poker/actions/winner.h @@ -10,6 +10,7 @@ #include "../../../poker/winner.h" #include "../pokerdiscussion.h" #include "action.h" +#include "round.h" /** Callback to fire when the winner starts */ void _pokerGameActionWinnerOnStart( diff --git a/src/game/poker/pokerdiscussion.c b/src/game/poker/pokerdiscussion.c index aec958da..9847dc32 100644 --- a/src/game/poker/pokerdiscussion.c +++ b/src/game/poker/pokerdiscussion.c @@ -96,8 +96,6 @@ void pokerDiscussionGet( } void pokerDiscussionQueue(pokerdiscussiondata_t *data) { - return; - pokerdiscussion_t discussion; uint8_t i, player; diff --git a/src/poker/turn.c b/src/poker/turn.c index 713a21b0..e30a4fd6 100644 --- a/src/poker/turn.c +++ b/src/poker/turn.c @@ -9,6 +9,7 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) { pokerplayer_t *player; + float confidence; player = poker->players + playerIndex; // Can the player do anything? @@ -16,11 +17,31 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) { return pokerTurnOut(poker, playerIndex); } + // Now we basically need to determine the AI's action here. The AI really only + // needs to do one thing, decide whether or not they want to Bet or Not. + // In future I may make checking optional, but for now there's really no + // reason not to. + + // Get the current winning hand. + pokerplayerwinning_t winning; + pokerWinnerPlayerGet(&poker->dealer, player, &winning); + + // Now let's determine the "base confidence". This is basically how good the + // hand is relative to a completely equal footing/player field. + confidence = winning.type->weight; + + // Now we have a base confidence, let's figure out how good our hand is based + // on our high card. This will decide whether or not our hand is as strong as + // it seems on its base level + + // Well, now they have decided to "not bet", or really they think that their + // cards are not worth the effort. But if they CAN check, they will. if(pokerTurnCanPlayerCheck(poker, playerIndex)) { return pokerTurnCheck(poker, playerIndex); } - return pokerTurnCall(poker, playerIndex); + // Nothing worth doing, so let's just fold here. + return pokerTurnFold(poker, playerIndex); } void pokerTurnAction(poker_t *poker, pokerplayer_t *player, pokerturn_t *turn) { diff --git a/src/poker/turn.h b/src/poker/turn.h index bbdb9a50..86c52c9f 100644 --- a/src/poker/turn.h +++ b/src/poker/turn.h @@ -17,13 +17,24 @@ #define POKER_TURN_TYPE_CALL_ALL_IN 0x04 #define POKER_TURN_TYPE_CHECK 0x05 +#define POKER_TURN_CONFIDENCE_ROYAL_FLUSH 1.0f +#define POKER_TURN_CONFIDENCE_STRAIGHT_FLUSH 0.9f +#define POKER_TURN_CONFIDENCE_FOUR_OF_A_KIND 0.85f +#define POKER_TURN_CONFIDENCE_FULL_HOUSE 0.83f +#define POKER_TURN_CONFIDENCE_FLUSH 0.8f +#define POKER_TURN_CONFIDENCE_STRAIGHT 0.75f +#define POKER_TURN_CONFIDENCE_THREE_OF_A_KIND 0.75f +#define POKER_TURN_CONFIDENCE_TWO_PAIR 0.7f +#define POKER_TURN_CONFIDENCE_PAIR 0.6f +#define POKER_TURN_CONFIDENCE_HIGH_CARD 0.5f + /** The turn that a player/the AI decided to do for its turn */ typedef struct { /** What type of action the turn is */ uint8_t type; /** How many chips they did in their turn (if applicable) */ int32_t chips; - /** How confident the AI is about their turn. */ + /** How confident the AI is about their turn. 0 = none, 1 = full */ float confidence; } pokerturn_t; diff --git a/src/poker/winner.c b/src/poker/winner.c index 317a5fab..e0fc1dd8 100644 --- a/src/poker/winner.c +++ b/src/poker/winner.c @@ -7,6 +7,10 @@ #include "winner.h" +void pokerWinnerGetBestCard(card_t *cards, uint8_t cardCount) { + +} + void pokerWinnerHandGetFull( pokerdealer_t *dealer, pokerplayer_t *player, card_t *cards ) { @@ -247,12 +251,15 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ uint8_t i, number; card_t card; int32_t index; + uint8_t countCardsSame; card_t highCardLeft, highCardRight; uint8_t highNumberLeft, highNumberRight; highNumberLeft = 0xFF; highNumberRight = 0xFF; + countCardsSame = 0; + for(i = 0; i < left->setSize; i++) { card = left->set[i]; @@ -265,7 +272,12 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ // 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 + + // Exact card match + if(index != -1) { + countCardsSame++; + continue; + } // Not exact card match.. ? } @@ -292,8 +304,17 @@ card_t pokerWinnerCompare(pokerplayerwinning_t *left, pokerplayerwinning_t *righ } } - if(highCardLeft == 0xFF && highCardRight == 0xFF) { - printf("Here\n"); + + if(countCardsSame == left->setSize) { + for(i = 0; i < left->setSize; i++) { + card = left->set[i]; + number = cardGetNumber(card); + if(highNumberLeft == 0xFF||number == CARD_ACE||highNumberLeft < number) { + highNumberLeft = number; + highCardLeft = card; + } + } + return highCardLeft; } if(highCardLeft == 0xFF) return 0xFF;