Beispiel #1
0
    def test_board_card_plays(self):
        bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL),
                         (PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL)]
        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=0).get_payoffs([0, 2])
        self.assertEqual([2, 0], payoffs.tolist())

        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=0).get_payoffs([2, 0])
        self.assertEqual([0, 2], payoffs.tolist())
Beispiel #2
0
    def test_bet_fold(self):
        bet_sequences = [(PlayerActions.BET_RAISE, PlayerActions.FOLD), ()]
        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=0).get_payoffs([1, 2])
        self.assertEqual([2, 0], payoffs.tolist())

        bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.BET_RAISE,
                          PlayerActions.FOLD), ()]
        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=0).get_payoffs([2, 1])
        self.assertEqual([0, 2], payoffs.tolist())
Beispiel #3
0
 def test_call_reraise_r2(self):
     cost = LeducPokerGame.LeducNode(
         bet_sequences=[(PlayerActions.CHECK_CALL,
                         PlayerActions.CHECK_CALL),
                        (PlayerActions.BET_RAISE, PlayerActions.BET_RAISE)],
         board_card=0).add_action(PlayerActions.CHECK_CALL)
     self.assertEqual(4, cost)
Beispiel #4
0
 def test_round2_bets_are_4_check_reraise(self):
     bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL),
                      (PlayerActions.CHECK_CALL, PlayerActions.BET_RAISE,
                       PlayerActions.BET_RAISE, PlayerActions.CHECK_CALL)]
     payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                        board_card=0).get_payoffs([1, 2])
     self.assertEqual([0, 18], payoffs.tolist())
Beispiel #5
0
 def test_game_rrc_is_round_1(self):
     bet_sequence = (PlayerActions.BET_RAISE, PlayerActions.BET_RAISE,
                     PlayerActions.CHECK_CALL)
     self.assertEqual(
         1,
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).game_round)
Beispiel #6
0
 def test_r2_cannot_raise_after_crr(self):
     r1_actions = (PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL)
     bet_sequence = (PlayerActions.CHECK_CALL, PlayerActions.BET_RAISE,
                     PlayerActions.BET_RAISE)
     self.assertFalse(
         LeducPokerGame.LeducNode([r1_actions, bet_sequence],
                                  board_card=0).can_raise)
Beispiel #7
0
    def test_suits_are_equivalent(self):
        bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL),
                         (PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL)]
        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=0).get_payoffs([3, 2])
        self.assertEqual([2, 0], payoffs.tolist())

        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=3).get_payoffs([0, 2])
        self.assertEqual([2, 0], payoffs.tolist())

        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=2).get_payoffs([0, 5])
        self.assertEqual([0, 2], payoffs.tolist())

        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=5).get_payoffs([0, 2])
        self.assertEqual([0, 2], payoffs.tolist())

        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=1).get_payoffs([0, 4])
        self.assertEqual([0, 2], payoffs.tolist())

        payoffs = LeducPokerGame.LeducNode(bet_sequences=bet_sequences,
                                           board_card=4).get_payoffs([0, 1])
        self.assertEqual([0, 2], payoffs.tolist())
