Question
Poker Hand Evaluation Note: Cards can appear in any order. Royal Flush: A straight flush with all the 'royal' cards (J-K) plus 10 and A.
Poker Hand Evaluation
Note: Cards can appear in any order.
Royal Flush: A straight flush with all the 'royal' cards (J-K) plus 10 and A. Example: 10 J Q KA
Straight Flush: Contains five consecutive cards that share the same suit. A straight flush does not contain an ace. For example: 3 7 6 4 5.
Four of a Kind: Contains four cards with the same rank. Ex: 4 10 4 4 4 .
Full House: Contains three cards that share the same rank and two cards that share a different rank. Ex: J K K J J .
Flush: Contains five cards all with the same suit. Ex: 8 2 A 4 10.
Straight: Contains five consecutive cards that do not all share the same suit. Ex: 3 7 6 5 4 .
Three of a Kind: Contains three cards that share the same rank and two cards that have unique ranks. For example: 4 7 8 4 4 .
Two Pair: Contains two cards that share the same rank, two cards that share a different rank, and one card that has a unique rank. Ex: 5 10 5 4 10
Pair: Contains two cards that share the same rank and three cards that have unique ranks. Ex: 4 10 4 4 4
High Card: All other hands. In comparing two such hands, the highest ranking card is used to determine the winner . Ex: 8 6 4 A 2
Grading:
Note: Your program will be tested on more poker hands than the ones that appear in the main() function of poker.py. Thus, it is important that you test your program on different inputs and identify the different types of poker hands in a general fashion.
10 points - Every royal flush is identified correctly. (All or nothing.)
10 points - Every straight flush is identified correctly. (All or nothing.)
10 points - Every four of a kind is identified correctly. (All or nothing.)
10 points - Every full house is identified correctly. (All or nothing.)
10 points - Every flush is identified correctly. (All or nothing.)
10 points - Every straight is identified correctly. (All or nothing.)
10 points - Every three of a kind is identified correctly. (All or nothing.)
10 points - Every two pair is identified correctly. (All or nothing.)
10 points - Every pair is identified correctly. (All or nothing.)
10 points - Every high card is identified correctly. The function should return the list representing the high card. (All or nothing.)
\# HINTS TD GET YOU STARTED: \# We use a list with two elements ta nodel a card, and a list of five cards madels a hand. * Data fron a card [rank, suit], in a hand [card, card, card, card, card] * can be retrived like this: hand[2][1] (that exanple gives us the third card's suit). a You can delete this functian and its calls below once you understand it. def hint (hand): if (hand [B] [8] =mand [1] [8]): * *eturn True t instead of returning the boolean yalue True, print message print!"Example: The first two cards both have the sane rank. It is", hand[6][0]) else Freturn Folse \# instead of returning the boolean value folse, print message: print("Example: The tirst two cards do not have the same rank."J print("Exanple Hints:"] hint [[[2,""],[7,"4"],[4,"],[8,"4"],[6,", " ]1]+ no: first twa ranks dan't natch print(i print a blank ilne * Helper Functions foptionalj N Here is a place for any extra functions you nay wish to create just ta make life \# easier when you tackle the hand evaluation functions below. For example. * sone of the cvaluatians dan't care about the suits at all. For those, it may be * sinpler to evaluate a list ot just the ranks. (1e: consider a straight or tour ot a kind.) \# Given a poker hand as a list, return a list of just the ranks. def get_ranks [hand]: ranks =1 for card in hand: ranks a append { card [0]\} return ranks * TDDD: * Decide on paraneters for the hand evaluation functions, and * define functions to return True if the criteria is net; false otherwise. \# In the case of the high_card \} fn, return the list representing the higest ranking card. * You may write more helper functians like the one above if you would like. def royal_fushihand: * Check whether hand cantains 10,J,0,K, and A cards all of the same suit. return {B=1} \# change this expression. (As it is, this funrtian will alvays return False\} def straight_fushihand): return False def straight(hand): return False def four_of_a_kind [hand ] : return RaTk0 def full_houselhand]: return False det flush(hand): return False def threc_of_o_kind { hand } : return False def two_pair[hand]: return Falso def pairlhand!: return Fals return rause def two_pair[hand]: return False def pair(hand): return False det high_cardfhandl: return "Fix me!" \# Do not nodify the evaluate function. def evaluste[poker_hand] : * Notice that once a hand is identified, no further evaluations are tried * Ex, A four of a kind is a so a three of a kind, but evalutes to four of a kind poker hand.sortll o INPORTAkT! Understand that the hand is sarted by rank after this. print (poker_hand, "Paker Hand: ", end=" = if royal_flushipoker_hand : print("Royal Flush") elif straight_flush paker_hand): elif four_ot_o_kind poker_hand): print("Four of a Kind") elif full houselpaker hand ): print["Full Hause"] elif flush (poker_hand]: elif straightlpaker" hand): print[i"Straight"] printi"Three of a Kind"; elif two pairlpoker hand): print[ ["Twn Pair ] clif pair[poker_hand]: print("one Pair") print["High Card:", high_card(poker_hand)? \#
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started