Cleanup of poker code done, about to start testing.
This commit is contained in:
@ -60,8 +60,8 @@ void PokerPlayer::bet(
|
||||
pot.chips += chips;
|
||||
pot.call = Math::max<int32_t>(pot.call, this ->currentBet);
|
||||
|
||||
auto existing = std::find(pot.players.begin(), pot.players.end(), this);
|
||||
if(existing == pot.players.end()) pot.players.push_back(this);
|
||||
auto existing = std::find(pot.players.begin(), pot.players.end(), shared_from_this());
|
||||
if(existing == pot.players.end()) pot.players.push_back(shared_from_this());
|
||||
}
|
||||
|
||||
void PokerPlayer::bet(const int32_t chips) {
|
||||
@ -98,7 +98,7 @@ struct PokerTurn PokerPlayer::getAITurn() {
|
||||
|
||||
// Can the player do anything?
|
||||
if(this->isFolded || this->isOut) {
|
||||
turn.type = POKER_TURN_TYPE_OUT;
|
||||
turn.type = PokerTurnType::Out;
|
||||
return turn;
|
||||
}
|
||||
|
||||
@ -241,13 +241,13 @@ struct PokerTurn PokerPlayer::getAITurn() {
|
||||
}
|
||||
|
||||
amount = Math::max<int32_t>(amount, callBet);
|
||||
turn = PokerTurn::bet(this, amount);
|
||||
turn = PokerTurn::bet(shared_from_this(), amount);
|
||||
turn.confidence = confidence;
|
||||
} else if(this->canCheck()) {
|
||||
turn = PokerTurn::bet(this, 0);
|
||||
turn = PokerTurn::bet(shared_from_this(), 0);
|
||||
turn.confidence = 1;
|
||||
} else {
|
||||
turn = PokerTurn::fold(this);
|
||||
turn = PokerTurn::fold(shared_from_this());
|
||||
turn.confidence = 1 - confidence;
|
||||
}
|
||||
|
||||
@ -266,7 +266,9 @@ int32_t PokerPlayer::getSumOfChips() {
|
||||
int32_t count = 0;
|
||||
auto it = pg->pots.begin();
|
||||
while(it != pg->pots.end()) {
|
||||
if(std::find(it->players.begin(), it->players.end(), this) != it->players.end()) {
|
||||
if(std::find(
|
||||
it->players.begin(), it->players.end(), shared_from_this()
|
||||
) != it->players.end()) {
|
||||
count += it->chips;
|
||||
}
|
||||
++it;
|
||||
|
@ -73,7 +73,7 @@ struct PokerPotWinning PokerPot::getWinners() {
|
||||
}
|
||||
|
||||
// Equal, compare hands.
|
||||
card = PokerWinning::compare(winnerLeft, winnerRight);
|
||||
card = PokerWinning::compare(*winnerLeft, *winnerRight);
|
||||
if(card.cardValue == 0xFF) {
|
||||
isWinner = false;
|
||||
break;
|
||||
|
@ -9,64 +9,69 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
struct PokerTurn PokerTurn::bet(PokerPlayer *player, int32_t chips) {
|
||||
struct PokerTurn PokerTurn::bet(
|
||||
std::shared_ptr<PokerPlayer> player,
|
||||
const int32_t chips
|
||||
) {
|
||||
struct PokerTurn turn;
|
||||
int32_t i;
|
||||
|
||||
assertNotNull(player);
|
||||
assertTrue(chips >= 0);
|
||||
assertNotNull(player, "Player cannot be null.");
|
||||
assertTrue(chips >= 0, "Chips must be greater than or equal to 0.");
|
||||
|
||||
turn.player = player;
|
||||
turn.confidence = 1;
|
||||
|
||||
if(chips == 0) {
|
||||
turn.type = POKER_TURN_TYPE_CHECK;
|
||||
turn.type = PokerTurnType::Check;
|
||||
turn.chips = 0;
|
||||
} else if(player->chips <= chips) {
|
||||
turn.chips = player->chips;
|
||||
turn.type = POKER_TURN_TYPE_ALL_IN;
|
||||
turn.type = PokerTurnType::AllIn;
|
||||
} else {
|
||||
turn.chips = chips;
|
||||
turn.type = POKER_TURN_TYPE_BET;
|
||||
i = player->pokerGame->getCurrentCallValue();
|
||||
turn.type = PokerTurnType::Bet;
|
||||
|
||||
if(chips == (i - player->currentBet)) {
|
||||
turn.type = POKER_TURN_TYPE_CALL;
|
||||
}
|
||||
auto pg = player->pokerGame.lock();
|
||||
assertNotNull(pg, "Player must be in a game.");
|
||||
|
||||
i = pg->getCurrentCallValue();
|
||||
|
||||
if(chips == (i - player->currentBet)) turn.type = PokerTurnType::Call;
|
||||
}
|
||||
|
||||
return turn;
|
||||
}
|
||||
|
||||
struct PokerTurn PokerTurn::fold(PokerPlayer *player) {
|
||||
struct PokerTurn PokerTurn::fold(std::shared_ptr<PokerPlayer> player) {
|
||||
struct PokerTurn turn;
|
||||
turn.player = player;
|
||||
turn.chips = 0;
|
||||
turn.confidence = 1;
|
||||
turn.type = POKER_TURN_TYPE_FOLD;
|
||||
turn.type = PokerTurnType::Fold;
|
||||
return turn;
|
||||
}
|
||||
|
||||
void PokerTurn::action() {
|
||||
assertNotNull(this->player);
|
||||
assertNotNull(this->player, "Player cannot be null.");
|
||||
|
||||
switch(this->type) {
|
||||
case POKER_TURN_TYPE_BET:
|
||||
case POKER_TURN_TYPE_CALL:
|
||||
case POKER_TURN_TYPE_ALL_IN:
|
||||
case PokerTurnType::Bet:
|
||||
case PokerTurnType::Call:
|
||||
case PokerTurnType::AllIn:
|
||||
this->player->bet(this->chips);
|
||||
break;
|
||||
|
||||
case POKER_TURN_TYPE_CHECK:
|
||||
case PokerTurnType::Check:
|
||||
player->bet(0);
|
||||
break;
|
||||
|
||||
case POKER_TURN_TYPE_FOLD:
|
||||
case PokerTurnType::Fold:
|
||||
player->fold();
|
||||
break;
|
||||
|
||||
default:
|
||||
assertUnreachable();
|
||||
assertUnreachable("Unknown turn type.");
|
||||
break;
|
||||
}
|
||||
}
|
@ -9,13 +9,13 @@
|
||||
namespace Dawn {
|
||||
class PokerPlayer;
|
||||
|
||||
enum PokerTurnType {
|
||||
POKER_TURN_TYPE_OUT,
|
||||
POKER_TURN_TYPE_FOLD,
|
||||
POKER_TURN_TYPE_BET,
|
||||
POKER_TURN_TYPE_CALL,
|
||||
POKER_TURN_TYPE_CHECK,
|
||||
POKER_TURN_TYPE_ALL_IN
|
||||
enum class PokerTurnType {
|
||||
Out,
|
||||
Fold,
|
||||
Bet,
|
||||
Call,
|
||||
Check,
|
||||
AllIn
|
||||
};
|
||||
|
||||
struct PokerTurn {
|
||||
@ -27,7 +27,7 @@ namespace Dawn {
|
||||
/** How confident the AI is about their turn. 0 = none, 1 = full */
|
||||
float_t confidence;
|
||||
/** Player that this action belongs to */
|
||||
PokerPlayer *player;
|
||||
std::shared_ptr<PokerPlayer> player;
|
||||
|
||||
/**
|
||||
* Generate a turn action for betting as a player.
|
||||
@ -36,14 +36,16 @@ namespace Dawn {
|
||||
* @param chips Chips to raise by.
|
||||
* @return A turn for a bet action.
|
||||
*/
|
||||
static struct PokerTurn bet(PokerPlayer *player, int32_t chips);
|
||||
static struct PokerTurn bet(
|
||||
std::shared_ptr<PokerPlayer> player, const int32_t chips
|
||||
);
|
||||
|
||||
/**
|
||||
* Return a turn action for the given player to fold.
|
||||
*
|
||||
* @return A turn for a fold action.
|
||||
*/
|
||||
static struct PokerTurn fold(PokerPlayer *player);
|
||||
static struct PokerTurn fold(std::shared_ptr<PokerPlayer> player);
|
||||
|
||||
/**
|
||||
* Actions / Performs this turn against the defined player.
|
||||
|
Reference in New Issue
Block a user