Skat is a traditional German card game for 3 players. The deck consists of 32 cards: Ace, King, Queen, Jack, 10, 9, 8, 7 in all 4 suits (Clubs, Spades, Hearts, Diamonds).
In every round there one player plays solo while the other two play against him. At the start of a round each player is dealt 10 cards, the remaining 2 card are called the skat and are put facedown in the middle. The solo player is determined by a bidding phase. This is the part of the game that you will have to deal with in this challenge, more details on this below.
The player who wins the bidding phase becomes the solo player. He picks up the skat and then drops two cards (which may be the same, the other team does not know), picks the trump suit, and the round starts.
One round consists of ten tricks. The player who wins a trick leads the next one until all cards are played. I won't explain the rules here, but you should know that having a lot of trump cards is good. If you want to learn about the rules check the Wikipedia article which I linked at the start of this post, but it is not needed for this challenge.
You want to teach your two sons how to play skat. The rules are not that hard, so they quickly get into it. The only thing giving them a hard time is the bidding, specifically calculating the game value of their hand. So you decide to write a small program which outputs the maximum game value that they can bid given their current hand.
Calculating the game value
Every hand has a certain game value. It is determined by the amount of sequential Jacks you have and the suit which you want to pick as trump. Let's start with the first factor, the jacks!
The Jack Factor
Jacks are always trump cards, and they beat every other trump card. The order of strength between the four Jacks is:
- Jack of Clubs (highest)
- Jack of Spades
- Jack of Hearts
- Jack of Diamonds (lowest)
In the further explanation I will refer to them with the numbers I assigned to them here.
You remember that there is some kind of factor that you get from the Jacks in your hand which is parts of the game value? Great! Here is how you get it:
This Jack factor is the number of top Jacks (see order above) in sequence, plus 1. So if you have all 4 Jacks it is 4 + 1 = 5. If you have only the first 2 Jacks, it is 2 + 1 = 3.
Alternatively, to make things a bit more complicated, the Jack Factor can also be the number of top Jacks in sequence that you are missing, plus 1. So if you are missing the first one, it is 1 + 1 = 2. If you are missing he first 3, it is 3 + 1 = 4. Here some examples, using the numbering above:
[1, 4] -> 1 + 1 = 2 [1, 2, 4] -> 2 + 1 = 3 [2, 3, 4] -> 1 + 1 = 2 [1, 2, 3, 4] -> 4 + 1 = 5  -> 4 + 1 = 5
That was the first factor. Here is how you get the 2nd one:
The Trump Suit Factor
This one is a lot simpler. The 2nd factor is determined by the trump suit that the solo player picks using the following mapping:
Clubs -> 12 Spades -> 11 Hearts -> 10 Diamonds -> 9
That was easy, wasn't it?
The Game Value
The game value is the product of the two factors. Pretty easy you think? Wrong! While the Jack-Factor is fixed, the suit-factor is not. The suit you end up picking as trump depends on the amount of trumps and the value of your non-trump cards in your hand. It would be way too complicated to explain what a good hand looks like, so you will use the following algorithm:
The Which-Trump-do-I-Pick Algorithm
You don't have to participate in the bidding. If you decide that your hand is too bad to play solo, you can just pass. Your hand must match the following criteria to be playable:
Have at least 6 trump cards (cards of the trump suit you pick + the number of Jacks). If this is possible for more than one suit, pick the one which would result in more trump cards. If there is still a tie, pick the suit with the highest rating given above.
Out of the non-trump cards, have at least 1 Ace.
If your hand does not match both of this criteria, you will pass. If it does, you will output the calculated game value and the chosen trump suit.
Short note: Of course this is a very simplified algorithm. There goes way too much strategy and experience into judging a hand than we could ever cover in a challenge like this.
Every card has an unique identifier. The first part is the suit (Clubs, Spades, Hearts, Diamonds), the second part is the value which is given by this mapping:
Ace -> A King -> K Queen -> Q Jack -> J 10 -> 0 9 -> 9 8 -> 8 7 -> 7
Both parts combined form one card. The value comes first, then comes the suit. You may take the cards in any format as you want.
If the hand is playable, output the game value and the picked trump suit (order doesn't matter). If it's not, output "pass".
- As mentioned you can take the input in the most convenient format for you. Examples see below in the test cases.
- Input may be provided by command line arguments, user input, or function arguments.
- Output may be provided as return value or may just be printed on the screen.
- The cards in the input may not be ordered in any way. Your program has to be able to deal with any random card order.
- Lowest byte-count wins!
Input in the test cases will be a list of 2-char Strings.
1. ["JC", "JS", "JD", "AC", "KC", "9C", "AS", "7H", "QD", "8D"] -> 36 Clubs 2. ["JD", "AS", "0S", "KS", "QS", "9S", "8S", "AD", "8C", "9C"] -> 44 Spades 3. ["JH", "JD", "0S", "KS", "9C", "8C", "QH", "KH", "AD", "9D"] -> pass 4. ["JD", "AS", "KS", "QS", "0S", "9S", "8D", "7D", "0C", "QH"] -> pass
- Two Jacks in a row with Clubs as trump. So the game value is 3 x 12 = 36
- Three Jacks in a row missing with Spades as trump. So the game value is 4 x 11 = 44
- Only a maximum 4 of trump cards is possible, so you will pass.
- Six trump cards with Spades but no non-trump ace, so you will pass.
If some rules are unclear, go ahead and comment. I have grown up with this game, so it hard for me to judge if I described everything in enough detail.
And now... Happy Coding!
edit: As pointed out to me in the comments (thanks to isaacg), there is a rule which counts the following top trumps after the 4 Jacks into the "Jack-factor" so it could go up to 11. To keep this challenge simple and to not confuse people, the rules I proposed originally will stay as they are. So the maximum factor stays at 5.