Beispiel #8
0
    def eval_exploitability(self, policy: Policies.Policy):
        values = np.zeros((2, 1, NUM_HOLDINGS))
        reach = np.ones((2, NUM_BOARD, NUM_HOLDINGS))

        self._eval(policy, LeducPoker.LeducGameState(
            player_cards=[0, 1], bet_sequences=[(), ()], board_card=None), reach, values)

        exploitability = np.zeros(2)

        for p in range(2):
            for h in range(NUM_HOLDINGS):
                exploitability[p] += values[p][0][h]

        return exploitability
    def get_game_value(self) -> float:
        game_values = []

        for my_card in LeducPoker.LeducPokerGame.DECK:
            opponent_card_probs = np.array([1 / 5] * 6)
            opponent_card_probs[my_card] = 0

            my_infoset = LeducPoker.LeducInfoset(card=my_card,
                                                 bet_sequences=[(), ()],
                                                 board_card=None)
            game_value = self._get_game_state_value(my_infoset,
                                                    opponent_card_probs)
            game_values.append(game_value[self.player_num])

        return sum(game_values) / len(game_values)
    def _get_opponent_game_value(
            self, my_infoset: LeducPoker.LeducInfoset,
            opponent_card_probs: np.ndarray) -> np.ndarray:
        cards_to_action_probs = {}
        total_action_probs = np.zeros(3)
        for opponent_card in LeducPoker.LeducPokerGame.DECK:
            if opponent_card == my_infoset.card or opponent_card == my_infoset.board_card:
                assert opponent_card_probs[opponent_card] == 0
                continue
            opponent_infoset = LeducPoker.LeducInfoset(
                card=opponent_card,
                bet_sequences=my_infoset.bet_sequences,
                board_card=my_infoset.board_card)
            action_probs = self.opponent_policy.action_prob(opponent_infoset)
            if not my_infoset.can_raise:
                action_probs[PlayerActions.CHECK_CALL] += action_probs[
                    PlayerActions.BET_RAISE]
                action_probs[PlayerActions.BET_RAISE] = 0
            if not my_infoset.can_fold:
                action_probs[PlayerActions.CHECK_CALL] += action_probs[
                    PlayerActions.FOLD]
                action_probs[PlayerActions.FOLD] = 0

            cards_to_action_probs[opponent_card] = action_probs
            total_action_probs += opponent_card_probs[
                opponent_card] * np.array(action_probs)

        retval = np.zeros(2)
        for action in PlayerActions.ALL_ACTIONS:
            if total_action_probs[action] == 0:
                continue
            post_action_card_probs = opponent_card_probs.copy()
            for opponent_card in LeducPoker.LeducPokerGame.DECK:
                if opponent_card == my_infoset.card or opponent_card == my_infoset.board_card:
                    continue
                post_action_card_probs[opponent_card] *= cards_to_action_probs[
                    opponent_card][action]

            post_action_card_probs = self._normalize(post_action_card_probs)

            post_action_infoset = copy.deepcopy(my_infoset)
            post_action_infoset.add_action(action)

            game_value = self._get_game_state_value(post_action_infoset,
                                                    post_action_card_probs)
            retval += game_value * total_action_probs[action]

        return retval
Beispiel #11
0
 def test_checkraise_is_not_terminal(self):
     bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL),
                      (PlayerActions.CHECK_CALL, PlayerActions.BET_RAISE)]
     self.assertFalse(
         LeducPokerGame.LeducNode(bet_sequences, board_card=1).is_terminal)
Beispiel #12
0
 def test_cannot_fold_after_c_r2(self):
     r1_bet_sequence = (PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL)
     bet_sequence = (PlayerActions.CHECK_CALL, )
     self.assertFalse(
         LeducPokerGame.LeducNode([r1_bet_sequence, bet_sequence],
                                  board_card=0).can_fold)
Beispiel #13
0
 def test_can_fold_after_cr_r2(self):
     r1_bet_sequence = (PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL)
     bet_sequence = (PlayerActions.CHECK_CALL, PlayerActions.BET_RAISE)
     self.assertTrue(
         LeducPokerGame.LeducNode([r1_bet_sequence, bet_sequence],
                                  board_card=0).can_fold)
Beispiel #14
0
 def test_p2_folds_is_terminal(self):
     bet_sequence = (PlayerActions.BET_RAISE, PlayerActions.BET_RAISE,
                     PlayerActions.FOLD)
     self.assertTrue(
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).is_terminal)
Beispiel #15
0
 def test_r2_can_raise_after_c(self):
     r1_actions = (PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL)
     bet_sequence = (PlayerActions.CHECK_CALL, )
     self.assertTrue(
         LeducPokerGame.LeducNode([r1_actions, bet_sequence],
                                  board_card=0).can_raise)
