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(
| 47 | |
| 48 | |
| 49 | class 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 | """ |
no outgoing calls