### Install PokerKit Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/index.md Install the PokerKit library using pip. Requires Python 3.11 or above. ```bash pip install pokerkit ``` -------------------------------- ### Install Project Requirements Source: https://github.com/uoftcprg/pokerkit/blob/main/CONTRIBUTING.rst Install all necessary Python packages for development using pip. Ensure your virtual environment is activated. ```bash pip install -r requirements.txt ``` -------------------------------- ### Setup and Activate Virtual Environment Source: https://github.com/uoftcprg/pokerkit/blob/main/CONTRIBUTING.rst Create and activate a Python virtual environment for your project. This isolates project dependencies. ```bash python -m venv venv ``` ```bash source venv/bin/activate ``` -------------------------------- ### Specify Starting Stacks for Game Simulation Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md Demonstrates various ways to provide starting stacks to a game simulation, including tuples, lists, dictionaries, and a single numeric value when the number of players is also specified. ```python state = game( (200, 200, 200, 200), # starting stacks 4, # number of players ) ``` ```python state = game( [200, 200, 200, 200], # starting stacks 4, # number of players ) ``` ```python state = game( {0: 200, 1: 200, 2: 200, 3: 200}, # starting stacks 4, # number of players ) ``` ```python state = game( 200, # starting stacks 4, # number of players ) ``` -------------------------------- ### Initialize FixedLimitDeuceToSevenLowballTripleDraw Game Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md Sets up a FixedLimitDeuceToSevenLowballTripleDraw game with specific automations, ante, blinds, and bet sizes. The number of players and starting stacks are then provided to start the simulation. ```python from pokerkit import ( Automation, FixedLimitDeuceToSevenLowballTripleDraw, NoLimitTexasHoldem, ) game = FixedLimitDeuceToSevenLowballTripleDraw( # automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.CARD_BURNING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # False for big blind ante, True otherwise 0, # ante (75000, 150000), # blinds or straddles 150000, # small bet 300000, # big bet ) state = game( (1180000, 4340000, 5910000, 10765000), # starting stacks 4, # number of players ) ``` -------------------------------- ### Initialize NoLimitTexasHoldem Game Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md Configures a NoLimitTexasHoldem game with specified automations, ante, blinds, and minimum bet. The simulation is then started with provided player stacks and count. ```python game = NoLimitTexasHoldem( # automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.CARD_BURNING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # False for big blind ante, True otherwise 500, # ante (1000, 2000), # blinds or straddles 2000, # min bet ) state = game( (1125600, 2000000, 553500), # starting stacks 3, # number of players ) ``` -------------------------------- ### pokerkit.state.State.get_dealable_cards() Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md Gets the cards recommended for dealing, handling deck replenishment. ```APIDOC ## pokerkit.state.State.get_dealable_cards() ### Description Gets the cards that are “recommended” to be dealt from, handling deck replenishing if the deck is/will be out of cards. ### Method `get_dealable_cards()` ### Response #### Success Response (200) - **dealable_cards** (list[string]) - A list of strings representing the cards recommended for dealing. ``` -------------------------------- ### Create a No-Limit Texas Hold'em game state Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Example of creating a game state for No-Limit Texas Hold'em with specified automations, antes, blinds, and starting stacks. Use 'math.inf' for undefined starting stacks. ```python from math import inf from pokerkit import Automation, Mode, NoLimitTexasHoldem state = NoLimitTexasHoldem.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), False, # Uniform antes? {-1: 600}, # Antes (200, 400, 800), # Blinds or straddles 400, # Min-bet (inf, 116400, 86900, inf, 50000, inf), # Starting stacks 6, # Number of players mode=Mode.CASH_GAME, ) ``` -------------------------------- ### Create FixedLimitBadugi Game State Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Initializes a game state for Fixed Limit Badugi with specified automations, betting structure, and an infinite starting stack. Use this to set up a new game instance. ```python from math import inf from pokerkit import Automation, FixedLimitBadugi state = FixedLimitBadugi.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 0, # Antes (1, 2), # Blinds or straddles 2, # Small-bet 4, # Big-bet inf, # Starting stacks 4, # Number of players ) ``` -------------------------------- ### Create and Simulate a Short-Deck Hold'em Game State Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Initializes a Short-Deck Hold'em game state with specified automations, antes, blinds, and starting stacks. Use this to set up a new game simulation. ```python from pokerkit import Automation, NoLimitShortDeckHoldem state = NoLimitShortDeckHoldem.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 3000, # Antes {-1: 3000}, # Blinds or straddles 3000, # Min-bet (495000, 232000, 362000, 403000, 301000, 204000), # Starting stacks 6, # Number of players ) # Below are the pre-flop dealings and actions. state.deal_hole('Th8h') # Badziakouski state.deal_hole('QsJd') # Zhong state.deal_hole('QhQd') # Xuan state.deal_hole('8d7c') # Jun state.deal_hole('KhKs') # Phua state.deal_hole('8c7h') # Koon state.check_or_call() # Badziakouski state.check_or_call() # Zhong state.complete_bet_or_raise_to(35000) # Xuan state.fold() # Jun state.complete_bet_or_raise_to(298000) # Phua state.fold() # Koon state.fold() # Badziakouski state.fold() # Zhong state.check_or_call() # Xuan ``` -------------------------------- ### Define Streets for Fixed-limit Razz Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md Configure the betting rounds (streets) for Fixed-limit Razz. This example demonstrates specific settings for hole card dealing, opening bets, and betting limits. Ensure the pokerkit library is imported. ```python from pokerkit import * # Fixed-limit razz streets = ( Street( card_burning_status=False, hole_dealing_statuses=(False, False, True), board_dealing_count=0, draw_status=False, opening=Opening.HIGH_CARD, min_completion_betting_or_raising_amount=2, max_completion_betting_or_raising_count=4, ), Street( card_burning_status=True, hole_dealing_statuses=(True,), board_dealing_count=0, draw_status=False, opening=Opening.LOW_HAND, min_completion_betting_or_raising_amount=2, max_completion_betting_or_raising_count=4, ), Street( card_burning_status=True, hole_dealing_statuses=(True,), board_dealing_count=0, draw_status=False, opening=Opening.LOW_HAND, min_completion_betting_or_raising_amount=4, max_completion_betting_or_raising_count=4, ), Street( card_burning_status=True, hole_dealing_statuses=(True,), board_dealing_count=0, draw_status=False, opening=Opening.LOW_HAND, min_completion_betting_or_raising_amount=4, max_completion_betting_or_raising_count=4, ), Street( card_burning_status=True, hole_dealing_statuses=(False,), board_dealing_count=0, draw_status=False, opening=Opening.LOW_HAND, min_completion_betting_or_raising_amount=4, max_completion_betting_or_raising_count=4, ), ) ``` -------------------------------- ### Create Fixed-Limit Deuce-To-Seven Lowball Triple Draw State Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Initializes a game state for Fixed-Limit Deuce-To-Seven Lowball Triple Draw, including setting up automations, blinds, and starting stacks. ```python from pokerkit import Automation, FixedLimitDeuceToSevenLowballTripleDraw state = FixedLimitDeuceToSevenLowballTripleDraw.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 0, # Antes (75000, 150000), # Blinds or straddles 150000, # Small-bet 300000, # Big-bet (1180000, 4340000, 5910000, 10765000), # Starting stacks 4, # Number of players ) ``` -------------------------------- ### Burn Card and Deal Board Cards Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Simulates burning a card before dealing community cards (flop, turn, river) in Omaha Hold'em. The '??' placeholder indicates the burned card is not specified in this example. ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) ``` ```python >>> state.deal_board('4s5c2h') BoardDealing(commentary=None, cards=(4s, 5c, 2h)) ``` ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) ``` ```python >>> state.deal_board('5h') BoardDealing(commentary=None, cards=(5h,)) ``` ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) ``` ```python >>> state.deal_board('9c') BoardDealing(commentary=None, cards=(9c,)) ``` -------------------------------- ### Define Kuhn Poker State Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md This snippet demonstrates how to initialize a custom game state for Kuhn Poker using the `State` class in PokerKit. It specifies automations, deck, hand types, streets, betting structure, ante trimming, antes, blinds, bring-in, starting stacks, and the number of players. ```python from pokerkit import ( Automation, BettingStructure, Deck, KuhnPokerHand, Opening, State, Street, ) state = State( # automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.CARD_BURNING, Automation.HOLE_DEALING, Automation.BOARD_DEALING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), Deck.KUHN_POKER, # deck (KuhnPokerHand,), # hand types (high/low-split will have two types) # streets ( Street( False, # card burning (False,), # hole card dealing statuses (False for face-down) 0, # board dealing count False, # standing pat or discarding Opening.POSITION, # who opens the betting? 1, # min bet 1, # maximum number of completions/bettings/raisings ), ), BettingStructure.FIXED_LIMIT, # betting structure True, # ``False`` for big blind ante, otherwise ``True`` (1,) * 2, # ante (0,) * 2, # blind or straddles 0, # bring-in (2,) * 2, # starting stacks 2, # number of players ) ``` -------------------------------- ### Simulate All-In Multi-Runout in No-Limit Texas Hold'em Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/index.md Simulates a multi-runout hand in a No-Limit Texas Hold'em cash game. Demonstrates dealing hole cards, player actions (fold, bet, check, call), dealing community cards across multiple runouts, and printing final stacks. Note that some starting stacks are set to infinity as they are not specified. ```python from math import inf from pokerkit import Automation, Mode, NoLimitTexasHoldem state = NoLimitTexasHoldem.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), False, # Uniform antes? {-1: 600}, # Antes (200, 400, 800), # Blinds or straddles 400, # Min-bet (inf, 116400, 86900, inf, 50000, inf), # Starting stacks 6, # Number of players mode=Mode.CASH_GAME, ) # Below are the pre-flop dealings and actions. state.deal_hole('JsTh') # Tony G state.deal_hole('Ah9d') # Hellmuth state.deal_hole('KsKc') # Wiggins state.deal_hole('5c2h') # Negreanu state.deal_hole('6h5h') # Brunson state.deal_hole('6s3s') # Laak state.fold() # Negreanu state.complete_bet_or_raise_to(2800) # Brunson state.fold() # Laak state.check_or_call() # Tony G state.complete_bet_or_raise_to(12600) # Hellmuth state.check_or_call() # Wiggins state.check_or_call() # Brunson state.check_or_call() # Tony G # Below are the flop dealing and actions. state.burn_card('??') state.deal_board('9hTs9s') state.check_or_call() # Tony G state.complete_bet_or_raise_to(17000) # Hellmuth state.complete_bet_or_raise_to(36000) # Wiggins state.fold() # Brunson state.fold() # Tony G state.complete_bet_or_raise_to(103800) # Hellmuth state.check_or_call() # Wiggins # Below is selecting the number of runouts. state.select_runout_count(4) # Hellmuth state.select_runout_count(None) # Wiggins # Below is the first runout. state.burn_card('??') state.deal_board('Jh') # Turn state.burn_card('??') state.deal_board('Ad') # River # Below is the second runout. state.burn_card('??') state.deal_board('Kh') # Turn state.burn_card('??') state.deal_board('3c') # River # Below is the third runout. state.burn_card('??') state.deal_board('7s') # Turn state.burn_card('??') state.deal_board('8s') # River # Below is the fourth runout. state.burn_card('??') state.deal_board('Qc') # Turn state.burn_card('??') state.deal_board('Kd') # River # Below are the final stacks. print(state.stacks) # [inf, 79400, 149700, inf, 37400, inf] ``` -------------------------------- ### Create Fixed-Limit Badugi Game State Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/simulation.md Initializes a Fixed-Limit Deuce to Seven Lowball Triple Draw game state. Requires specifying automations, blind ante status, ante, blinds, bet sizes, starting stacks, and number of players. ```python from pokerkit import ( Automation, FixedLimitDeuceToSevenLowballTripleDraw, NoLimitTexasHoldem, ) state = FixedLimitDeuceToSevenLowballTripleDraw.create_state( # automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.CARD_BURNING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # False for big blind ante, True otherwise 0, # ante (75000, 150000), # blinds or straddles 150000, # small bet 300000, # big bet (1180000, 4340000, 5910000, 10765000), # starting stacks 4, # number of players ) ``` -------------------------------- ### Construct Game State and Play Hand Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/notation.md Demonstrates constructing a PotLimitOmahaHoldem game state, dealing hole and board cards, progressing through betting rounds, and creating a hand history file. ```python from pokerkit import * # Game state construction game = PotLimitOmahaHoldem( ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.CARD_BURNING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, 0, (500, 1000), 1000, ) state = game((1259450.25, 678473.5), 2) # State progression; Pre-flop state.deal_hole("Ah3sKsKh") # Antonius state.deal_hole("6d9s7d8h") # Blom state.complete_bet_or_raise_to(3000) # Blom state.complete_bet_or_raise_to(9000) # Antonius state.complete_bet_or_raise_to(27000) # Blom state.complete_bet_or_raise_to(81000) # Antonius state.check_or_call() # Blom # Flop state.deal_board("4s5c2h") state.complete_bet_or_raise_to(91000) # Antonius state.complete_bet_or_raise_to(435000) # Blom state.complete_bet_or_raise_to(779000) # Antonius state.check_or_call() # Blom # Turn & River state.deal_board("5h") state.deal_board("9c") # Creating hand history hh = HandHistory.from_game_state(game, state) hh.players = ["Patrik Antonius", "Viktor Blom"] # Dump hand with open("path/to/file.phh", "wb") as file: hh.dump(file) ``` -------------------------------- ### Get Final Stacks in Texas Hold'em Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Retrieves the final chip stacks for all players after the hand has concluded. This reflects the outcome of the game. ```python >>> state.stacks [572100, inf, 1109500] ``` -------------------------------- ### Run Unit and Doctests Source: https://github.com/uoftcprg/pokerkit/blob/main/CONTRIBUTING.rst Execute the project's unit tests and doctests to verify the correctness of your changes. Ensure all tests pass before submitting a pull request. ```bash python -m unittest ``` ```bash python -m doctest pokerkit/*.py ``` -------------------------------- ### Simulate All-In and Betting Actions Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Demonstrates a sequence of betting actions in an all-in situation, including checking, calling, raising, and folding. Use this to model player decisions during critical betting rounds. ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('9hTs9s') BoardDealing(commentary=None, cards=(9h, Ts, 9s)) >>> state.check_or_call() # Tony G CheckingOrCalling(commentary=None, player_index=0, amount=0) >>> state.complete_bet_or_raise_to( ... 17000, ... ) # Hellmuth CompletionBettingOrRaisingTo(commentary=None, player_index=1, amount... >>> state.complete_bet_or_raise_to( ... 36000, ... ) # Wiggins CompletionBettingOrRaisingTo(commentary=None, player_index=2, amount... >>> state.fold() # Brunson Folding(commentary=None, player_index=4) >>> state.fold() # Tony G Folding(commentary=None, player_index=0) >>> state.complete_bet_or_raise_to( ... 103800, ... ) # Hellmuth CompletionBettingOrRaisingTo(commentary=None, player_index=1, amount... >>> state.check_or_call() # Wiggins CheckingOrCalling(commentary=None, player_index=2, amount=38300) ``` -------------------------------- ### Deal Cards for Fourth Runout Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Example of dealing the turn and river cards for the fourth runout. This completes the sequence of dealing for four runouts. ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('Qc') # Turn BoardDealing(commentary=None, cards=(Qc,)) >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('Kd') # River BoardDealing(commentary=None, cards=(Kd,)) ``` -------------------------------- ### Deal Cards for Third Runout Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Example of dealing the turn and river cards for the third runout. This demonstrates the repetitive nature of dealing for each subsequent runout. ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('7s') # Turn BoardDealing(commentary=None, cards=(7s,)) >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('8s') # River BoardDealing(commentary=None, cards=(8s,)) ``` -------------------------------- ### Simulate Flop, Turn, and River Actions in Poker Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Demonstrates dealing cards and player actions for flop, turn, and river stages. Use this to simulate game progression after initial dealing. ```python state.burn_card('??') state.deal_board('Jc3d5c') state.complete_bet_or_raise_to(35000) # Ivey state.check_or_call() # Dwan # Below are the turn dealing and actions. state.burn_card('??') state.deal_board('4h') state.complete_bet_or_raise_to(90000) # Ivey state.complete_bet_or_raise_to(232600) # Dwan state.complete_bet_or_raise_to(1067100) # Ivey state.check_or_call() # Dwan # Below is the river dealing. state.burn_card('??') state.deal_board('Jh') # Below are the final stacks. print(state.stacks) # [572100, inf, 1109500] ``` -------------------------------- ### Simulate a Badugi Hand with PokerKit Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/index.md Use this code to simulate a full Badugi hand, from initial deal to showdown. It includes setting up game parameters, player actions like folding, calling, checking, and drawing, and finally displaying the results. Ensure all necessary imports are present. ```python from math import inf from pokerkit import Automation, FixedLimitBadugi state = FixedLimitBadugi.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 0, # Antes (1, 2), # Blinds or straddles 2, # Small-bet 4, # Big-bet inf, # Starting stacks 4, # Number of players ) # Below are the pre-flop dealings and actions. state.deal_hole('????????') # Bob state.deal_hole('????????') # Carol state.deal_hole('????????') # Ted state.deal_hole('????????') # Alice state.fold() # Ted state.check_or_call() # Alice state.check_or_call() # Bob state.check_or_call() # Carol # Below are the first draw and actions. state.stand_pat_or_discard('????') # Bob state.stand_pat_or_discard('????') # Carol state.stand_pat_or_discard('??') # Alice state.burn_card('??') state.deal_hole('????') # Bob state.deal_hole('????') # Carol state.deal_hole('??') # Alice state.check_or_call() # Bob state.complete_bet_or_raise_to() # Carol state.check_or_call() # Alice state.check_or_call() # Bob # Below are the second draw and actions. state.stand_pat_or_discard('??') # Bob state.stand_pat_or_discard() # Carol state.stand_pat_or_discard('??') # Alice state.burn_card('??') state.deal_hole('??') # Bob state.deal_hole('??') # Alice state.check_or_call() # Bob state.complete_bet_or_raise_to() # Carol state.complete_bet_or_raise_to() # Alice state.fold() # Bob state.check_or_call() # Carol # Below are the third draw and actions. state.stand_pat_or_discard('??') # Carol state.stand_pat_or_discard() # Alice state.burn_card('??') state.deal_hole('??') # Carol state.check_or_call() # Carol state.complete_bet_or_raise_to() # Alice state.check_or_call() # Carol # Below is the showdown. state.show_or_muck_hole_cards('2s4c6d9h') # Alice state.show_or_muck_hole_cards('3s5d7c8h') # Carol # Below are the final stacks. print(state.stacks) # [inf, inf, inf, inf] print(state.payoffs) # [-4, 20, 0, -16] ``` -------------------------------- ### Deal Cards for Second Runout Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Example of dealing the turn and river cards for the second runout. Each runout requires its own set of burn and deal actions. ```python >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('Kh') # Turn BoardDealing(commentary=None, cards=(Kh,)) >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_board('3c') # River BoardDealing(commentary=None, cards=(3c,)) ``` -------------------------------- ### Simulate Texas Hold'em Hand with PokerKit Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Demonstrates setting up a No-Limit Texas Hold'em game state, dealing hole cards, and simulating betting actions. Use this to create custom poker game simulations. ```python from math import inf from pokerkit import Automation, NoLimitTexasHoldem state = NoLimitTexasHoldem.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 500, # Antes (1000, 2000), # Blinds or straddles 2000, # Min-bet (1125600, inf, 553500), # Starting stacks 3, # Number of players ) # Below are the pre-flop dealings and actions. state.deal_hole('Ac2d') # Ivey state.deal_hole('????') # Antonius state.deal_hole('7h6h') # Dwan state.complete_bet_or_raise_to(7000) # Dwan state.complete_bet_or_raise_to(23000) # Ivey state.fold() # Antonius state.check_or_call() # Dwan ``` -------------------------------- ### Simulate Poker Actions Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Demonstrates a sequence of actions in a poker game, including standing pat, discarding, burning cards, dealing hole cards, and completing bets. This is useful for simulating game flow. ```python state.stand_pat_or_discard() # Yockey state.stand_pat_or_discard('AsQs') # Arieh state.burn_card('??') state.deal_hole('2hQh') # Arieh state.complete_bet_or_raise_to() # Yockey state.check_or_call() # Arieh ``` ```python state.stand_pat_or_discard() # Yockey state.stand_pat_or_discard('Qh') # Arieh state.burn_card('??') state.deal_hole('4d') # Arieh state.complete_bet_or_raise_to() # Yockey state.check_or_call() # Arieh ``` ```python state.stand_pat_or_discard() # Yockey state.stand_pat_or_discard('6s') # Arieh state.burn_card('??') state.deal_hole('7c') # Arieh state.complete_bet_or_raise_to() # Yockey state.check_or_call() # Arieh ``` ```python print(state.stacks) # [0, 4190000, 5910000, 12095000] ``` -------------------------------- ### Deal Hole Cards in Fixed-Limit Texas Hold'em Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Deals hole cards to players in a Fixed-Limit Texas Hold'em game. This is typically done at the start of a hand. ```python >>> state.deal_hole('AcAs') HoleDealing(commentary=None, player_index=0, cards=(Ac, As), statuse... ``` ```python >>> state.deal_hole('7h6h') HoleDealing(commentary=None, player_index=1, cards=(7h, 6h), statuse... ``` -------------------------------- ### Manual Game State Management in Python Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/tips.md Use this snippet for step-by-step control over poker game operations when full automation is not desired. It requires importing necessary components from the pokerkit library. ```python from pokerkit import * def create_state(): ... state = create_state() while state.status: if state.can_post_ante(): state.post_ante() elif state.can_collect_bets(): state.collect_bets() elif state.can_post_blind_or_straddle(): state.post_blind_or_straddle() elif state.can_burn_card(): state.burn_card('??') elif state.can_select_runout_count(): # Cash-game mode only state.select_runout_count() elif state.can_deal_hole(): state.deal_hole() elif state.can_deal_board(): state.deal_board() elif state.can_kill_hand(): state.kill_hand() elif state.can_push_chips(): state.push_chips() elif state.can_pull_chips(): state.pull_chips() else: action = input('Action: ') parse_action(state, action) ``` -------------------------------- ### Get Final Stacks in Fixed-Limit Texas Hold'em Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Retrieves the final chip stacks for all players after a hand in Fixed-Limit Texas Hold'em. This is useful for tracking game progress. ```python >>> state.stacks [204, 196] ``` -------------------------------- ### Pre-flop Actions in Short-Deck Hold'em Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Simulates pre-flop betting actions including checking, calling, completing bets, raising, and folding. Note the sequence of actions and amounts. ```pycon >>> state.check_or_call() # Badziakouski CheckingOrCalling(commentary=None, player_index=0, amount=3000) ``` ```pycon >>> state.check_or_call() # Zhong CheckingOrCalling(commentary=None, player_index=1, amount=3000) ``` ```pycon >>> state.complete_bet_or_raise_to(35000) # Xuan CompletionBettingOrRaisingTo(commentary=None, player_index=2, amount... ``` ```pycon >>> state.fold() # Jun Folding(commentary=None, player_index=3) ``` ```pycon >>> state.complete_bet_or_raise_to( ... 298000, ... ) # Phua CompletionBettingOrRaisingTo(commentary=None, player_index=4, amount... ``` ```pycon >>> state.fold() # Koon Folding(commentary=None, player_index=5) ``` ```pycon >>> state.fold() # Badziakouski Folding(commentary=None, player_index=0) ``` ```pycon >>> state.fold() # Zhong Folding(commentary=None, player_index=1) ``` ```pycon >>> state.check_or_call() # Xuan CheckingOrCalling(commentary=None, player_index=2, amount=263000) ``` -------------------------------- ### Simulate Texas Hold'em Flop and Actions Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst Demonstrates dealing the flop, burning cards, and handling betting actions in a Texas Hold'em game. ```python state.burn_card('??') state.deal_board('4s5c2h') state.complete_bet_or_raise_to(91000) # Antonius state.complete_bet_or_raise_to(435000) # Blom state.complete_bet_or_raise_to(779000) # Antonius state.check_or_call() # Blom # Below is the turn dealing. state.burn_card('??') state.deal_board('5h') # Below is the river dealing. state.burn_card('??') state.deal_board('9c') # Below are the final stacks. print(state.stacks) # [1937923.75, 0.0] ``` -------------------------------- ### Dump Multiple Hands to a Single File Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/notation.md Shows how to dump a list of hand histories into a single file using HandHistory.dump_all. ```python from pokerkit import * hhs = [...] # Assume hhs is a list of HandHistory objects # Dump hands with open("path/to/file.phhs", "wb") as file: HandHistory.dump_all(hhs, file) ``` -------------------------------- ### Create Fixed-Limit Badugi State Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Initializes a game state for Fixed-Limit Badugi, using infinite stacks as they are not specified. ```python from math import inf from pokerkit import * state = FixedLimitBadugi.create_state( ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, 0, (1, 2), 2, 4, inf, 4, ) ``` -------------------------------- ### Dealing Initial Hands in Badugi Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Simulates dealing initial hole cards to players in a Badugi game. Each player receives four cards. ```python >>> state.deal_hole('????????') # Bob HoleDealing(commentary=None, player_index=0, cards=(??, ??, ??, ??),... >>> state.deal_hole('????????') # Carol HoleDealing(commentary=None, player_index=1, cards=(??, ??, ??, ??),... >>> state.deal_hole('????????') # Ted HoleDealing(commentary=None, player_index=2, cards=(??, ??, ??, ??),... >>> state.deal_hole('????????') # Alice HoleDealing(commentary=None, player_index=3, cards=(??, ??, ??, ??),... ``` -------------------------------- ### Simulate Short-Deck Hold'em Hand Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/index.md This snippet simulates a Short-Deck Hold'em hand, including pre-flop, flop, turn, and river actions, and prints the final stacks. It uses specific automations for this variant. ```python from pokerkit import Automation, NoLimitShortDeckHoldem state = NoLimitShortDeckHoldem.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 3000, # Antes {-1: 3000}, # Blinds or straddles 3000, # Min-bet (495000, 232000, 362000, 403000, 301000, 204000), # Starting stacks 6, # Number of players ) # Below are the pre-flop dealings and actions. state.deal_hole('Th8h') # Badziakouski state.deal_hole('QsJd') # Zhong state.deal_hole('QhQd') # Xuan state.deal_hole('8d7c') # Jun state.deal_hole('KhKs') # Phua state.deal_hole('8c7h') # Koon state.check_or_call() # Badziakouski state.check_or_call() # Zhong state.complete_bet_or_raise_to(35000) # Xuan state.fold() # Jun state.complete_bet_or_raise_to(298000) # Phua state.fold() # Koon state.fold() # Badziakouski state.fold() # Zhong state.check_or_call() # Xuan # Below is the flop dealing. state.burn_card('??') state.deal_board('9h6cKc') # Below is the turn dealing. state.burn_card('??') state.deal_board('Jh') # Below is the river dealing. state.burn_card('??') state.deal_board('Ts') # Below are the final stacks. print(state.stacks) # [489000, 226000, 684000, 400000, 0, 198000] ``` -------------------------------- ### First Round Actions in Badugi Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Illustrates player actions after the initial deal, including folding, checking, and calling. ```python >>> state.fold() # Ted Folding(commentary=None, player_index=2) >>> state.check_or_call() # Alice CheckingOrCalling(commentary=None, player_index=3, amount=2) >>> state.check_or_call() # Bob CheckingOrCalling(commentary=None, player_index=0, amount=1) >>> state.check_or_call() # Carol CheckingOrCalling(commentary=None, player_index=1, amount=0) ``` -------------------------------- ### First Draw and Actions in Badugi Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/examples.md Simulates the first draw phase where players decide to stand pat or discard, followed by dealing new cards and subsequent betting actions. ```python >>> state.stand_pat_or_discard('????') # Bob StandingPatOrDiscarding(commentary=None, player_index=0, cards=(??, ... >>> state.stand_pat_or_discard('????') # Carol StandingPatOrDiscarding(commentary=None, player_index=1, cards=(??, ... >>> state.stand_pat_or_discard('??') # Alice StandingPatOrDiscarding(commentary=None, player_index=3, cards=(??,) >>> state.burn_card('??') CardBurning(commentary=None, card=??) >>> state.deal_hole('????') # Bob HoleDealing(commentary=None, player_index=0, cards=(??, ??), statuse... >>> state.deal_hole('????') # Carol HoleDealing(commentary=None, player_index=1, cards=(??, ??), statuse... >>> state.deal_hole('??') # Alice HoleDealing(commentary=None, player_index=3, cards=(??,), statuses=(... >>> state.check_or_call() # Bob CheckingOrCalling(commentary=None, player_index=0, amount=0) >>> state.complete_bet_or_raise_to() # Carol CompletionBettingOrRaisingTo(commentary=None, player_index=1, amount=2) >>> state.check_or_call() # Alice CheckingOrCalling(commentary=None, player_index=3, amount=2) >>> state.check_or_call() # Bob CheckingOrCalling(commentary=None, player_index=0, amount=2) ``` -------------------------------- ### Representing Cards in PokerKit Source: https://github.com/uoftcprg/pokerkit/blob/main/docs/evaluation.md Demonstrates multiple equivalent ways to define a set of two cards (Ace of Spades and King of Spades) in PokerKit. ```python from pokerkit import * cards = Card(Rank.ACE, Suit.SPADE), Card(Rank.KING, Suit.SPADE) cards = [Card(Rank.ACE, Suit.SPADE), Card(Rank.KING, Suit.SPADE)] cards = {Card(Rank.ACE, Suit.SPADE), Card(Rank.KING, Suit.SPADE)} cards = Card.parse('AsKs') cards = 'AsKs' ``` -------------------------------- ### Simulate Pot-Limit Omaha Hold'em Hand Source: https://github.com/uoftcprg/pokerkit/blob/main/README.rst This snippet demonstrates setting up and simulating a Pot-Limit Omaha Hold'em hand, including dealing hole cards and pre-flop betting actions. It uses various Automation types for game progression. ```python from pokerkit import Automation, PotLimitOmahaHoldem state = PotLimitOmahaHoldem.create_state( # Automations ( Automation.ANTE_POSTING, Automation.BET_COLLECTION, Automation.BLIND_OR_STRADDLE_POSTING, Automation.HOLE_CARDS_SHOWING_OR_MUCKING, Automation.HAND_KILLING, Automation.CHIPS_PUSHING, Automation.CHIPS_PULLING, ), True, # Uniform antes? 0, # Antes (500, 1000), # Blinds or straddles 1000, # Min-bet (1259450.25, 678473.5), # Starting stacks 2, # Number of players ) # Below are the pre-flop dealings and actions. state.deal_hole('Ah3sKsKh') # Antonius state.deal_hole('6d9s7d8h') # Blom state.complete_bet_or_raise_to(3000) # Blom state.complete_bet_or_raise_to(9000) # Antonius state.complete_bet_or_raise_to(27000) # Blom state.complete_bet_or_raise_to(81000) # Antonius state.check_or_call() # Blom ```