예제 #1
0
    def test_comparing_flush(self):
        ordered_hands = [
            Hand(list(map(Card, ['2H', '4H', '6H', '8H', 'TH']))),
            Hand(list(map(Card, ['3H', '4H', '6H', '8H', 'TH']))),
            Hand(list(map(Card, ['2H', '5H', '6H', '8H', 'TH']))),
            Hand(list(map(Card, ['2H', '4H', '7H', '8H', 'TH']))),
            Hand(list(map(Card, ['2H', '4H', '6H', '9H', 'TH']))),
            Hand(list(map(Card, ['2H', '4H', '6H', '8H', 'JH']))),
        ]

        for left_index in range(0, len(ordered_hands)):
            for right_index in range(left_index + 1, len(ordered_hands)):
                self.assertTrue(
                    ordered_hands[right_index] > ordered_hands[left_index])

        equal_hands = [
            Hand(list(map(Card, ['2H', '4H', '6H', '8H', 'TH']))),
            Hand(list(map(Card, ['2D', '4D', '6D', '8D', 'TD']))),
            Hand(list(map(Card, ['2S', '4S', '6S', '8S', 'TS']))),
            Hand(list(map(Card, ['2C', '4C', '6C', '8C', 'TC']))),
        ]

        for left_index in range(0, len(equal_hands)):
            for right_index in range(left_index + 1, len(equal_hands)):
                self.assertEqual(equal_hands[right_index],
                                 equal_hands[left_index])
