poCker
|
Contains the logic of a poker game in a form of DI'able functions. See their arrangement and implementation in main.c. More...
Go to the source code of this file.
Classes | |
struct | GameState |
Represents the current state of a poker game. More... | |
Functions | |
GameState * | gsCreateNew (const GameRuleSet *) |
Creates a new, clean and unconfigured GameState struct. | |
void | gsSetUpBettingRound (GameState *, Player *[], const GameRuleSet *) |
Sets the members of a GameState struct according to its current betting_round value. | |
void | gsAdvancePlayerTurn (GameState *, Player *[], const GameRuleSet *, const int *) |
Advances the player's turn by allowing them to take action and applying any changes causes by the chosen action. | |
void | gsConcludeBettingRound (GameState *) |
Sets the amount of revealed community cards and increments the betting_round value of the passed GameState struct. | |
int | gsDetermineWinners (int[], const GameRuleSet *, const GameState *, const Player *[], const PlayingCard *[]) |
Determines the winner(s) and populates the winners array with their indexes. | |
void | gsAwardPot (GameState *, Player *[], const int[], const int) |
Determines the winner(s) and pays them their winnings from the pot. | |
bool | gsCheckGameOverCondition (Player *[], const GameRuleSet *) |
Checks if everyone but one player has any funds left. | |
void | gsPassDealerButton (GameState *, const GameRuleSet *) |
Pass the dealer button to the next player. Done once after each full round. This also causes the blind player statuses to move. | |
void | gsConcludeSingleGame (GameState *) |
Prepares the GameState struct for a fresh game while preserving dealer button positions. | |
Contains the logic of a poker game in a form of DI'able functions. See their arrangement and implementation in main.c.
void gsAdvancePlayerTurn | ( | GameState * | state, |
Player * | players[], | ||
const GameRuleSet * | ruleSet, | ||
const int * | player_dec_override ) |
Advances the player's turn by allowing them to take action and applying any changes causes by the chosen action.
state | The current state of the game to modify accordingly. |
players | An array of Players to modify accordingly. |
ruleSet | The GameRuleSet on which some logic is based. |
player_dec_override | Meant for unit-testing. A non-null pointer will override whatever the player's decision was. Keep in mind this value won't be validated! |
void gsAwardPot | ( | GameState * | state, |
Player * | players[], | ||
const int | winners[], | ||
const int | winners_count ) |
Determines the winner(s) and pays them their winnings from the pot.
state | The GameState struct to modify accordingly. |
players | An array of Players to modify accordingly. |
winners | An array containing indexes of winning Players. |
winners_count | The size of the winners array. |
Tapped out winners receive their rewards first, the rest is then divided evenly between other winners. If the pot happened to be indivisible by amount of winners, small blind player receives the remainder.
bool gsCheckGameOverCondition | ( | Player * | players[], |
const GameRuleSet * | rules ) |
Checks if everyone but one player has any funds left.
players | An array of Players to be modified accordingly. |
rules | GameRuleSet containing the amount of Players. |
If the condition is true, this would indicate end of the whole game. This function also reverts the "folded" and "tappedout" statuses for all Players with any funds left. Broke players are marked as folded right away, preventing them from being able to act again.
void gsConcludeBettingRound | ( | GameState * | state | ) |
void gsConcludeSingleGame | ( | GameState * | state | ) |
GameState * gsCreateNew | ( | const GameRuleSet * | rules | ) |
Creates a new, clean and unconfigured GameState struct.
rules | The GameRuleSet struct to base the creation of the GameState on. |
int gsDetermineWinners | ( | int | winners[], |
const GameRuleSet * | rules, | ||
const GameState * | state, | ||
const Player * | players[], | ||
const PlayingCard * | comm_cards[] ) |
Determines the winner(s) and populates the winners array with their indexes.
winners | An array which will be filled with Player indexes. |
rules | The GameRuleSet struct containing the amount of Players. |
state | The GameState containing all_but_one_folded and revealed community cards count. |
players | An array of Players to modify accordingly. |
comm_cards | The community cards to analyze when determining who has got the best handrank. |
If the win happened because of everyone else folding, only one player who did not fold is awarded the whole pot. Otherwise, everyone's hands are compared, winners are pulled and awarded their fair share.
void gsPassDealerButton | ( | GameState * | state, |
const GameRuleSet * | rules ) |
Pass the dealer button to the next player. Done once after each full round. This also causes the blind player statuses to move.
state | The GameState struct to modify. |
rules | The GameRuleSet containing the amount of Players. |
void gsSetUpBettingRound | ( | GameState * | state, |
Player * | players[], | ||
const GameRuleSet * | ruleSet ) |
Sets the members of a GameState struct according to its current betting_round value.
state | The GameState struct to modify. |
players | An array of Players which might be modified if the round being set up is the pre-flop. |
ruleSet | The GameRuleSet dictating current game's rules regarding small and big blinds. |