def test_get_hand_rank_52_holdem(self): cpp_poker = CppHandeval() b = np.array([[2, 0], [2, 3], [11, 1], [10, 2], [11, 2]], dtype=np.int8) h = np.array([[11, 3], [5, 1]], dtype=np.int8) assert isinstance( cpp_poker.get_hand_rank_52_holdem(hand_2d=h, board_2d=b), int)
def test_get_hand_rank_52_plo(self): cpp_poker = CppHandeval() b = np.array([[2, 0], [2, 3], [11, 1], [10, 2], [11, 2]], dtype=np.int8) h = np.array([[11, 3], [5, 1], [5, 2], [11, 0]], dtype=np.int8) handstr = cpp_poker.get_hand_rank_52_plo(hand_2d=h, board_2d=b) assert handstr == 1240771
def get_hand_rank_52_plo(self, n_reps): cpp_poker = CppHandeval() b = np.array([[2, 0], [2, 3], [11, 1], [10, 2], [11, 2]], dtype=np.int8) h = np.array([[11, 3], [5, 1], [5, 2], [11, 0]], dtype=np.int8) start = default_timer() for _ in range(n_reps): value = cpp_poker.get_hand_rank_52_plo(hand_2d=h, board_2d=b) end = default_timer() print(f"time for get_hand_rank_52_plo: {end - start} runs: {n_reps}")
def __init__(self): from PokerRL.game._.cpp_wrappers.CppHandeval import CppHandeval self._clib = CppHandeval()
class Flop3HoldemRules: """ General rules of Texas Hold'em poker games """ N_HOLE_CARDS = 2 N_RANKS = 13 N_SUITS = 4 N_CARDS_IN_DECK = N_RANKS * N_SUITS RANGE_SIZE = PokerRange.get_range_size(n_hole_cards=N_HOLE_CARDS, n_cards_in_deck=N_CARDS_IN_DECK) BTN_IS_FIRST_POSTFLOP = False N_FLOP_CARDS = 3 N_TURN_CARDS = 0 N_RIVER_CARDS = 0 N_TOTAL_BOARD_CARDS = N_FLOP_CARDS ALL_ROUNDS_LIST = [Poker.PREFLOP, Poker.FLOP] SUITS_MATTER = True ROUND_BEFORE = { Poker.PREFLOP: Poker.PREFLOP, Poker.FLOP: Poker.PREFLOP, Poker.TURN: None, Poker.RIVER: None, } ROUND_AFTER = { Poker.PREFLOP: Poker.FLOP, Poker.FLOP: None, Poker.TURN: None, Poker.RIVER: None, } RANK_DICT = { Poker.CARD_NOT_DEALT_TOKEN_1D: "", 0: "2", 1: "3", 2: "4", 3: "5", 4: "6", 5: "7", 6: "8", 7: "9", 8: "T", 9: "J", 10: "Q", 11: "K", 12: "A" } SUIT_DICT = { Poker.CARD_NOT_DEALT_TOKEN_1D: "", 0: "h", 1: "d", 2: "s", 3: "c" } STRING = "FLOP3_HOLDEM_RULES" def __init__(self): from PokerRL.game._.cpp_wrappers.CppHandeval import CppHandeval self._clib = CppHandeval() def get_hand_rank_all_hands_on_given_boards(self, boards_1d, lut_holder): """ for docs refer to PokerEnv """ raise NotImplementedError( "Batched hand eval for multiple boards is unfortunately not implemented for FHP at the moment." ) # TODO def get_hand_rank(self, hand_2d, board_2d): """ for docs refer to PokerEnv """ return self._clib.get_hand_rank_fhp3(hand_2d=hand_2d, board_2d=board_2d) @classmethod def get_lut_holder(cls): from PokerRL.game._.look_up_table import LutHolderHoldem return LutHolderHoldem(cls)
class PLORules: """ General rules of Pot Limit Omaha """ N_HOLE_CARDS = 4 N_RANKS = 13 N_SUITS = 4 N_CARDS_IN_DECK = N_RANKS * N_SUITS RANGE_SIZE = PokerRange.get_range_size(n_hole_cards=N_HOLE_CARDS, n_cards_in_deck=N_CARDS_IN_DECK) BTN_IS_FIRST_POSTFLOP = False N_FLOP_CARDS = 3 N_TURN_CARDS = 1 N_RIVER_CARDS = 1 N_TOTAL_BOARD_CARDS = N_FLOP_CARDS + N_TURN_CARDS + N_RIVER_CARDS ALL_ROUNDS_LIST = [Poker.PREFLOP, Poker.FLOP, Poker.TURN, Poker.RIVER] SUITS_MATTER = True ROUND_BEFORE = { Poker.PREFLOP: Poker.PREFLOP, Poker.FLOP: Poker.PREFLOP, Poker.TURN: Poker.FLOP, Poker.RIVER: Poker.TURN } ROUND_AFTER = { Poker.PREFLOP: Poker.FLOP, Poker.FLOP: Poker.TURN, Poker.TURN: Poker.RIVER, Poker.RIVER: None } RANK_DICT = { Poker.CARD_NOT_DEALT_TOKEN_1D: "", 0: "2", 1: "3", 2: "4", 3: "5", 4: "6", 5: "7", 6: "8", 7: "9", 8: "T", 9: "J", 10: "Q", 11: "K", 12: "A" } SUIT_DICT = { Poker.CARD_NOT_DEALT_TOKEN_1D: "", 0: "h", 1: "d", 2: "s", 3: "c" } STRING = "PLO_RULES" def __init__(self): from PokerRL.game._.cpp_wrappers.CppHandeval import CppHandeval self._clib = CppHandeval() def get_hand_rank_all_hands_on_given_boards(self, boards_1d, lut_holder): """ for docs refer to PokerEnv returns a numpy array [1,hole_hands_total] where best hand has biggest number and not possible hand has -1 """ r = self._clib.get_hand_rank_all_hands_on_given_boards_52_holdem(boards_1d=boards_1d, lut_holder=lut_holder) return r def get_hand_rank(self, hand_2d, board_2d): """ for docs refer to PokerEnv """ r = self._clib.get_hand_rank_52_plo(hand_2d=hand_2d, board_2d=board_2d) return r @classmethod def get_lut_holder(cls): from PokerRL.game._.look_up_table import LutHolderPLO return LutHolderPLO(cls)