Example #1
0
 def test_hand_2pairs(self):
     hand = PokerHand(["5H", "3H", "3H", "4H", "4H"])
     assert(hand.has_2pairs())
     hand2 = PokerHand(["2H", "3H", "4H", "4H", "5H"])
     assert(not hand2.has_2pairs())
     hand3 = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(not hand3.has_2pairs())
Example #2
0
 def test_hand_straight_flush(self):
     hand = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(hand.has_straight_flush())
     hand2 = PokerHand(["2H", "3H", "5H", "6H", "7C"])
     assert(not hand2.has_straight_flush())
     hand3 = PokerHand(["2H", "3H", "5H", "6H", "8H"])
     assert(not hand3.has_straight_flush())
Example #3
0
 def test_hand_get_straight_flush(self):
     hand = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(hand.get_straight_flush() == PokerCard("6H"))
     hand2 = PokerHand(["2H", "3H", "5H", "6H", "7C"])
     assert(hand2.get_straight_flush() == None)
     hand3 = PokerHand(["2H", "3H", "5H", "6H", "8H"])
     assert(hand3.get_straight_flush() == None)
Example #4
0
 def __init__(self, parent, players):
     PokerHand.__init__(self, parent, players)
     self.hand_phases = [
         self.blinds_and_preflop,
         self.__wrap(self.deal_table_cards),  # flop
         self.betting_round,
         self.__wrap(self.deal_table_cards),  # turn
         self.betting_round,
         self.__wrap(self.deal_table_cards),  # river
         self.betting_round,
         self.__wrap(self.showdown),
     ]
Example #5
0
	def test_which_hand_is_stronger(self):
		order = ['HIGH','PAIR','TWOPAIRS','DRILL','STRAIGHT','FLUSH','FULL','POKER','SFLUSH','RFLUSH']
		actual = []
		for i in range(0,len(order)):
			left_hand = PokerHand(SAMPLES[order[i]])
			for j in range(i+1,len(SAMPLES)):
				if j >= len(order):
					break
				right_hand = PokerHand(SAMPLES[order[j]])
				actual.append(right_hand.is_stronger_than(left_hand))
		expected = [True for i in range(0,len(actual))]
		self.assertEqual(expected,actual)
Example #6
0
class TestPokerCompaire(unittest2.TestCase):
    def setUp(self):
        self.P = PokerHand('2S AH 4H 5S 6C')
        self.P1 = PokerHand("4S 5H 6H TS AC")
        self.P2 = PokerHand("2S 3H 6H 7S 9C")
        self.P3 = PokerHand("2S AH 4H 5S KC")
        pass

    def test_compare_with(self):

        self.assertEqual('Tie', self.P.compare_with('AD 4C 5H 6H 2C'))

        self.assertEqual('Win', self.P1.compare_with("3S 5H 6H TS AC"))

        self.assertEqual('Loss', self.P2.compare_with("7H 3C TH 6H 9S"))

        self.assertEqual('Loss', self.P3.compare_with("AH AC 5H 6H 7S"))

    def test_count_value(self):
        self.assertEqual(True, self.P.count_value(3, 'AAAQ3', 1))
Example #7
0
def test_one_pair_tie_break_1(deck):
    """
  Test tiebreak situation for the pair being the same rank, and the first high
  card beiing the same (should fall to the 2nd high card).
  """
    a = PokerHand([deck['AD'], deck['AH'], deck['9C'], deck['2C'], deck['7C']])
    b = PokerHand([deck['AC'], deck['AS'], deck['9S'], deck['JS'], deck['2S']])
    assert a.is_one_pair()
    assert b.is_one_pair()
    assert b > a
Example #8
0
def three_of_a_kind(deck):
    return PokerHand(
        [deck['JH'], deck['8D'], deck['JS'], deck['2C'], deck['JC']])
Example #9
0
 def test_hand_get_full_house(self):
     hand = PokerHand(["5H", "5H", "3H", "3H", "3H"])
     assert(hand.get_full_house() == PokerCard("3H"))
     hand2 = PokerHand(["2H", "3H", "4H", "4H", "4H"])
     assert(hand2.get_full_house() == None)
