I like card game challenges so I made this one for the Italian card game Scopa. My family has been playing this game since time immemorial. It has a very interesting scoring system that should be fun to golf. I will post an answer in R to get the fun started, that I am sure people will improve upon.
The challenge: figure out the number of points scored in a round of Scopa, given the cards the player captured during the round as input.
There are 40 cards in a Scopa deck. If you are using an international deck you remove the 8s, 9s, and 10s, leaving A,2,3,4,5,6,7,Q,J,K in each suit.1 There are two players or partnerships, and after every round, all cards end up captured by one or the other of the two players. The score is counted as follows (more information here):
- The player with the most cards scores 1 point.
- The player with the most diamonds (or coins if using the Italian deck) scores 1 point.
- The player with the 7 of diamonds (or coins), known as the sette bello or beautiful seven, scores 1 point.
- The player with the highest primiera scores 1 point. A player's primiera score is the sum of the scores of the highest-value card that the player captured in each suit (see table below). If you do not have at least one card in every suit, you lose by default even if your score would exceed your opponent's score. In the exceedingly rare case that neither player has at least one card in every suit, the player with the higher primiera total scores the point.2
Table of primiera scores
| Rank | Value |
| ----- | ----- |
| 7 | 21 |
| 6 | 18 |
| A | 16 |
| 5 | 15 |
| 4 | 14 |
| 3 | 13 |
| 2 | 12 |
| Q,J,K | 10 |
So a player can score at most 4 points in a round.3 If there is a tie, which is possible for cards, diamonds, or primiera, no one scores the point.
It's important to realize that since each card must be captured by one of the two players, you can infer what cards the other player must have taken even if you only know what cards one player took. You will need to do this to correctly score primiera.
Challenge rules
Input
Your code should take as input the cards captured by a single player during a round of Scopa.
Input must be in string format, in which one character represents the rank of each card and one character its suit. This removes the potential loophole of passing the primiera scores in directly as input. Conversion of card ranks to primiera scores must be done in the program. However you may choose to use a single string separated by spaces or commas, an array of strings, or any other format. For example if you choose to encode ranks as 76A5432QJK
and suits as DCHS
you could use inputs such as ['7D', '6H', 'QD', 'JS']
or '7D,6H,QD,JS'
.
Output
An integer from 0 to 4 representing the player's score.
Winning
Shortest answer in bytes wins!
Test cases
["7D", "6D", "AD", "5D", "4D", "3D", "2D", "QD", "7C", "6C", "4C", "3C", "2C", "7H", "4H", "2H", "5S", "3S", "QS", "JS", "KS"]
Scores 4: 1 point for >20 cards, 1 point for >5 diamonds, 1 point for the 7 of diamonds, and 1 point for scoring 78 in primiera (7,7,7,5 where opponent has 7,6,5,K for 64)
["3D", "7C", "6C", "AC", "5C", "4C", "3C", "2C", "QC", "4H", "7S"]
Scores 0: <=20 cards, <=5 diamonds, no 7 of diamonds, and only scores 69 in primiera (7,7,4,3 where opponent has 7,7,6,K for 70)
[7D", "6D", "AD", "5D", "4D", "3D", "2D", "7C", "6C", "AC", "5C", "4C", "3C", "2C", "7H", "6H", "AH", "5H", "4H", "3H", "2H"]
Scores 3: 1 point for >20 cards, 1 point for >5 diamonds, 1 point for 7 of diamonds. The primiera would be 63 (7,7,7) and the opponent can only score 51 (7,Q,Q,Q) but since this hand has no spades it loses the point by default.
["7D", "6D", "AD", "5D", "4D", "3D", "2D", "QD", "JD", "KD", "QC", "QH", "QS"]
Scores 3: <=20 cards, 1 point for >5 diamonds, 1 point for 7 of diamonds. The primiera only scores 51 (7,Q,Q,Q) and the opponent can score 63 (7,7,7) but since the opponent's hand has no diamonds this hand wins the primiera point by default.
["7D", "6D", "AD", "5D", "4D", "3D", "2D", "QD", "JD", "KD", "7C", "7H"]
Scores 3: <=20 cards, 1 point for >5 diamonds, 1 point for 7 of diamonds. Even though this hand has no spades, it still wins primiera by a score of 63 to 57 (7,7,7 versus 7,6,6) because the opponent's hand has no diamonds.
["7D", "6D", "AD", "5D", "4D", "3D", "2D", "QD", "JD", "KD", "QC", "QH"]
Scores 2: <=20 cards, 1 point for >5 diamonds, 1 point for 7 of diamonds. This hand has no spades, and opponent's hand has no diamonds. Opponent wins primiera by a score of 63 to 41 (7,7,7 versus 7,Q,Q).
[]
(empty array)
Scores 0
1: At least in our family, Jack outranks Queen in Scopa but this is irrelevant for scoring purposes.
2: I've been playing this game since childhood and have never seen that happen but your code had better be able to handle that case!
3: There are bonus points for "sweeps" scored during the round which I am ignoring for the purpose of this challenge.