Committing progress
This commit is contained in:
@@ -40,18 +40,12 @@ void conversationQueueBeginBetting() {
|
||||
if(POKER_PLAYER_BETTER == POKER_HUMAN_INDEX) {
|
||||
// This is the human player.
|
||||
BGB_MESSAGE("Player betting.");
|
||||
POKER_PLAYERS[
|
||||
POKER_PLAYER_BETTER
|
||||
].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
|
||||
} else {
|
||||
// This is an AI player.
|
||||
BGB_MESSAGE("AI turn to bet");
|
||||
POKER_PLAYERS[
|
||||
POKER_PLAYER_BETTER
|
||||
].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
|
||||
}
|
||||
QUEUE_ITEM = QUEUE_NEXT_BETTER;
|
||||
conversationQueueNext();
|
||||
conversationPause(1);
|
||||
}
|
||||
|
||||
void conversationQueueNextBetter() {
|
||||
@@ -80,6 +74,9 @@ void conversationQueueNextBetter() {
|
||||
POKER_PLAYERS[j].state &
|
||||
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND
|
||||
) != 0) {
|
||||
//TODO: Refer to pokerbet function, but basically I can't let the player
|
||||
//bet if they have bet more money than the second richest player.
|
||||
|
||||
// Check each pot, if the pot is inactive or the player is CALLED/CHECKED
|
||||
for(k = 0; k < POKER_POT_COUNT_MAX; k++) {
|
||||
// Is this pot active?
|
||||
@@ -98,12 +95,10 @@ void conversationQueueNextBetter() {
|
||||
}
|
||||
|
||||
// They haven't bet yet, make them the "next better"
|
||||
BGB_printf("NEXT BETTER IS NOW %d", j);
|
||||
POKER_PLAYER_BETTER = j;
|
||||
|
||||
QUEUE_ITEM = QUEUE_BEGIN_BETTING;
|
||||
conversationPause(1);
|
||||
// conversationQueueNext();
|
||||
conversationQueueNext();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -116,17 +116,76 @@ void pokerNewRound() {
|
||||
}
|
||||
|
||||
inline void pokerBet(uint8_t player, uint16_t amount) {
|
||||
// TODO: This may become a function because if a player doesn't have enough
|
||||
// chips to bet to the active pot, then the pot needs to autosplit, take those
|
||||
// who have bet into the pot up to the amount that the player betting can bet,
|
||||
// and push them into a new pot.
|
||||
// There also needs to be a limit on this, for example;
|
||||
// player 0 has $1200, and bets $1000, he can't bet more than that ever.
|
||||
// player 1 has $1000, and bets all of it. The remanin
|
||||
// player 2 has $700, and bets all o it. A new $300 sidepot auto creates
|
||||
// player 3 has $500 and bets all of it, Another sidepot with $200 is auto made.
|
||||
// TODO: This may become a function because if a player doesn't have enough
|
||||
// chips to bet to the active pot, then the pot needs to autosplit, take those
|
||||
// who have bet into the pot up to the amount that the player betting can bet,
|
||||
// and push them into a new pot.
|
||||
// There also needs to be a limit on this, for example;
|
||||
// player 0 has $1200, and bets $1000, they can't bet more than that ever.
|
||||
// player 1 has $1000, and bets all of it. The remanin
|
||||
// player 2 has $700, and bets all o it. A new $300 sidepot auto creates
|
||||
// player 3 has $500 and bets all of it, Another sidepot with $200 is auto made.
|
||||
POKER_PLAYERS[player].state |= POKER_PLAYER_STATE_HAS_BET_THIS_ROUND;
|
||||
POKER_PLAYERS[player].chips -= amount;
|
||||
POKER_POTS[POKER_POT_CURRENT].chips += amount;
|
||||
POKER_POTS[POKER_POT_CURRENT].players[player] += amount;
|
||||
POKER_POTS[POKER_POT_CURRENT].call = MATH_MAX(
|
||||
amount, POKER_POTS[POKER_POT_CURRENT].players[player]
|
||||
);
|
||||
}
|
||||
|
||||
POKER_PLAYERS[player].chips -= amount;\
|
||||
POKER_POTS[POKER_POT_CURRENT].chips += amount;\
|
||||
POKER_POTS[POKER_POT_CURRENT].call = amount;
|
||||
inline uint8_t pokerGetCallBet(uint8_t player) {
|
||||
return (
|
||||
POKER_POTS[POKER_POT_CURRENT].call -
|
||||
POKER_POTS[POKER_POT_CURRENT].players[POKER_PLAYER_BETTER]
|
||||
);
|
||||
}
|
||||
|
||||
void pokerAi(uint8_t player) {
|
||||
uint8_t i, cardNumber0, cardNumber1, suitNumber0, suitNumber1;
|
||||
uint16_t callBet;
|
||||
uint8_t confidence;// TODO: Determine type.
|
||||
pokerplayer_t *plyr = POKER_PLAYERS + player;
|
||||
|
||||
// The following logic is heavily inspired by;
|
||||
// https://github.com/gorel/C-Poker-AI/blob/master/src/common/pokerai.c
|
||||
// But with some changes and smarts added by me. The original source code will
|
||||
// essentially just run a crap tun of simulated games and get the times that
|
||||
// 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
|
||||
cardNumber0 = cardGetNumber(plyr->hand[0]);
|
||||
cardNumber1 = cardGetNumber(plyr->hand[1]);
|
||||
suitNumber0 = cardGetSuit(plyr->hand[0]);
|
||||
suitNumber1 = cardGetSuit(plyr->hand[1]);
|
||||
|
||||
// Get delta between cards
|
||||
i = MATH_ABS(cardNumber0 - cardNumber1);
|
||||
|
||||
// Get card weight
|
||||
confidence = cardNumber0 + cardNumber1;
|
||||
if(cardNumber0 == cardNumber1) {// Pairs
|
||||
confidence += 6;
|
||||
} else if(suitNumber0 == suitNumber1) {// Same suit
|
||||
confidence += 4;
|
||||
}
|
||||
|
||||
// Get difference from cards for guessing flush
|
||||
if(i > 4) {
|
||||
confidence -= 4;
|
||||
} else if(i > 2) {
|
||||
confidence -= i;
|
||||
}
|
||||
} else {
|
||||
// Simulate my hand being the winning hand, use that as the confidence
|
||||
// TODO: Repurpose old code lmao. Just take it from Dawn-C
|
||||
}
|
||||
|
||||
// Now we know how confident the AI is, let's put a chip value to that weight
|
||||
// How many chips to call?
|
||||
callBet = pokerGetCallBet(player);
|
||||
}
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../util.h"
|
||||
#include "card.h"
|
||||
#include "player.h"
|
||||
#include "pot.h"
|
||||
@@ -34,4 +35,6 @@ void pokerInit();
|
||||
|
||||
void pokerNewRound();
|
||||
|
||||
inline void pokerBet(uint8_t player, uint16_t amount);
|
||||
inline void pokerBet(uint8_t player, uint16_t amount);
|
||||
|
||||
inline uint8_t pokerGetCallBet(uint8_t player);
|
@@ -9,4 +9,5 @@
|
||||
#include "libs.h"
|
||||
|
||||
#define MATH_MIN(a, b) a > b ? b : a
|
||||
#define MATH_MAX(a, b) a < b ? b : a
|
||||
#define MATH_MAX(a, b) a < b ? b : a
|
||||
#define MATH_ABS(n) (n < 0 ? -n : n)
|
Reference in New Issue
Block a user