Example #10
0
    while NumberOfPlayers.isdigit() is False:
        NumberOfPlayers = input(
            "How many players are in your Poker game? Enter here: ")

    print(
        "\nThe characteristics of the string of cards are:\n- A space is used as card seperator\n- Each card consists of two characters\n- The \
first character is the value of the card, valid characters are:\n\
	`2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `T`(en), `J`(ack), `Q`(ueen), `K`(ing), `A`(ce)\n\
- The second character represents the suit, valid characters are: `S`(pades), `H`(earts), `D`(iamonds), `C`(lubs)\n\n\
	For example... Queen of Hearts, Ten of Spades, and Nine of Diamonds = 'QH TS 9D'\n"
    )

    while check != "Valid":
        player = input("Please enter the 5 cards in your hand: ")
        check = check_hand(player.upper())
        if check == "Valid":
            hand = PokerHand("Player", player.upper())
    for i in range(int(NumberOfPlayers) - 1):
        check = "Reset"
        name.append(input("Enter the next opponent's name: "))
        while check != "Valid":
            o = input(f"Enter {name[i]}'s hand: ")
            check = check_hand(o.upper())
            if check == "Valid":
                opp.append(o)

    for i, k in enumerate(opp):
        opponent.append(PokerHand(name[i], k.upper()))

    unittest.main()
Example #11
0
from poker import PokerHand

# test high card rank
hand = PokerHand('3D JC 8S 4H 2C')
assert hand.rank == 'High Card', hand.rank

# keep this at the end - it will only show if all your tests pass
print('Tests passing!')
Example #12
0
def test_high_card_tie_break(deck):
    a = PokerHand([deck['3H'], deck['8D'], deck['JS'], deck['6C'], deck['7C']])
    b = PokerHand([deck['QH'], deck['2D'], deck['9S'], deck['6S'], deck['7S']])
    assert a._score() is None
    assert b._score() is None
    assert a < b  # Queen beats Jack
Example #13
0
def straight_flush(deck):
    return PokerHand(
        [deck['6H'], deck['7H'], deck['8H'], deck['9H'], deck['TH']])
Example #14
0
def full_house(deck):
    return PokerHand(
        [deck['JH'], deck['JC'], deck['JS'], deck['7H'], deck['7C']])
Example #15
0
def one_pair(deck):
    return PokerHand(
        [deck['2H'], deck['8D'], deck['JS'], deck['2C'], deck['7C']])
Example #16
0
def test_straight_tiebreak(deck):
    a = PokerHand([deck['3H'], deck['4D'], deck['5S'], deck['6C'], deck['7C']])
    b = PokerHand([deck['4H'], deck['5D'], deck['6S'], deck['7S'], deck['8S']])
    assert a.is_straight()
    assert b.is_straight()
    assert b > a  # Straight ending in 8 beats one ending in 7
Example #17
0
def test_two_pair_tie_break_2_tie(deck):
    a = PokerHand([deck['3H'], deck['7D'], deck['3S'], deck['6C'], deck['7C']])
    b = PokerHand([deck['3D'], deck['3C'], deck['7H'], deck['6S'], deck['7S']])
    assert a.is_two_pair()
    assert b.is_two_pair()
    assert b == a  # Each hand has a pair of 3 and 7, with 6 high card (tie)
Example #18
0
 def test_hand_get_straight(self):
     hand = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(hand.get_straight() == PokerCard("6H"))
     hand2 = PokerHand(["2H", "3H", "5H", "6H", "7H"])
     assert(hand2.get_straight() == None)
Example #19
0
 def test_hand_straight(self):
     hand = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(hand.has_straight())
     hand2 = PokerHand(["2H", "3H", "5H", "6H", "7H"])
     assert(not hand2.has_straight())
Example #20
0
def straight(deck):
    return PokerHand(
        [deck['6H'], deck['7D'], deck['8S'], deck['9C'], deck['TC']])
Example #21
0
def test_three_of_a_kind_tiebreak(deck):
    a = PokerHand([deck['3H'], deck['7D'], deck['3S'], deck['3C'], deck['9C']])
    b = PokerHand([deck['QH'], deck['QD'], deck['2S'], deck['6S'], deck['QS']])
    assert a.is_three_of_a_kind()
    assert b.is_three_of_a_kind()
    assert b > a  # Queen beats 7
Example #22
0
def flush(deck):
    return PokerHand(
        [deck['6H'], deck['2H'], deck['AH'], deck['7H'], deck['5H']])
