Exemple #1
0
    def test_get_possible_range_idxs_leduc(self):

        for n in range(2, 9):
            env_bldr = get_leduc_env_bldr()

            # if actually blocked
            for c in range(env_bldr.rules.N_CARDS_IN_DECK):
                board_2d = env_bldr.lut_holder.get_2d_cards(
                    np.array([c], dtype=np.int32))
                result = PokerRange.get_possible_range_idxs(
                    rules=env_bldr.rules,
                    lut_holder=env_bldr.lut_holder,
                    board_2d=board_2d)

                should_be = np.delete(
                    np.arange(env_bldr.rules.RANGE_SIZE, dtype=np.int32), c)

                assert np.array_equal(a1=result, a2=should_be)

            # if nothing blocked
            board_2d = np.array([Poker.CARD_NOT_DEALT_TOKEN_2D], dtype=np.int8)
            result = PokerRange.get_possible_range_idxs(
                rules=env_bldr.rules,
                lut_holder=env_bldr.lut_holder,
                board_2d=board_2d)

            should_be = np.arange(env_bldr.rules.RANGE_SIZE, dtype=np.int32)

            assert np.array_equal(a1=result, a2=should_be)
Exemple #2
0
    def _fill_chance_node_strategy(self, node):
        assert node.strategy is None
        if node.is_terminal:
            return

        if node.p_id_acting_next == self._tree.CHANCE_ID:
            game_round = node.children[0].env_state[EnvDictIdxs.current_round]
            n_children = len(node.children)
            assert n_children == self._env_bldr.lut_holder.DICT_LUT_N_BOARDS[
                game_round]

            # chance nodes are uniform random
            node.strategy = np.zeros(shape=(self._env_bldr.rules.RANGE_SIZE,
                                            n_children),
                                     dtype=np.float32)

            # set strategy for impossible hands to 0
            for c_id in range(n_children):
                mask = PokerRange.get_possible_range_idxs(
                    rules=self._env_bldr.rules,
                    lut_holder=self._env_bldr.lut_holder,
                    board_2d=node.children[c_id].env_state[
                        EnvDictIdxs.board_2d])
                node.strategy[
                    mask,
                    c_id] = 1.0 / (self._env_bldr.rules.N_CARDS_IN_DECK - 2)

        for c in node.children:
            self._fill_chance_node_strategy(node=c)
Exemple #3
0
    def test_get_possible_range_idxs_holdem(self):
        env_bldr = get_holdem_env_bldr()
        for n in range(2, 9):
            board_2d = np.array(
                [[0, 0], [5, 2], [12, 3], Poker.CARD_NOT_DEALT_TOKEN_2D],
                dtype=np.int8)
            result = PokerRange.get_possible_range_idxs(
                rules=env_bldr.rules,
                lut_holder=env_bldr.lut_holder,
                board_2d=board_2d)

            assert result.shape[0] == 1176  # nck of 49:2

            # all of these should be blocked
            for e in [0, 1, 2, 3, 4, 50, 1325]:
                assert not np.any(result == e)