Beispiel #16
0
 def test_game_r_is_round_0(self):
     bet_sequence = (PlayerActions.BET_RAISE, )
     self.assertEqual(
         0,
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).game_round)
Beispiel #17
0
 def test_game_start_is_not_terminal(self):
     bet_sequence = ()
     self.assertFalse(
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).is_terminal)
Beispiel #18
0
 def test_final_call_r1(self):
     cost = LeducPokerGame.LeducNode(
         bet_sequences=[(PlayerActions.BET_RAISE, PlayerActions.BET_RAISE,
                         PlayerActions.BET_RAISE), ()],
         board_card=None).add_action(PlayerActions.CHECK_CALL)
     self.assertEqual(2, cost)
Beispiel #19
0
 def test_reraise_r1(self):
     cost = LeducPokerGame.LeducNode(
         bet_sequences=[(PlayerActions.BET_RAISE, ), ()],
         board_card=None).add_action(PlayerActions.BET_RAISE)
     self.assertEqual(5, cost)
Beispiel #20
0
 def test_cc_r1(self):
     cost = LeducPokerGame.LeducNode(
         bet_sequences=[(PlayerActions.CHECK_CALL, ), ()],
         board_card=None).add_action(PlayerActions.CHECK_CALL)
     self.assertEqual(1, cost)
Beispiel #21
0
 def test_first_bet(self):
     cost = LeducPokerGame.LeducNode(bet_sequences=[(), ()],
                                     board_card=None).add_action(
                                         PlayerActions.BET_RAISE)
     self.assertEqual(3, cost)
Beispiel #22
0
 def test_can_raise_after_cr(self):
     bet_sequence = (PlayerActions.CHECK_CALL, PlayerActions.BET_RAISE)
     self.assertTrue(
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).can_raise)
Beispiel #23
0
 def test_can_fold_after_r(self):
     bet_sequence = (PlayerActions.BET_RAISE, )
     self.assertTrue(
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).can_fold)
Beispiel #24
0
 def test_first_check_is_free_r2(self):
     cost = LeducPokerGame.LeducNode(
         bet_sequences=[(PlayerActions.CHECK_CALL,
                         PlayerActions.CHECK_CALL), ()],
         board_card=0).add_action(PlayerActions.CHECK_CALL)
     self.assertEqual(0, cost)
Beispiel #25
0
 def test_round1_is_not_terminal(self):
     bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL),
                      ()]
     self.assertFalse(
         LeducPokerGame.LeducNode(bet_sequences, board_card=1).is_terminal)
Beispiel #26
0
 def test_can_open_raise(self):
     bet_sequence = ()
     self.assertTrue(
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).can_raise)
Beispiel #27
0
 def test_game_start_is_round_0(self):
     bet_sequence = ()
     self.assertEqual(
         0,
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).game_round)
Beispiel #28
0
 def test_nonterminal_payoff_raises_exception(self):
     with self.assertRaises(RuntimeError):
         LeducPokerGame.LeducNode(bet_sequences=[(), ()],
                                  board_card=0).get_payoffs([0, 0])
Beispiel #29
0
 def test_raisecall_showdown_is_terminal(self):
     bet_sequences = [(PlayerActions.CHECK_CALL, PlayerActions.CHECK_CALL),
                      (PlayerActions.BET_RAISE, PlayerActions.CHECK_CALL)]
     self.assertTrue(
         LeducPokerGame.LeducNode(bet_sequences, board_card=1).is_terminal)
Beispiel #30
0
 def test_cannot_raise_after_rr(self):
     bet_sequence = (PlayerActions.BET_RAISE, PlayerActions.BET_RAISE)
     self.assertFalse(
         LeducPokerGame.LeducNode([bet_sequence, ()],
                                  board_card=0).can_raise)