예제 #2
0
 def test_figures_out_flush_is_best_card(self):
     cards = [
         Card(rank=rank, suit="Hearts")
         for rank in ["2", "5", "10", "Queen", "King"]
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Flush")
예제 #3
0
    def test_comparing_straight_flush(self):
        hands = [
            Hand(list(map(Card, ['3H', '4H', '5H', '6H', '7H']))),
            Hand(list(map(Card, ['3S', '4S', '5S', '6S', '7S']))),
            Hand(list(map(Card, ['6D', '7D', '8D', '9D', 'TD']))),
        ]

        self.assertEqual(hands[0], hands[1])
        self.assertTrue(hands[2] > hands[1])
예제 #4
0
 def test_three_of_kind_of_8_third_to_last_pos(self):
     card_list = [
         Card("C","9"),
         Card("H","10"),
         Card("H","8"), 
         Card("D","8"), 
         Card("S","8"), 
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Three of a kind")
예제 #5
0
 def test_three_of_kind_of_7_first_until_third_pos(self):
     card_list = [
         Card("H","7"), 
         Card("D","7"), 
         Card("S","7"), 
         Card("C","9"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Three of a kind")
예제 #6
0
 def test_two_pairs_7_and_9_at_first_until_four_pos(self):
     card_list = [
         Card("H","7"), 
         Card("S","7"), 
         Card("H","9"), 
         Card("C","9"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Two Pairs")
예제 #7
0
 def test_pair_6_at_first_and_second_position(self):
     card_list = [
         Card("H","6"), 
         Card("C","6"), 
         Card("H","8"), 
         Card("H","9"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "One Pair")
예제 #8
0
 def test_pair_de_7_na_second_and_fourth_position(self):
     card_list = [
         Card("H","9"), 
         Card("H","7"), 
         Card("H","8"), 
         Card("C","7"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "One Pair")
예제 #9
0
 def test_high_card_hand(self):
     card_list = [
         Card("H","6"), 
         Card("C","5"), 
         Card("H","8"), 
         Card("D","2"),
         Card("H","10"),
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "High Card")
예제 #10
0
 def test_four_of_8_second_to_last_pos(self):
     card_list = [
         Card("C","9"),
         Card("C","8"),
         Card("H","8"), 
         Card("D","8"), 
         Card("S","8"), 
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Four of a kind")
예제 #11
0
 def test_full_house_of_8_and_9(self):
     card_list = [
         Card("C","9"),
         Card("H","9"),
         Card("H","8"), 
         Card("D","8"), 
         Card("S","8"), 
     ]
     hand = Hand(card_list)
     self.assertEqual(hand.result(), "Full house")
예제 #12
0
 def test_figures_out_straight_flush_is_best_card(self):
     cards = [
         Card("6", "Diamonds"),
         Card("7", "Diamonds"),
         Card("8", "Diamonds"),
         Card("9", "Diamonds"),
         Card("10", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Straight Flush")
예제 #13
0
def p54(data_file_path: str) -> int:
    player_1_wins = 0
    with open(data_file_path) as file:
        for line in file:
            cards = line.split()
            player_1_hand = Hand(list(map(Card, cards[0:5])))
            player_2_hand = Hand(list(map(Card, cards[5:10])))
            if player_1_hand > player_2_hand:
                player_1_wins += 1

    return player_1_wins
예제 #14
0
    def test_comparing_royal_flush(self):
        hands = [
            Hand(list(map(Card, ['AH', 'KH', 'QH', 'JH', 'TH']))),
            Hand(list(map(Card, ['TS', 'QS', 'KS', 'JS', 'AS']))),
            Hand(list(map(Card, ['AD', 'KD', 'QD', 'JD', 'TD']))),
            Hand(list(map(Card, ['AC', 'KC', 'QC', 'JC', 'TC']))),
        ]

        for left_index in range(0, len(hands)):
            for right_index in range(left_index + 1, len(hands)):
                self.assertEqual(hands[left_index], hands[right_index])
예제 #15
0
 def test_figures_out_four_of_a_kind_is_best_card(self):
     cards = [
         Card("Ace", "Diamonds"),
         Card("Ace", "Hearts"),
         Card("Ace", "Clubs"),
         Card("Ace", "Spades"),
         Card("King", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Four of a Kind")
예제 #16
0
 def test_figures_out_full_house_is_best_card(self):
     cards = [
         Card("Ace", "Diamonds"),
         Card("Ace", "Hearts"),
         Card("Ace", "Clubs"),
         Card("King", "Spades"),
         Card("King", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Full House")
예제 #17
0
 def test_figures_out_royal_flush_is_best_card(self):
     cards = [
         Card("10", "Diamonds"),
         Card("Jack", "Diamonds"),
         Card("Queen", "Diamonds"),
         Card("King", "Diamonds"),
         Card("Ace", "Diamonds")
     ]
     hand = Hand()
     hand.add_cards(cards)
     self.assertEqual(hand.best_rank(), "Royal Flush")
예제 #18
0
    def test_comparing_full_house(self):
        hands = [
            Hand(list(map(Card, ['3H', '3C', '3D', '2S', '2H']))),
            Hand(list(map(Card, ['3H', '3C', '3D', '4S', '4H']))),
            Hand(list(map(Card, ['4H', '4C', '4D', '2S', '2H']))),
            Hand(list(map(Card, ['4H', '4C', '4D', '3S', '3H']))),
        ]

        for left_index in range(0, len(hands)):
            for right_index in range(left_index + 1, len(hands)):
                self.assertTrue(hands[right_index] > hands[left_index])
예제 #19
0
    def test_figures_out_two_pairs_is_best_card(self):
        cards = [
            Card("Ace", "Diamonds"),
            Card("Ace", "Clubs"),
            Card("King", "Diamonds"),
            Card("King", "Clubs"),
            Card("5", "Clubs"),
        ]

        hand = Hand()
        hand.add_cards(cards)
        self.assertEqual(hand.best_rank(), "Two Pair")
예제 #20
0
    def test_figures_out_three_of_the_kind_is_best_card(self):
        cards = [
            Card("Ace", "Diamonds"),
            Card("Ace", "Clubs"),
            Card("Ace", "Diamonds"),
            Card("King", "Clubs"),
            Card("5", "Clubs"),
        ]

        hand = Hand()
        hand.add_cards(cards)
        self.assertEqual(hand.best_rank(), "Three of a Kind")
예제 #21
0
파일: test_hand.py 프로젝트: zxpower/poker
def test_suited_hand_to_combos():
    assert Hand("76s").to_combos() == (
        Combo("7c6c"),
        Combo("7d6d"),
        Combo("7h6h"),
        Combo("7s6s"),
    )
예제 #22
0
def testhands():
    testinput = [
        'TH TS TC KH KC', # full house  K
        'QH QS QC 2H 2C', # full house  Q
        'TH TS TC KH AH', # 3ofakind    T
        '3S 2H 4C 5H 6H', # straight    6
        'AH 2S 3C 4H 5H', # straight    5
        'AH 2H 3H 4H 5H', # str flush   5
        'TH TS QH KH AH', # pair        T
        '8H 8S 9H 9S AS', # twopair     9
        'TH TS KH KS AS', # twopair     K
        'TH JH QH KH AH', # royal       A
    ]

    testscores = []

    for test in testinput:
        hand = Hand.fromString(test)

        testscores.append(hand)

    testscores.sort(key=lambda hand: hand.result().score(), reverse=True)

    for hand in testscores:
        print hand.result(), hand.result().score()
        pass
예제 #23
0
    def test_comparing_different_hand_types(self):
        hands = [
            Hand(list(map(Card, ['2D', '4C', '6H', '8S', 'TD']))),  #HC
            Hand(list(map(Card, ['2D', '4C', '4D', '5H', '8D']))),  #OP
            Hand(list(map(Card, ['2C', '3H', '3C', '6D', '6C']))),  #TP
            Hand(list(map(Card, ['3D', '4H', '4D', '4S', 'TC']))),  #TK
            Hand(list(map(Card, ['7S', '8C', '9H', 'TC', 'JD']))),  #S
            Hand(list(map(Card, ['3H', '5H', 'JH', 'AH', '2H']))),  #F
            Hand(list(map(Card, ['5D', 'TC', 'TH', '5S', '5H']))),  #FH
            Hand(list(map(Card, ['7H', '7D', '7C', '7S', '8H']))),  #FK
            Hand(list(map(Card, ['8D', '9D', 'TD', 'JD', 'QD']))),  #SF
            Hand(list(map(Card, ['TC', 'JC', 'QC', 'KC', 'AC']))),  #RF
        ]

        for left_index in range(0, len(hands)):
            for right_index in range(left_index + 1, len(hands)):
                self.assertTrue(hands[right_index] > hands[left_index])
예제 #24
0
파일: test.py 프로젝트: JeffCarpenter/poker
 def setUp(self):
     self.cards = {
         Card(5, Suits.Clubs),
         Card(5, Suits.Spades),
         Card(2, Suits.Hearts),
         Card(2, Suits.Diamonds),
         Card(2, Suits.Spades),
     }
     self.hand = Hand(self.cards)
예제 #25
0
파일: test_hand.py 프로젝트: zxpower/poker
def test_pair_hand_to_combos():
    assert Hand("22").to_combos() == (
        Combo("2c2d"),
        Combo("2c2h"),
        Combo("2c2s"),
        Combo("2d2h"),
        Combo("2d2s"),
        Combo("2h2s"),
    )
예제 #26
0
    def test_comparing_three_of_a_kind(self):
        ordered_hands = [
            Hand(list(map(Card, ['6H', '6D', '6C', '2S', '4H']))),
            Hand(list(map(Card, ['6H', '6D', '6C', '3S', '4H']))),
            Hand(list(map(Card, ['6H', '6D', '6C', '3S', '5H']))),
            Hand(list(map(Card, ['6H', '6D', '6C', '7S', '9H']))),
            Hand(list(map(Card, ['6H', '6D', '6C', '8S', '9H']))),
            Hand(list(map(Card, ['6H', '6D', '6C', '7S', 'TH']))),
            Hand(list(map(Card, ['7H', '7D', '7C', '2S', '4H']))),
            Hand(list(map(Card, ['7H', '7D', '7C', '8S', '9H']))),
        ]

        for left_index in range(0, len(ordered_hands)):
            for right_index in range(left_index + 1, len(ordered_hands)):
                self.assertTrue(
                    ordered_hands[right_index] > ordered_hands[left_index])
def parse_player_hands_from_line(line):
    cards = line.split(' ')
    # For every chunk of 5 cards (a player's hand)
    chunk_size = 5
    player_hands = []
    player_number = 1
    for i in range(0, len(cards), chunk_size):
        player_hand = Hand(cards[i:i + chunk_size])
        print("Player {} Hand: {}".format(player_number, str(player_hand)))
        player_hands.append(player_hand)
        player_number += 1

    # Determine the winner
    determine_winner(player_hands)
예제 #28
0
파일: test_hand.py 프로젝트: zxpower/poker
def test_offsuit_hand_to_combos():
    assert Hand("76o").to_combos() == (
        Combo("7c6d"),
        Combo("7c6h"),
        Combo("7c6s"),
        Combo("7d6c"),
        Combo("7d6h"),
        Combo("7d6s"),
        Combo("7h6c"),
        Combo("7h6d"),
        Combo("7h6s"),
        Combo("7s6c"),
        Combo("7s6d"),
        Combo("7s6h"),
    )
예제 #29
0
    def test_full_house(self):
        # Given
        hand = Hand([
            Card(CardFace.Two, CardSuit.Clubs),
            Card(CardFace.Five, CardSuit.Spades),
            Card(CardFace.Five, CardSuit.Clubs),
            Card(CardFace.Five, CardSuit.Hearts),
            Card(CardFace.Two, CardSuit.Hearts),
        ])

        # When
        hand_rank = hand.rank
        expected = Trick.FullHouse

        # Then
        expect(hand_rank).to(equal(expected))
예제 #30
0
    def test_three_of_a_kind(self):
        # Given
        hand = Hand([
            Card(CardFace.Two, CardSuit.Clubs),
            Card(CardFace.Five, CardSuit.Spades),
            Card(CardFace.Five, CardSuit.Clubs),
            Card(CardFace.Five, CardSuit.Hearts),
            Card(CardFace.Six, CardSuit.Hearts),
        ])

        # When
        hand_rank = hand.rank
        expected = Trick.ThreeOfAKind

        # Then
        expect(hand_rank).to(equal(expected))
예제 #31
0
    def test_two_pair(self):
        # Given
        hand = Hand([
            Card(CardFace.Two, CardSuit.Clubs),
            Card(CardFace.Five, CardSuit.Spades),
            Card(CardFace.Five, CardSuit.Clubs),
            Card(CardFace.Six, CardSuit.Clubs),
            Card(CardFace.Six, CardSuit.Hearts),
        ])

        # When
        hand_rank = hand.rank
        expected = Trick.TwoPair

        # Then
        expect(hand_rank).to(equal(expected))
예제 #32
0
    def test_hi_card(self):
        # Given
        hand = Hand([
            Card(CardFace.Two, CardSuit.Clubs),
            Card(CardFace.Four, CardSuit.Spades),
            Card(CardFace.Five, CardSuit.Clubs),
            Card(CardFace.Six, CardSuit.Clubs),
            Card(CardFace.Seven, CardSuit.Clubs),
        ])

        # When
        hand_rank = hand.rank
        expected = Trick.HiCard

        # Then
        expect(hand_rank).to(equal(expected))
예제 #33
0
파일: test.py 프로젝트: JeffCarpenter/poker
class FullHouseTest(TestCase):
    def setUp(self):
        self.cards = {
            Card(5, Suits.Clubs),
            Card(5, Suits.Spades),
            Card(2, Suits.Hearts),
            Card(2, Suits.Diamonds),
            Card(2, Suits.Spades),
        }
        self.hand = Hand(self.cards)
    def test_category(self):
        self.assertEqual(self.hand.best_category, Categories.FullHouse, self.hand.count_groups())
    def test_kickers(self):
        self.assertEqual(self.hand.kickers, set())
    def test_punchers(self):
        self.assertEqual(self.cards, self.hand.punchers)
예제 #34
0
def test_make_random():
    hand = Hand.make_random()
    assert isinstance(hand, Hand)
    assert isinstance(hand.first, Rank)
    assert isinstance(hand.second, Rank)