Example #23
0
def test_flush_tiebreak(deck):
    a = PokerHand([deck['2H'], deck['7H'], deck['6H'], deck['KH'], deck['9H']])
    b = PokerHand([deck['2D'], deck['QD'], deck['5D'], deck['9D'], deck['AD']])
    assert a.is_flush()
    assert b.is_flush()
    assert b > a  # Queen beats 7
Example #24
0
def four_of_a_kind(deck):
    return PokerHand(
        [deck['2D'], deck['2H'], deck['2C'], deck['2S'], deck['5H']])
Example #25
0
from poker import PokerHand

# test high card rank
hand = PokerHand('3D JC 8S 4H 2C')
assert hand.rank == 'High Card', hand.rank

hand = PokerHand('AS TC 2H 3H 8D')
assert hand.rank == 'High Card', hand.rank

hand = PokerHand('2H 3D 7D 9S TS')
assert hand.rank == 'High Card', hand.rank

hand = PokerHand('TS QH 3D 5D 6D')
assert hand.rank == 'High Card', hand.rank

# test pair rank
hand = PokerHand('AH AD 8C 4S 7H')
assert hand.rank == 'Pair', hand.rank

hand = PokerHand('2H 3H 5H 7D 2C')
assert hand.rank == 'Pair', hand.rank

hand = PokerHand('9S TC 2S 8C 8S')
assert hand.rank == 'Pair', hand.rank

hand = PokerHand('AC QH 3D 5D 3H')
assert hand.rank == 'Pair', hand.rank

# test two pair rank
hand = PokerHand('4C 4S 3C 3D QC')
assert hand.rank == 'Two Pair', hand.rank
Example #26
0
def royal_flush(deck):
    return PokerHand(
        [deck['TH'], deck['JH'], deck['QH'], deck['KH'], deck['AH']])
Example #27
0
 def test_hand_4kind(self):
     hand = PokerHand(["2H", "4H", "4H", "4H", "4H"])
     assert(hand.has_4kind())
     hand2 = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(not hand2.has_4kind())
Example #28
0
S = 'S'
C = 'C'
# you can use integers for the others (but not 10 - use T)

# test single card
card_1 = Card(A, S)
card_2 = Card(A, D)
assert card_1 == card_2
card_3 = Card(K, S)
assert card_1 != card_3
assert card_1 > card_3
assert not card_1 < card_3

# test comparing two poker hands
cards = [Card(v, s) for v, s in [(A, S), (2, D), (4, C), (7, H), (K, S)]]
hand_1 = PokerHand(cards)
cards = [Card(v, s) for v, s in [(A, C), (3, D), (5, C), (8, H), (T, S)]]
hand_2 = PokerHand(cards)
assert hand_1 == hand_2
assert hand_2 == hand_1

cards = [Card(v, s) for v, s in [(A, S), (2, D), (4, C), (7, H), (K, S)]]
hand_1 = PokerHand(cards)
cards = [Card(v, s) for v, s in [(Q, S), (3, D), (5, C), (8, H), (T, S)]]
hand_2 = PokerHand(cards)
assert hand_1 > hand_2
assert hand_2 < hand_1

# test creating a deck
deck = create_deck()
assert len(deck) == 52
Example #29
0
 def test_hand_get_pair_vals(self):
     hand = PokerHand(["4H", "2H", "2H", "3H", "3H"])
     assert(hand.get_pairs() == [PokerCard("2H"), PokerCard("3H")])
Example #30
0
 def test_something(self):
     self.assertNotEqual(PokerHand("THIS IS A TEST"), None)
Example #31
0
def test_straight_flush_tiebreak(deck):
    a = PokerHand([deck['3H'], deck['4H'], deck['5H'], deck['6H'], deck['7H']])
    b = PokerHand([deck['4D'], deck['5D'], deck['6D'], deck['7D'], deck['8D']])
    assert a.is_straight_flush()
    assert b.is_straight_flush()
    assert b > a  # Straight ending in 8 beats one ending in 7
Example #32
0
def test_full_house_tibreak(deck):
    a = PokerHand([deck['2H'], deck['7H'], deck['7D'], deck['2C'], deck['7C']])
    b = PokerHand([deck['9D'], deck['4D'], deck['9S'], deck['4S'], deck['9C']])
    assert a.is_full_house()
    assert b.is_full_house()
    assert b > a
