コード例 #1
0
ファイル: look_up_table.py プロジェクト: zxpower/PokerRL
    def get_n_board_branches_LUT(self):
        _N_CARDS_DEALT_IN_TRANSITION_TO_LUT = self.get_n_cards_dealt_in_transition_to_LUT(
        )
        _N_CARDS_OUT_AT = self.get_n_cards_out_at_LUT()
        lut = {Poker.PREFLOP: 0}
        for r in [
                _r for _r in self.rules.ALL_ROUNDS_LIST if _r != Poker.PREFLOP
        ]:
            nc = self.rules.N_CARDS_IN_DECK \
                 - _N_CARDS_OUT_AT[self.rules.ROUND_BEFORE[r]] \
                 - self.rules.N_HOLE_CARDS

            # get_range_size is actually a general combinatorial function that we can also use here
            lut[r] = PokerRange.get_range_size(
                n_hole_cards=_N_CARDS_DEALT_IN_TRANSITION_TO_LUT[r],
                n_cards_in_deck=nc)
        return lut
コード例 #2
0
ファイル: test_rangeManager.py プロジェクト: zxpower/PokerRL
 def test_get_range_size(self):
     assert PokerRange.get_range_size(n_hole_cards=2,
                                      n_cards_in_deck=52) == 1326
     assert PokerRange.get_range_size(n_hole_cards=4,
                                      n_cards_in_deck=52) == 270725
     assert PokerRange.get_range_size(n_hole_cards=1,
                                      n_cards_in_deck=52) == 52
     assert PokerRange.get_range_size(n_hole_cards=1,
                                      n_cards_in_deck=6) == 6
     assert PokerRange.get_range_size(n_hole_cards=1,
                                      n_cards_in_deck=6) == 6
     assert PokerRange.get_range_size(n_hole_cards=3,
                                      n_cards_in_deck=6) == 20
コード例 #3
0
ファイル: game_rules.py プロジェクト: JarlPed/DREAM-1
class BigLeducRules:
    N_HOLE_CARDS = 1
    N_RANKS = 12
    N_SUITS = 2
    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 = True

    N_FLOP_CARDS = 1
    N_TURN_CARDS = 0
    N_RIVER_CARDS = 0
    N_TOTAL_BOARD_CARDS = N_FLOP_CARDS + N_TURN_CARDS + N_RIVER_CARDS
    ALL_ROUNDS_LIST = [Poker.PREFLOP, Poker.FLOP]

    SUITS_MATTER = False

    ROUND_BEFORE = {
        Poker.PREFLOP: Poker.PREFLOP,
        Poker.FLOP: Poker.PREFLOP
    }
    ROUND_AFTER = {
        Poker.PREFLOP: Poker.FLOP,
        Poker.FLOP: None
    }

    RANK_DICT = {i: str(i + 2) for i in range(N_RANKS)}
    SUIT_DICT = {k: ["a", "b", "c", "d", "e", "f", "g"][k] for k in range(N_SUITS)} \
        if N_SUITS < 8 \
        else {i: "_" + str(i) for i in range(N_SUITS)}

    STRING = "BIG_LEDUC_RULES"

    def __init__(self):
        pass

    def get_hand_rank_all_hands_on_given_boards(self, boards_1d, lut_holder):
        """
        for general docs refer to PokerEnv
        """
        hand_ranks = np.full(shape=(boards_1d.shape[0], LeducRules.RANGE_SIZE), fill_value=-1, dtype=np.int32)
        for board_idx in range(boards_1d.shape[0]):
            for range_idx in range(LeducRules.RANGE_SIZE):
                hand_ranks[board_idx, range_idx] = self.get_hand_rank(
                    hand_2d=lut_holder.get_2d_hole_cards_from_range_idx(range_idx=range_idx),
                    board_2d=lut_holder.get_2d_cards(cards_1d=boards_1d[board_idx]))

        return hand_ranks

    def get_hand_rank(self, hand_2d, board_2d):
        """
        for docs refer to PokerEnv
        """
        if board_2d[0, 0] == hand_2d[0, 0]:
            return 10000 + hand_2d[0, 0]
        else:
            return hand_2d[0, 0]

    @classmethod
    def get_lut_holder(cls):
        from PokerRL.game._.look_up_table import LutHolderLeduc

        return LutHolderLeduc(cls)
コード例 #4
0
ファイル: game_rules.py プロジェクト: JarlPed/DREAM-1
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)
コード例 #5
0
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)