Program 2: Poker Hand Evaluation
Logistics
- Due Date: Friday, September 29th no later than 11:59 p.m.
- Partner Information: You may complete this assignment
individually or with exactly one partner. If you work with a partner,
you must both be enrolled in the same lab section.
- Submission Instructions (working alone): Upload your solution,
entitled YourFirstName-YourLastName-Program2.py to the
BrightSpace Program 2 Dropbox.
- Submission Instructions (working with one lab mate): Upload your
solution, entitled
YourFirstName-YourLastName-PartnerFirstName-PartnerLastName-Program2.py
to the BrightSpace Program 2 Dropbox. Note: If you work with a partner,
only one person needs to submit a solution. If you both submit a
solution, the submission that will be graded is the one from the partner
whose last name comes alphabetically first.
- Deadline Reminder:
Once the submission deadline passes, BrightSpace will no
longer accept your Python submission and you will no longer
be able to earn credit. Thus, if you are not able to fully complete
the assignment, submit whatever you have before the deadline so that
partial credit can be earned.
Learning Outcomes
- To solve this problem, you need to understand the following
Python concepts: lists, functions, loops and if statements.
Poker Hand Representation
- A hand consists of five different cards drawn from a 52-card deck.
Each card contains a rank (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 or 14)
and a suit ("clubs", "diamonds", "hearts" or "spades").
For the ranks, an 11 represents a jack, a 12 represents a queen,
a 13 represents a king and a 14 represents an ace.
Poker Hand Evaluation - From Best to Worst
Note: Cards can appear in any order.
- Royal Flush: Contains a 10, jack, queen, king and ace, all of the
same suit. For example: king clubs, jack clubs, ace clubs, 10 clubs,
queen clubs.
- Straight Flush: Contains five consecutive cards that share the same
suit. A straight flush does not contain an ace. For example:
3 clubs, 7 clubs, 6 clubs, 4 clubs, 5 clubs.
- Four of a Kind: Contains four cards that share
the same rank. For example: 4 clubs, 10 diamonds, 4 hearts, 4 spades,
4 diamonds.
- Full House: Contains three cards that share the same rank
and two cards that share a different rank. For example:
jack hearts, king hearts, king clubs, jack clubs, jack diamonds.
- Flush: Contains five cards of the same suit.
- Straight: Contains five consecutive cards that do not all share
the same suit. For example: 3 clubs, 7 diamonds, 6 hearts, 5 hearts,
4 clubs.
- Three of a Kind: Contains three cards that share the same rank
and two cards that have unique ranks. For example: 6 clubs, 7 clubs,
8 clubs, 7 diamonds, 7 hearts.
- 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.
For example: six diamonds, six hearts, queen spades, ace clubs,
queen diamonds.
- Pair: Contains two cards that share the same rank and
three cards that have unique ranks. For example: king hearts,
queen hearts, 9 diamonds, 9 hearts, ace spades.
- Nothing: All other hands of five cards. For example:
9 hearts, 6 diamonds, 3 diamonds, 10 spades, queen clubs.
Assignment
- Download Program2.py and rename it
according to the instructions above.
Once you fully understand it, modify it
to evaluate poker hands correctly. When it is run using
the hands provided, it should produce
this output.
- The evaluate function is correct - do not modify it.
- If it is helpful to do so, you are welcome to introduce other
functions into your solution.
Grading - 100 points
Note: Your program will be tested on a different set of
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.
- 5 points - Every royal flush is identified correctly. (All or nothing.)
- 5 points - Every straight flush is identified correctly. (All or nothing.)
- 5 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 nothing is identified correctly. (All or nothing.)
- 15 points - The Python solution is properly commented,
easy to understand, high quality and does not contain unnecessary code.
(3 points for each type of improvement up to 15 points.)
Program 2 Test Data
hand1 = [[10, "clubs"], [14, "clubs"], [12, "clubs"], [13, "clubs"], [11, "clubs"]] # royal flush
hand2 = [[13, "clubs"], [12, "clubs"], [11, "clubs"], [10, "clubs"], [9, "clubs"]] # straight flush
hand3 = [[9, "diamonds"], [9, "clubs"], [9, "hearts"], [2, "clubs"], [9, "spades"]] # 4 of a kind
hand4 = [[8, "diamonds"], [7, "clubs"], [8, "hearts"], [8, "clubs"], [7, "spades"]] # full house
hand5 = [[13, "hearts"], [7, "hearts"], [2, "hearts"], [8, "hearts"], [10, "hearts"]] # flush
hand6 = [[13, "clubs"], [11, "clubs"], [10, "clubs"], [12, "clubs"], [14, "spades"]] # straight
hand7 = [[13, "diamonds"], [14, "clubs"], [14, "hearts"], [8, "clubs"], [14, "spades"]] # 3 of a kind
hand8 = [[10, "spades"], [10, "clubs"], [6, "diamonds"], [2, "diamonds"], [2, "hearts"]] # 2 pair
hand9 = [[10, "spades"], [12, "clubs"], [11, "diamonds"], [9, "diamonds"], [11, "hearts"]] # 1 pair
hand10 =[[14, "diamonds"], [12, "diamonds"], [6, "diamonds"], [8, "diamonds"], [10, "hearts"]] # nothing
hands = [hand1, hand2, hand3, hand4, hand5, hand6, hand7, hand8, hand9, hand10]
for hand in hands:
print(hand, "-->", evaluate(hand))
Honor's Lab
- The points you earn from the grading scale above will be
multiplied by .9 for a maximum of 90 points.
- The other 10 points can be earned by enhancing the
assignment in a creative, non-trivial manner.
- In the BrightSpace Dropbox comment box, describe
your enhancement clearly. (You must include this comment
to earn the additional points.)