cardgames.games.poker_game.PokerGame

class cardgames.games.poker_game.PokerGame(loadout, players, instructions)

Bases: cardgames.components.game.Game

A class to simulate a game of poker.

__init__(loadout, players, instructions)

Initialises attributes, and sets up a loop that starts a new game until there is a winner, or the game is exited.

Parameters
  • loadout (str) – name of saved game to load (not yet functioning)

  • players (list(str)) –

  • instructions (bool) – show instructions

Methods

__init__(loadout, players, instructions)

Initialises attributes, and sets up a loop that starts a new game until there is a winner, or the game is exited.

assess(p)

Assess the cards of a player to find the best hand given the community cards.

next_game()

Simulates one game of poker, consisting of five rounds (Preflop, Flop, Turn, River and Showdown).

player_choice(p)

Prints the player's options and asks each user for input to either: check, call, raise or fold.

player_turns()

Iterates through list of player names, and checks each player's status to see if player has previously folded or gone all in before presenting the player with a choice of actions.

reveal()

Assesses the players cards to reveal the winner.

Attributes

player_names

List of player names :type: list

assess(p: cardgames.components.player.Player)

Assess the cards of a player to find the best hand given the community cards.

Lists all pairwise combinations of the 5 community and 2 player cards, and uses the combinations to find all pairs, triples, and four-of-a-kinds, and sets the players best_cards attribute to the best hand the player has. TODO (Flushes and full houses not calculated yet.)

Parameters

p (player.Player) – player

next_game()

Simulates one game of poker, consisting of five rounds (Preflop, Flop, Turn, River and Showdown).

player_choice(p)

Prints the player’s options and asks each user for input to either: check, call, raise or fold. Adjusts the player’s attributes and the game’s attributes accordingly.

Parameters

p (player.Player) – player

Returns

player

Return type

player.Player

player_names

List of player names :type: list

player_turns()

Iterates through list of player names, and checks each player’s status to see if player has previously folded or gone all in before presenting the player with a choice of actions.

reveal()

Assesses the players cards to reveal the winner.

For each player: checks their status (eg. folded, all in). If they are in the round, calls assess() to find their best cards. Compares the rank (given in hand_ranks) of their best hand to the current best hand.