Ejemplo n.º 1
0
    def test_generate_suited_hands_dead_cards(self):
        rank1 = 'Three'
        rank2 = 'King'

        dead_cards = [
            card.Card('Hearts', 'Three'),
            card.Card('Spades', 'King')
        ]
        all_hands = hand_ranges.generate_suited_hands(rank1,
                                                      rank2,
                                                      dead_cards=dead_cards)

        self.assertEqual(2, len(all_hands))
        expected_hands = [
            poker_hand.HoldemHand(cards=[
                card.Card('Diamonds', 'Three'),
                card.Card('Diamonds', 'King')
            ]),
            poker_hand.HoldemHand(cards=[
                card.Card('Clubs', 'Three'),
                card.Card('Clubs', 'King')
            ]),
        ]
        for h in expected_hands:
            self.assertIn(h, all_hands)
Ejemplo n.º 2
0
    def test_hand_eq_ne(self):
        lhs_short = ['as', 'ad']
        lhs_cards = [card.create_card_from_short_name(sn) for sn in lhs_short]
        lhs_he_hand = poker_hand.HoldemHand(cards=lhs_cards)

        rhs_short = ['ks', 'kd']
        rhs_cards = [card.create_card_from_short_name(sn) for sn in rhs_short]
        rhs_he_hand = poker_hand.HoldemHand(cards=rhs_cards)
        self.assertNotEqual(lhs_he_hand, rhs_he_hand)
Ejemplo n.º 3
0
def generate_unsuited_hands(rank1, rank2, dead_cards=None):
    """Generates all unsuited combinations of the two ranks.

    Args:
        rank1: str, a card rank.
        rank2: str, another card rank.
        dead_cards: str, list of cards or None.  Cards that should be excluded
            from consideration.

    Returns:
        list of HoldemHand.
    """
    c1_possibilities = [card.Card(s, rank1) for s in card.SUITS]
    c2_possibilities = [card.Card(s, rank2) for s in card.SUITS]

    hands = []
    for c1 in c1_possibilities:
        if dead_cards and c1 in dead_cards:
            continue
        for c2 in c2_possibilities:
            if dead_cards and c2 in dead_cards:
                continue
            if c1.suit == c2.suit:
                continue
            hands.append(poker_hand.HoldemHand(cards=[c1, c2]))
    return hands
Ejemplo n.º 4
0
    def test_generate_pair_hands(self):
        rank = 'Two'
        all_pairs = hand_ranges.generate_pair_hands(rank)

        self.assertEqual(6, len(all_pairs))
        expected_hand = poker_hand.HoldemHand(
            cards=[card.Card('Hearts', 'Two'),
                   card.Card('Spades', 'Two')])
        self.assertIn(expected_hand, all_pairs)
Ejemplo n.º 5
0
    def test_generate_suited_hands(self):
        rank1 = 'Two'
        rank2 = 'Jack'

        all_hands = hand_ranges.generate_suited_hands(rank1, rank2)

        self.assertEqual(4, len(all_hands))
        expected_hand = poker_hand.HoldemHand(
            cards=[card.Card('Hearts', 'Two'),
                   card.Card('Hearts', 'Jack')])
        self.assertIn(expected_hand, all_hands)
        for h in all_hands:
            self.assertEqual(h.cards[0].suit, h.cards[1].suit)
Ejemplo n.º 6
0
    def test_generate_unsuited_hands(self):
        rank1 = 'King'
        rank2 = 'Queen'

        all_hands = hand_ranges.generate_unsuited_hands(rank1, rank2)

        self.assertEqual(12, len(all_hands))
        sample_expected_hand = poker_hand.HoldemHand(
            cards=[card.Card('Clubs', 'King'),
                   card.Card('Spades', 'Queen')])
        self.assertIn(sample_expected_hand, all_hands)
        for h in all_hands:
            self.assertNotEqual(h.cards[0].suit, h.cards[1].suit)
Ejemplo n.º 7
0
def generate_pair_hands(rank, dead_cards=None):
    """Generates all possible pair hands for the given rank."""
    if rank not in card.RANKS:
        raise ValueError('Invalid rank: %s' % rank)

    cards = [card.Card(s, rank) for s in card.SUITS]
    filtered_cards = cards
    if dead_cards:
        filtered_cards = [c for c in cards if c not in dead_cards]

    return [
        poker_hand.HoldemHand(cards=c)
        for c in itertools.combinations(filtered_cards, 2)
    ]
Ejemplo n.º 8
0
def generate_suited_hands(rank1, rank2, dead_cards=None):
    """Generates all suited combinations of the two ranks.

    Args:
        rank1: str, a card rank.
        rank2: str, a card rank.
        dead_cards: str, list of Cards or None.  Cards that should be excluded
            from consideration.

    Returns:
        list of HoldemHand.
    """
    hands = []
    for suit in card.SUITS:
        c1 = card.Card(suit, rank1)
        c2 = card.Card(suit, rank2)
        if dead_cards and (c1 in dead_cards or c2 in dead_cards):
            continue
        hands.append(poker_hand.HoldemHand(cards=[c1, c2]))
    return hands
Ejemplo n.º 9
0
 def assertHandMatchesShortCards(self, short_cards, hand):
     expected_hand = poker_hand.HoldemHand(
         cards=[card.create_card_from_short_name(sn) for sn in short_cards])
     self.assertEqual(expected_hand, hand)