Program 2: Simplified Five Card Cribbage
Logistics
- Due Date: Friday, February 8th 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 or you
will both lose 10 points.
- 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.
Simplified Five Card Cribbage Scoring
- A hand consists of five different cards. Each card contains
a rank and a suit. All ranks will be "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten", "jack", "queen",
"king" or "ace". All suits will be "clubs", "diamonds", "hearts"
or "spades".
- If all five cards have the same suit, that is called a flush
and is worth 5 points. For example, if all five cards are "diamonds",
that is a flush.
- If any two cards have the same rank, that is called a pair
and is worth 2 points. For example, if the ranks of the cards are
"two", "two", "two", "five" and "five", there are four pairs for
a total of 8 points.
- If any two cards add up to 15, that is called a fifteen
and is worth 2 points. An "ace" is worth 11, a "king" is worth 10,
a "queen" is worth 10, a "jack" is worth 10, and all other cards are
worth their face value (e.g. a "seven" is worth 7). For example,
if the ranks of the cards are "six", "seven", "seven", "eight" and
"nine", there are three fifteens for a total of 6 points. Note: In
this simplified version of Cribbage, only pairs of cards that add up
to 15 are worth 2 points. Fifteens that are produced by three or more
cards are worth 0 points.
- The value of a hand is the sum of anything that scores points.
For example, a hand consisting of a "three", "four", "four", "six"
and "nine" is worth 4 points (2 for the pair of "fours", 2 for
the fifteen).
Assignment
- Download cribbage.py and modify it
so that when it is run on this input file,
it produces this output in the Python shell.
Note: the input file (cribbage.txt) should be located in the
same directory as the python program.
Input File Information
- We will study files later this semester.
- The input file can contain any number of cribbage hands.
Each line contains a five card cribbage hand in this format:
Card 1 Rank, Card 1 Suit, Card 2 Rank, Card 2 Suit,
Card 3 Rank, Card 3 Suit, Card 4 Rank, Card 4 Suit,
Card 5 Rank, Card 5 Suit.
- All cribbage hands are valid.
- Note: Your program might be tested on a different set of cribbage
hands so it is important to make your solution as general as possible.
- Note: The cards in a cribbage hand can appear in any order.
Test File (Posted February 9th)
Grading - 100 points
- 10 points - Every flush is identified correctly.
(All or nothing.)
- 15 points - Every pair is identified correctly.
(5 points for each incorrect answer up to 15 points.)
- 25 points - Every fifteen is identified correctly.
(5 points for each incorrect answer up to 25 points.)
- 15 points - A separate function is used to determine each different
type of scoring (e.g. flush, pairs, fifteens).
(5 points for each missing function up to 15 points.)
- 20 points - The format of your output matches the format
of the sample output exactly. (4 points for
each type of difference up to 20 points.)
- 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.)