MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / PokerHand

Class PokerHand

project_euler/problem_054/sol1.py:49–363  ·  view source on GitHub ↗

Create an object representing a Poker Hand based on an input of a string which represents the best 5-card combination from the player's hand and board cards. Attributes: (read-only) hand: a string representing the hand consisting of five cards Methods: compare_with(

Source from the content-addressed store, hash-verified

47
48
49class PokerHand:
50 """Create an object representing a Poker Hand based on an input of a
51 string which represents the best 5-card combination from the player's hand
52 and board cards.
53
54 Attributes: (read-only)
55 hand: a string representing the hand consisting of five cards
56
57 Methods:
58 compare_with(opponent): takes in player's hand (self) and
59 opponent's hand (opponent) and compares both hands according to
60 the rules of Texas Hold'em.
61 Returns one of 3 strings (Win, Loss, Tie) based on whether
62 player's hand is better than the opponent's hand.
63
64 hand_name(): Returns a string made up of two parts: hand name
65 and high card.
66
67 Supported operators:
68 Rich comparison operators: <, >, <=, >=, ==, !=
69
70 Supported built-in methods and functions:
71 list.sort(), sorted()
72 """
73
74 _HAND_NAME = (
75 "High card",
76 "One pair",
77 "Two pairs",
78 "Three of a kind",
79 "Straight",
80 "Flush",
81 "Full house",
82 "Four of a kind",
83 "Straight flush",
84 "Royal flush",
85 )
86
87 _CARD_NAME = (
88 "", # placeholder as tuples are zero-indexed
89 "One",
90 "Two",
91 "Three",
92 "Four",
93 "Five",
94 "Six",
95 "Seven",
96 "Eight",
97 "Nine",
98 "Ten",
99 "Jack",
100 "Queen",
101 "King",
102 "Ace",
103 )
104
105 def __init__(self, hand: str) -> None:
106 """

Callers 12

solutionFunction · 0.85
test_hand_is_flushFunction · 0.85
test_hand_is_straightFunction · 0.85
test_hand_is_same_kindFunction · 0.85
test_hand_valuesFunction · 0.85
test_compare_simpleFunction · 0.85
test_compare_randomFunction · 0.85
test_hand_sortedFunction · 0.85
test_euler_projectFunction · 0.85

Calls

no outgoing calls

Tested by 11

test_hand_is_flushFunction · 0.68
test_hand_is_straightFunction · 0.68
test_hand_is_same_kindFunction · 0.68
test_hand_valuesFunction · 0.68
test_compare_simpleFunction · 0.68
test_compare_randomFunction · 0.68
test_hand_sortedFunction · 0.68
test_euler_projectFunction · 0.68