Example #33
0
 def test_hand_full_house(self):
     hand = PokerHand(["3H", "3H", "3H", "2H", "2H"])
     assert(hand.has_full_house())
     hand2 = PokerHand(["2H", "3H", "4H", "5H", "6H"])
     assert(not hand2.has_full_house())
Example #34
0
from poker import PokerHand, VALUES, SUITS
from itertools import product, combinations
import json

deck = ['{}{}'.format(v, s) for v, s in product(VALUES, SUITS)]


def sort_cards_string(card_string):
    cards = card_string.split(' ')
    return ' '.join(sorted(cards))


hand_ranks = {
    sort_cards_string(' '.join(c)): PokerHand(' '.join(c)).rank
    for c in combinations(deck, 5)
}

with open('hand_ranks.json', 'w') as f:
    json.dump(hand_ranks, f)
Example #35
0
def two_pair(deck):
    return PokerHand(
        [deck['2H'], deck['8D'], deck['JS'], deck['2C'], deck['JC']])
Example #36
0
 def test_all_hands(self):
     self.assertTrue(
         PokerHand("TC TH 5C 5H KH").compare_with(PokerHand("9C 9H 5C 5H AC")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("TS TD KC JC 7C").compare_with(PokerHand("JS JC AS KC TD")) == Result.LOSS
     )
     self.assertTrue(
         PokerHand("7H 7C QC JS TS").compare_with(PokerHand("7D 7C JS TS 6D")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("5S 5D 8C 7S 6H").compare_with(PokerHand("7D 7S 5S 5D JS")) == Result.LOSS
     )
     self.assertTrue(
         PokerHand("AS AD KD 7C 3D").compare_with(PokerHand("AD AH KD 7C 4S")) == Result.LOSS
     )
     self.assertTrue(
         PokerHand("TS JS QS KS AS").compare_with(PokerHand("AC AH AS AS KS")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("TS JS QS KS AS").compare_with(PokerHand("TC JS QC KS AC")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("TS JS QS KS AS").compare_with(PokerHand("QH QS QC AS 8H")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("AC AH AS AS KS").compare_with(PokerHand("TC JS QC KS AC")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("AC AH AS AS KS").compare_with(PokerHand("QH QS QC AS 8H")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("TC JS QC KS AC").compare_with(PokerHand("QH QS QC AS 8H")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("7H 8H 9H TH JH").compare_with(PokerHand("JH JC JS JD TH")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("7H 8H 9H TH JH").compare_with(PokerHand("4H 5H 9H TH JH")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("7H 8H 9H TH JH").compare_with(PokerHand("7C 8S 9H TH JH")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("7H 8H 9H TH JH").compare_with(PokerHand("TS TH TD JH JD")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("7H 8H 9H TH JH").compare_with(PokerHand("JH JD TH TC 4C")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("JH JC JS JD TH").compare_with(PokerHand("4H 5H 9H TH JH")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("JH JC JS JD TH").compare_with(PokerHand("7C 8S 9H TH JH")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("JH JC JS JD TH").compare_with(PokerHand("TS TH TD JH JD")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("JH JC JS JD TH").compare_with(PokerHand("JH JD TH TC 4C")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("4H 5H 9H TH JH").compare_with(PokerHand("7C 8S 9H TH JH")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("4H 5H 9H TH JH").compare_with(PokerHand("TS TH TD JH JD")) == Result.LOSS
     )
     self.assertTrue(
         PokerHand("4H 5H 9H TH JH").compare_with(PokerHand("JH JD TH TC 4C")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("7C 8S 9H TH JH").compare_with(PokerHand("TS TH TD JH JD")) == Result.LOSS
     )
     self.assertTrue(
         PokerHand("7C 8S 9H TH JH").compare_with(PokerHand("JH JD TH TC 4C")) == Result.WIN
     )
     self.assertTrue(
         PokerHand("TS TH TD JH JD").compare_with(PokerHand("JH JD TH TC 4C")) == Result.WIN
     )
Example #37
0
def test_four_of_a_kind_tibreak(deck):
    a = PokerHand([deck['2H'], deck['2D'], deck['2D'], deck['2C'], deck['7C']])
    b = PokerHand([deck['9D'], deck['9H'], deck['9S'], deck['4S'], deck['9C']])
    assert a.is_four_of_a_kind()
    assert b.is_four_of_a_kind()
    assert b > a