Oops!
I went to check the assignment for my CS221 lab and realized I had another outlab due tomorrow as well! I hope I can get them both done :/ Here’s what I will have to finish before I sleep tonight (if I sleep tonight):
Cribbage is an old card game, usually played by 2 people. Points are scored by having various card combinations in a hand. In Cribbage, many of these combinations are similar to other card games, two-of-a-kind, three-of-a-kind, four-of-a-kind and runs (numerically sequential cards of 3 or more). But also in Cribbage, combinations of cards that add up to 15 are important. (Face cards are counted as 10 points, and aces are worth 1 point).
In our version of Cribbage, we will be “dealt” n cards from a standard 52 card deck. The number n will be at least 1 and no greater than 13. It is the job of your program to calculate the score for the n cards.
For our purposes, we will not use card suits, and we will represent the cards as single characters, as follows: Ace=1, Two=2, Three=3, Four=4, Five=5, Six=6, Seven=7, Eight=8, Nine=9, Ten=T, Jack=J, Queen=Q, King=K
Scoring
Two-of-a-kind (a pair): 2 points
Three-of-a-kind (3 pair): 6 points
Four-of-a-kind (6 pair): 12 points
Runs (sequentially numbered cards of length greater than 2): 1 point per card in the run
Fifteens: 2 points for any distinct combination of cards that sum to 15
- Example #1 (n = 5)
- Hand dealt: 595T5
- 14 points (3 pair for 6 points, plus 4 15s for 8 points(10+5, 10+5, 10+5, 5+5+5))
- Example #2 (n = 5)
- Hand dealt: 62947
- 6 points (3 15s (9+6, 2+4+9, 2+6+7))
- Example #3 (n = 5)
- Hand dealt: 56788
- 14 points (2 runs of 4 cards for 8 points, a pair of 8s for 2 points, and two 15s (8+7,8+7) for 4 points)
- Example #4 (n = 5)
- Hand dealt: 45666
- 21 points (3 runs of 3 cards for 9 cards, 3 pair for 6 points, 3 15s for 6 points)
Your task is to write a program that reads a file of “dealt” cards, and returns the correct score for each dealing.
Wish me luck!