uoftcprg / pokerkit

An open-source Python library for poker game simulations, hand evaluations, and statistical analysis
https://pokerkit.readthedocs.io/
MIT License
257 stars 29 forks source link

Manage multiple rounds #15

Closed alcapotine closed 3 months ago

alcapotine commented 3 months ago

Hi! First and foremost thanks a lot for this library, it is very usefull. I am trying to setup a project but I am facing many questions and can't find the answer within the documentation. I am trying to automate a no limit hold'em 6 players tournament, finish until only one player is left with chips.

My questions:

  1. As all the players are managed directly within the library, is it necessary to create/duplicate a class player, duplicate all the data and create a new game NoLimitTexasHoldem at each iteration for each new hands to continue the game as normal?

1b. If not how to start a new round after chips have been pulled?

I get the error "Currently, nobody can be dealt hole cards" when trying to deal new cards. Even though a winner has already been selected and chips pulled, I would expect the automation to re-shuffle the deck and initiate all parameters for a new round.

1c. If not, how is it possible to cycle all the players position clockwise after each round?

1d. If not, When a player reach 0 chips, is there a way to remove the player and keep the game without this player?

Many thanks for your answer, apologies if the question could have been solved otherwise.

  #start
  from math import inf

    from pokerkit import Automation, NoLimitTexasHoldem

    PLAYERCOUNT = 6

    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
        0,  # ante
        (0.25, 0.5),  # blinds or straddles
        0.5,  # min bet
    )

    state = game(
        (50, 50, 50, 50, 50, 50),  # starting stacks
        PLAYERCOUNT,  # number of players
    )

  for i in range(0,3):

    # =========== PREFLOP ===========
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()
    state.deal_hole()

    print("======PREFLOP=======")
    print("Cards:  ", state.hole_cards)
    print("Stacks:  ", state.stacks)

    #Betting phase
    state.complete_bet_or_raise_to(1)
    state.complete_bet_or_raise_to(2)
    state.fold()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()

    # =========== FLOP ===========
    state.deal_board()
    print("======FLOP=======")
    print("Cards:  ", state.hole_cards)
    print("Stacks:  ", state.stacks)
    print("Board: ", state.board_cards)

    #Betting phase
    state.complete_bet_or_raise_to(1)
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()

    # =========== TURN ===========
    state.deal_board()
    print("======TURN=======")
    print("Cards:  ", state.hole_cards)
    print("Stacks:  ", state.stacks)
    print("Board: ", state.board_cards)

    #Betting phase
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()

    # =========== RIVER ===========

    state.deal_board()
    print("======RIVER=======")
    print("Cards:  ", state.hole_cards)
    print("Stacks:  ", state.stacks)
    print("Board: ", state.board_cards)

    #Betting phase
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()
    state.check_or_call()

    # ========= SHOWDOWN =========
    print("END OF ROUND")
    print(state.stacks)

    for i in range(0, PLAYERCOUNT):
        print("Payer ", i , " has the result: ", state.payoffs[i])
AussieSeaweed commented 3 months ago

Thanks for using my library!

In PokerKit, you need to create a new state to simulate a new hand.

In your case, when you create a new state to serve as the next hand, you would have to pass in the final stacks of the players from the last hand (state.stacks).

Since you are playing Texas hold'em, you would have to handle the rotation of the player button which would mean rotating the stack list. You would have to filter out zero stack value player as well (who busted). There is no easy function for this, sorry.