Title: Score my Tarok hand
Inspired by this challenge
In Slovenia (and elsewhere in central Europe), the card game Tarok is very popular. See here for a complete list of rules, but essentially it is a trick taking game, played in teams that change per round.
This challenge is a code-golf challenge, concerning the scoring of a hand, at the end of a round.
In a normal round, the game is played in partnerships. Any one player could decide the "contract" for the round, and that player (plus anyone on their team) either wins or loses the round, giving them a positive or negative score. They are known as the "Declaring team". The "Opposing team" cannot score in that round.
The input for this challenge will therefore be the Declaring team's cards, plus the contract type they bid for.
In a game of Tarok, there are 54 cards; as follows (shown as highest to lowest in each suit - names in brackets after a card are local names given to certain cards):
- Spades, Clubs: King, Queen, Knight, Jack, 10, 9, 8, 7
- Diamonds, Hearts: King, Queen, Knight, Jack 1, 2, 3, 4
- Taroks: Joker (škis), XXI (mond), XX, XIX, ... III, II, I (pagat)
The point value of the cards are as follows:
- kings, škis, XXI and I - 5 points each
- queens - 4 points each
- knights - 3 points each
- jacks - 2 points each
- all other cards - 1 points each
Scoring a hand
This is what I believe makes this challenge interesting.
- For each set of three cards in your hand, add up their values and subtract 2.
- If you end up with one or two cards left over after making the sets of three, add up their values and subtract 1.
- So, a pair or a set of three one-point cards are both worth 1 point; but a single one-point card is worth nothing.
The total value of the pack comes to 70 card points.
In most contracts (see below), the declarer's side wins if at the end of the play they have at least 36 of the available 70 points; otherwise they lose. Because of this, the members of each team pool their cards for scoring; and so if you know the score of one team, you can calculate the score of the other.
Once the hand value has been calculated, the difference from 35 is taken (i.e.
handValue - 35), and this difference is rounded to the nearest 5 points.
Contracts and Bonuses
Once the hand score is known for the declaring team, the final score is calculated based on the "contract" that was chosen at the start of the round (where "difference" is the rounded hand difference from 35, calculated above. Note this may be negative, if the opposing team got more points):
Contract Name | Scoring (+ if contract won, - if lost)
Three | difference +/- 10
Two | difference +/- 20
One | difference +/- 30
Solo Three | difference +/- 40
Solo Two | difference +/- 50
Solo One | difference +/- 60
Beggar* | 70 (fixed)
Solo without | 80 (fixed)
Open Beggar* | 90 (fixed)
Colour Valat Without** | 125 (fixed), no bonuses
Valat Without** | 500 (fixed), no bonuses
With the exception of those marked, all contracts are "won" if the difference is 36 or higher; otherwise it was "lost".
* - to win the points, you must win no tricks (and therefore no cards)
** - to win the points, you must win ALL the tricks (and therefore all the cards). In this case, no other scoring bonuses are applied.
Bonus points are awarded to the declaring team, or subtracted from the declaring team if the opposing team complete the criteria. Bonuses are only awarded on contracts where the difference is taken into account. (i.e. from "Three" to "Solo One" only, in the above table)
Bonus Criteria | Bonus Points
Take škis, XXI and I ("the Trule") in tricks | 10
Take all 4 kings in tricks | 10
Take all the tricks ("Valat") | 500, no other scoring is applied
(note that in Tarok, there are some actions that take place during play which give additional bonuses, such as announcing at the start of the game your intention to get a certain bonus; but as those would require more inputs to calculate, I will leave these out of this challenge.)
All 54 cards, any contract -> +500 points
No Cards, called Beggar -> + 70 points
king, king, king, king, škis, XXI, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, 2H; called "One" -> 30 points for contract + 20 points difference (hand score is 56 which is 21 different from 35, so round to 20) + 10 points kings bonus + 10 points Trule Bonus = 70 points
No cards, called "Solo One" -> -500 (opposing team got Valat bonus)
KS,8S,7S, called "Two" ->failed contract, so -30 (difference), -20 (contract), -10 (opponents got Trule bonus) = -60 points
KH, KD, škis, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, 2H, 7C,1D,2D,4D; called "Solo Without" = +80 points
KH, KD, škis, I, queen, queen, queen, queen, knight, knight, knight, knight, jack, jack, 1H, X, III,II,2D,KS; called "Three" = +15 difference (49-35, rounded) + 10 contract = +25