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)
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)
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)
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)
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)
def test_parse_string_into_cards_space_sep(self): card_input = 'ah ad qs qc' cards = poker_hand.parse_string_into_cards(card_input) self.assertEqual(4, len(cards)) self.assertIn(card.create_card_from_short_name('ah'), cards) self.assertIn(card.create_card_from_short_name('ad'), cards) self.assertIn(card.create_card_from_short_name('qs'), cards) self.assertIn(card.create_card_from_short_name('qc'), cards)
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)
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))
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)
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))
def get_board_cards(board_cards='', interaction=True): """Determine which cards to place on the board initially. Args: board_cards: str, which cards should be placed on the board in every iteration. For example, "As,Ah,Ad,Ac". interaction: bool, whether or not we should prompt the user for a value if the input is empty. Returns: list of Card, cards to place on the board each iteration. """ if not board_cards and interaction: print ('Please input the board cards, separated by spaces. ' 'For example, "Ah As"') board_cards = raw_input() return poker_hand.parse_string_into_cards(board_cards)
def get_dead_cards(dead_cards='', interaction=True): """Find which cards should be excluded from being selected in the sim. Args: dead_cards: str, which cards should be excluded from consideration in this simulation. interaction: bool, whether or not we should prompt the user for a value if the input is empty. Returns: list of Card, cards that should be excluded. """ if not dead_cards and interaction: print ('Please input any dead cards, separated by spaces. ' 'For example, "Ah As"') dead_cards = raw_input() return poker_hand.parse_string_into_cards(dead_cards)
def get_dead_cards(dead_cards='', interaction=True): """Find which cards should be excluded from being selected in the sim. Args: dead_cards: str, which cards should be excluded from consideration in this simulation. interaction: bool, whether or not we should prompt the user for a value if the input is empty. Returns: list of Card, cards that should be excluded. """ if not dead_cards and interaction: print('Please input any dead cards, separated by spaces. ' 'For example, "Ah As"') dead_cards = raw_input() return poker_hand.parse_string_into_cards(dead_cards)
def get_board_cards(board_cards='', interaction=True): """Determine which cards to place on the board initially. Args: board_cards: str, which cards should be placed on the board in every iteration. For example, "As,Ah,Ad,Ac". interaction: bool, whether or not we should prompt the user for a value if the input is empty. Returns: list of Card, cards to place on the board each iteration. """ if not board_cards and interaction: print('Please input the board cards, separated by spaces. ' 'For example, "Ah As"') board_cards = raw_input() return poker_hand.parse_string_into_cards(board_cards)
def test_parse_string_into_cards_empty_string(self): self.assertEqual([], poker_hand.parse_string_into_cards(''))