Working on AI

This commit is contained in:
2022-01-15 09:42:47 -08:00
parent 31a6271f27
commit 4d9152a6a3
6 changed files with 185 additions and 41 deletions

View File

@@ -66,12 +66,12 @@ void pokerNewRound() {
POKER_DECK_SIZE = CARD_DECK_SIZE;
// Shuffle Deck
for(i = CARD_DECK_SIZE-1; i > 0; i--) {
k = POKER_DECK[i];
j = rand() % (i+1);
POKER_DECK[i] = POKER_DECK[j];
POKER_DECK[j] = k;
}
// for(i = CARD_DECK_SIZE-1; i > 0; i--) {
// k = POKER_DECK[i];
// j = rand() % (i+1);
// POKER_DECK[i] = POKER_DECK[j];
// POKER_DECK[j] = k;
// }
// Reset Players and decide new blinds.
found = 0;
@@ -146,7 +146,6 @@ void pokerAi(uint8_t player, pokerturn_t *turn) {
uint8_t i, cardNumber0, cardNumber1, suitNumber0, suitNumber1;
uint16_t callBet, maxBet, amount, bluffBet;
uint8_t random;// TODO: Determine type.
bool isBluff;
uint16_t confidence, expectedGain, potOdds;
pokerplayer_t *plyr = POKER_PLAYERS + player;
@@ -157,7 +156,6 @@ void pokerAi(uint8_t player, pokerturn_t *turn) {
// they are expected to win from those games, but I'm just going to use the
// odds of the hand being the winning hand.
// Is this preflop?
if(POKER_COMMUNITY_SIZE == 0) {
// Get the hand weight
@@ -211,34 +209,36 @@ void pokerAi(uint8_t player, pokerturn_t *turn) {
// Now work out the pot odds, this is basically "how many times the callbet
// could I win if I win this hand". e.g. Desirable hands will have an
// expected gain much higher than the callbet.
//TODO: not float
potOdds = callBet / (callBet + expectedGain);
potOdds = plyr->chips / 1000;
potOdds = MATH_MAX((callBet + expectedGain), 1) / MATH_MAX(potOdds, 1);
} else {
// If the call bet is zero then there's fairly equal odds, so let's just
// take the chances out of the remainig player count.
potOdds = 1000 / pokerGetRemainingBetterCount();
potOdds = 1000 / pokerGetRemainingBetterCount() * 2;// 0 - 1000
}
// Now determine the expected ROI
// TODO: not float
expectedGain = confidence / potOdds;
//TODO: I think these values are a bit odd.
expectedGain = (confidence*100) / (potOdds / 10);
// Now get a random number 0-100.
random = rand() % 100;
// Determine the max bet that the AI is willing to make. This is valued as
// "3/4 chips remaining - random(0-50)" and subtract the callbet. I will
// probably chance this since the random 0-50 is.. random
// TODO: Rewrite this
maxBet = plyr->chips - (random / 2);
maxBet -= callBet;
// Determine the max bet that the AI is willing to make. The max bet is
// basically how high the AI is willing to bet.
maxBet = plyr->chips;// TODO: Replace with below code and test, just running
// With this for now.
// maxBet = plyr->chips / MATH_MAX(random / 10, 1);
// maxBet -= callBet;
// BGB_printf("Rand %u, Max Bet %u", random, callBet);
// Determine what's a good bluff bet.
// TODO: not float
bluffBet = random * maxBet / 100 / 2;
bluffBet = maxBet;
// bluffBet = ((random * 100) / maxBet) * plyr->chips;
// Now prep the output
isBluff = false;
turn->bluff = false;
amount = 0;
// Now the actual AI can happen. This is basically a weight to confidence
@@ -249,17 +249,17 @@ void pokerAi(uint8_t player, pokerturn_t *turn) {
amount = 0;
} else {
amount = bluffBet;
isBluff = true;
turn->bluff = true;
}
} else if ((expectedGain < 1000 && confidence < 850) || confidence < 100) {
if (random < 80) {
amount = 0;
} else if(random < 5) {
amount = callBet;
isBluff = true;
turn->bluff = true;
} else {
amount = bluffBet;
isBluff = true;
turn->bluff = true;
}
} else if ((expectedGain < 1300 && confidence < 900) || confidence < 500) {
if (random < 60 || confidence < 500) {
@@ -274,6 +274,7 @@ void pokerAi(uint8_t player, pokerturn_t *turn) {
amount = maxBet;
}
} else {
// TODO: check this
amount = (plyr->chips - callBet) * 9 / 10;
}
@@ -282,21 +283,31 @@ void pokerAi(uint8_t player, pokerturn_t *turn) {
if(random > 5) amount = callBet;
}
// Did we actually bet?
if(amount > 0) {
// Let's not get caught in a raising loop with AI.
if(plyr->timesRaised >= POKER_TURN_MAX_RAISES) {
amount = callBet;
}
if(plyr->timesRaised >= POKER_TURN_MAX_RAISES) amount = callBet;
amount = MATH_MAX(amount, callBet);
// turn = pokerTurnBet(poker, playerIndex, amount);
amount = MATH_MIN(amount, plyr->chips);
turn->chips = amount;
turn->confidence = confidence;
if(amount == plyr->chips) {
turn->type == POKER_TURN_TYPE_ALL_IN;
} else if(amount == callBet) {
turn->type = POKER_TURN_TYPE_CALL;
} else {
turn->type == POKER_TURN_TYPE_BET;
}
} else if(pokerCanPlayerCheck(player)) {
// turn = pokerTurnBet(poker, playerIndex, 0);
turn->type = POKER_TURN_TYPE_CHECK;
turn->chips = 0;
turn->confidence = 1000;
} else {
// turn = pokerTurnFold(poker, playerIndex);
turn->type = POKER_TURN_TYPE_FOLD;
turn->chips = 0;
turn->confidence = 1000 - confidence;
}
}