Working on more AI kinks.

This commit is contained in:
2021-09-27 21:53:56 -07:00
parent 4ef0766506
commit 25e683b512
11 changed files with 54 additions and 44 deletions

View File

@ -23,6 +23,7 @@ void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action ,uint8_t i){
pokerDealerInit(&poker->dealer);
// Reset the players
printf("Resetting the players\n");
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
pokerPlayerReset(poker->players + i);
}

View File

@ -33,12 +33,21 @@ void pokerBetResetBetter(
) {
uint8_t i;
pokerplayer_t *player;
// Reset the round betting state.
for(i = 0; i < POKER_PLAYER_COUNT; i++) {
player = players + i;
player->state = flagOff(player->state, POKER_PLAYER_STATE_ROUND_MOVE);
}
// Now reset to the first player that needs to bet.
// We do this step first to reset the better
bet->better = pokerBetGetRoundPlayerDefault(roundSmallBlind);
// Then we check who's remaining. We do this because the default better may
// have folded already.
bet->better = pokerBetGetRemainingPlayer(bet, players, roundSmallBlind);
}
bool pokerBetPlayerCanBet(pokerbet_t *bet, pokerplayer_t *player) {

View File

@ -31,7 +31,6 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
// they are expected to win from those games, but I'm just going to use the
// odds of the winning hand.
// Is this preflop?
if(poker->dealer.cardsFacing == 0 && player->cardCount >= 2) {
// Get the hand weight
@ -123,7 +122,7 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
amount = maxBet;
}
} else if (confidence < 0.95 || poker->dealer.cardsFacing < 0x04) {
if(random < 30) {
if(random < 20) {
amount = callBet;
} else {
amount = maxBet;
@ -132,19 +131,21 @@ pokerturn_t pokerTurnGet(poker_t *poker, uint8_t playerIndex) {
amount = (player->chips - callBet) * 9 / 10;
}
if(isBluff) printf("Mum I'm bluffing\n");
printf("Raised %i times\n", player->timesRaised);
// Let's not get caught in a raising loop with AI.
if(player->timesRaised >= POKER_TURN_MAX_RAISES) {
printf("Calling instead.\n");
amount = callBet;
// If this is the first round... make it a lot less likely I'll bet
if(poker->dealer.cardsFacing == 0x00 && amount > callBet) {
if(random > 5) amount = callBet;
}
// Did we actually bet?
if(amount > 0) {
amount = mathMin(amount, callBet);
printf("I plan on betting %i chips\n", amount);
// Let's not get caught in a raising loop with AI.
if(player->timesRaised >= POKER_TURN_MAX_RAISES) {
amount = callBet;
}
amount = mathMax(amount, callBet);
turn = pokerTurnRaise(poker, playerIndex, amount);
turn.confidence = confidence;
} else if(pokerTurnCanPlayerCheck(poker, playerIndex)) {
@ -170,10 +171,12 @@ void pokerTurnAction(poker_t *poker, pokerplayer_t *player, pokerturn_t *turn) {
case POKER_TURN_TYPE_CHECK:
pokerBetPlayer(&poker->bet, player, 0);
player->timesRaised = 0;
break;
case POKER_TURN_TYPE_FOLD:
player->state |= POKER_PLAYER_STATE_FOLDED;
player->timesRaised = 0;
break;
}
@ -193,9 +196,7 @@ pokerturn_t pokerTurnFold(poker_t *poker, uint8_t player) {
}
pokerturn_t pokerTurnCheck(poker_t *poker, uint8_t player) {
pokerturn_t turn;
turn.type = POKER_TURN_TYPE_CHECK;
return turn;
return pokerTurnRaise(poker, player, 0);
}
pokerturn_t pokerTurnCall(poker_t *poker, uint8_t playerIndex) {
@ -213,9 +214,10 @@ pokerturn_t pokerTurnRaise(poker_t *poker, uint8_t playerIndex, int32_t chips) {
pokerplayer_t *player;
player = poker->players + playerIndex;
if(chips < poker->bet.currentBet) chips = poker->bet.currentBet;
if(player->chips <= chips) {
if(chips == 0) {
turn.type = POKER_TURN_TYPE_CHECK;
turn.chips = 0;
} else if(player->chips <= chips) {
turn.chips = player->chips;
turn.type = POKER_TURN_TYPE_ALL_IN;
} else {

View File

@ -32,15 +32,15 @@
#define POKER_WINNNIG_TYPE_HIGH_CARD 0x0A
#define POKER_WINNNIG_CONFIDENCE_ROYAL_FLUSH 1.0f
#define POKER_WINNNIG_CONFIDENCE_STRAIGHT_FLUSH 0.9f
#define POKER_WINNNIG_CONFIDENCE_FOUR_OF_A_KIND 0.85f
#define POKER_WINNNIG_CONFIDENCE_FULL_HOUSE 0.83f
#define POKER_WINNNIG_CONFIDENCE_STRAIGHT_FLUSH 0.99f
#define POKER_WINNNIG_CONFIDENCE_FOUR_OF_A_KIND 0.9f
#define POKER_WINNNIG_CONFIDENCE_FULL_HOUSE 0.85f
#define POKER_WINNNIG_CONFIDENCE_FLUSH 0.8f
#define POKER_WINNNIG_CONFIDENCE_STRAIGHT 0.75f
#define POKER_WINNNIG_CONFIDENCE_THREE_OF_A_KIND 0.75f
#define POKER_WINNNIG_CONFIDENCE_TWO_PAIR 0.7f
#define POKER_WINNNIG_CONFIDENCE_PAIR 0.6f
#define POKER_WINNNIG_CONFIDENCE_HIGH_CARD 0.5f
#define POKER_WINNNIG_CONFIDENCE_STRAIGHT 0.7f
#define POKER_WINNNIG_CONFIDENCE_THREE_OF_A_KIND 0.5f
#define POKER_WINNNIG_CONFIDENCE_TWO_PAIR 0.4f
#define POKER_WINNNIG_CONFIDENCE_PAIR 0.2f
#define POKER_WINNNIG_CONFIDENCE_HIGH_CARD 0.1f
/** Holds information about a player's winning state */
typedef struct {