示例#1
0
    def test_non_overlapping_card_hands(self):
        hand_ranges = poker_hand.parse_hands_into_holdem_hands('TT')
        dead_cards = poker_hand.parse_string_into_cards('Th')

        # Checking that this does not raise an exception, even though TT and
        # Th potentially overlap.
        monte_carlo_runner.MonteCarloRunner(hand_ranges, dead_cards=dead_cards)
示例#2
0
    def test_get_winning_indices(self):
        h0_short_cards = ['as', 'ad', 'qd', 'qc', 'qs']
        h0_hand = poker_hand.PokerHand(cards=[
            card.create_card_from_short_name(sn) for sn in h0_short_cards
        ])

        h1_short_cards = ['as', '2s', '3s', '4s', '5s']
        h1_hand = poker_hand.PokerHand(cards=[
            card.create_card_from_short_name(sn) for sn in h1_short_cards
        ])
        h2_short_cards = ['qs', '2s', '3s', '4s', '5s']
        h2_hand = poker_hand.PokerHand(cards=[
            card.create_card_from_short_name(sn) for sn in h2_short_cards
        ])

        index_to_hand_dict = {
            0: h0_hand,
            1: h1_hand,
            2: h2_hand,
        }

        mcr = monte_carlo_runner.MonteCarloRunner([])

        self.assertItemsEqual([1],
                              mcr._get_winning_indices(index_to_hand_dict))
示例#3
0
    def test_overapping_card_specs_dead_and_board(self):
        board_cards = poker_hand.parse_string_into_cards('2h3h')
        dead_cards = poker_hand.parse_string_into_cards('3h')

        with self.assertRaises(monte_carlo_runner.Error):
            monte_carlo_runner.MonteCarloRunner([],
                                                board_cards=board_cards,
                                                dead_cards=dead_cards)
示例#4
0
    def test_get_best_hands_for_players(self):
        he_hands = poker_hand.parse_hands_into_holdem_hands('asad,2h2d')
        board_cards = poker_hand.parse_string_into_cards('ac,ah,kd,kc,2c')
        mcr = monte_carlo_runner.MonteCarloRunner(he_hands,
                                                  board_cards=board_cards)

        best_hands_for_each_player = mcr._get_best_hands_for_each_player(
            mcr.select_hands_for_players(), board_cards)

        self.assertEqual(2, len(best_hands_for_each_player))
示例#5
0
    def test_overlapping_card_specs_hand_and_board(self):
        board_cards = poker_hand.parse_string_into_cards('3h')
        dead_cards = []
        hand_ranges = poker_hand.parse_hands_into_holdem_hands('3h4h')

        with self.assertRaisesRegexp(monte_carlo_runner.Error,
                                     'Cards specified multiple times'):
            monte_carlo_runner.MonteCarloRunner(hand_ranges,
                                                board_cards=board_cards,
                                                dead_cards=dead_cards)
示例#6
0
def main(parsed_args):
    """Run the main program."""
    board_cards = get_board_cards(board_cards=parsed_args.board_cards,
                                  interaction=parsed_args.interaction)
    dead_cards = get_dead_cards(dead_cards=parsed_args.dead_cards,
                                interaction=parsed_args.interaction)
    used_cards = board_cards + dead_cards
    player_he_hands = get_player_hands(hands=parsed_args.hands,
                                       used_cards=used_cards)

    mc_runner = monte_carlo_runner.MonteCarloRunner(
        player_he_hands,
        board_cards=board_cards,
        dead_cards=dead_cards,
        iterations=parsed_args.num_iterations)
    mc_runner.run_all_iterations()
示例#7
0
    def test_reset_deck(self):
        he_ranges = poker_hand.parse_hands_into_holdem_hands('asad,qsjh')
        board_cards = poker_hand.parse_string_into_cards('2c2d')

        dead_cards = poker_hand.parse_string_into_cards('8h')

        mcr = monte_carlo_runner.MonteCarloRunner(he_ranges,
                                                  board_cards=board_cards,
                                                  dead_cards=dead_cards)

        mcr._reset_deck(mcr.select_hands_for_players())
        self.assertEqual(52 - 7, len(mcr.current_deck.cards))
        removed_cards = (he_ranges[0].possible_hands[0].cards +
                         he_ranges[1].possible_hands[0].cards + board_cards +
                         dead_cards)
        for rc in removed_cards:
            self.assertNotIn(rc, mcr.current_deck.cards)
示例#8
0
 def test_overlapping_card_specs_hands(self):
     hand_ranges = poker_hand.parse_hands_into_holdem_hands(
         '3hJh,Qh6d,JhAs')
     with self.assertRaisesRegexp(monte_carlo_runner.Error,
                                  'Cards specified multiple times'):
         monte_carlo_runner.MonteCarloRunner(hand_ranges)