13
1
Input:
Firstly
An array of three cards representing the cards played by each player formatted like
[JD][TH][9S]
Representing
Jack of Diamonds, 10 of Hearts, and Nine of Spades.
As you always sit across from your team-mate in Euchre, the second element represents your team mate's play. Here, the TH
.
Secondly
A Single Char, String, etc representing the trump suit formatted like
S, D, C, H
representing
Spades, Diamonds, Clubs, Hearts
Thirdly an array of four cards representing your hand formatted like
[KD][JC][QH][AS]
representing
King of Diamonds, Jack of Clubs, Queen of Hearts, Ace of Spades
Objective:
Given the three inputs, output the best possible card to add to the cards that have been played such that it meets the following criteria:
- It takes the hand if it can, if not output the least valuable card
- It takes the hand if it can, however it will not trump your team mate unless it is unavoidable
- If it can take the hand, it does so by using the least valuable card. (If you have an ace and a queen that can win the hand, you play the queen).
- Any plays must follow suit as required by the rules at the bottom.
Output format like [JD]
Formatting
A - Ace
K - King
Q - Queen
J - Jack
T - Ten
9 - Nine
H - Hearts
D - Diamonds
S - Spades
C - Clubs
TH, 9D, JD, QH, AD, 9C, TC
Examples
In: [QD][KD][9C]
, "C"
, [AH][JH][QH][9H]
Out: 9H
Reason: As clubs are trump, the 9C is winning the hand, we are unable to take the hand so we should discard our lowest card, here the 9H
In: [QD][KD][AD]
, "H"
, [AH][JH][QH][9H]
Out: 9H
Reason: As Hearts are trump, the Ace of Diamonds is currently winning the hand, we are able to trump the hand so we should use our lowest card, here the 9H
In: [QD][KD][TD]
, "D"
, [AD][JH][QH][9D]
Out: 9D
Reason: As diamonds are trump and we are currently winning the hand, we should play the 9D because our partner currently is winning the hand, so we want to play the 9D
over the AD
In: [QH][KH][JH]
, "D"
, [AD][JD][QH][9D]
Out: QH
Reason: As Diamonds are trump our opponents are winning with the left Bower JH
We have the right bower but cannot trump him because QH was led and we must follow suit, the QH
In: [QH][KH][JH]
, "D"
, [AD][JD][QC][9D]
Out: JD
Reason: As Diamonds are trump our opponents are winning with the left Bower JH
We have the right bower and since we have no Diamonds
we can trump over him with the JD
Euchre Card Strengths
If Hearts is trump:
JH
JD
AH
KH
QH
TH
9H
See the Euchre Rules if you are unfamiliar with the strength of different cards in Euchre
Since this is Code-Golf the shortest code wins!
Good Luck and have fun!
2I think the play should be described here not with a link. – Jonathan Allan – 2016-11-15T12:49:33.667
@JonathanAllan I thought about it, but it is better described in the link. Probably not the best challenge for those who are unfamiliar with the game. Unless they want to learn on the fly. – jacksonecac – 2016-11-15T12:51:10.240
The example with
9D
as the result has hearts set as trumps (although I don't think it affects this result). – Jonathan Allan – 2016-11-15T13:02:18.217@JonathanAllan nice catch, thank you. – jacksonecac – 2016-11-15T13:04:50.397
Would it maybe be better if
10
was denoted asT
? Would make the card parsing less of a headache. – Kade – 2016-11-15T16:56:28.673Good idea, I will make the change – jacksonecac – 2016-11-15T16:57:09.110
Why take a trick that your partner has already won? – Sparr – 2018-12-11T04:31:36.970
@Sparr the 2nd-to-last test case addresses this:
In: [QH][KH][JH], "D", [AD][JD][QH][9D] Out: QH
. We play the QH because our partner already won. Although, this hand is not possible in euchre because it has the QH both in-play and in-hand. – Dave – 2018-12-11T07:11:12.177I'm more asking from a strategy standpoint. Seems like bad euchre play. – Sparr – 2018-12-11T08:32:15.427
@Sparr because the first card played was
[QH]
meaning the rest of the play is hearts by default. So you would only be able to play[QH]
because you have a hearts card so you have to play it. I think that's how this game works, at least a similar Chinese card game works this way. – HyperNeutrino – 2018-12-11T14:29:50.497I just read the examples and it seems like they match my expectations and violate the objective. I think whoever wrote this used "trump your team mate" when they meant any play over them, not just trumps? – Sparr – 2018-12-11T22:33:37.807
Would the rules be better stated as this? 1) If your team mate is winning, play the lowest ranked legal card. 2) If your team mate is losing, play the lowest ranked legal card that wins the hand if you can, otherwise play the lowest ranked legal card. – Sparr – 2018-12-11T22:35:34.213
Yes, that is a clearer and more concise description of the objective. 'Legal card' is defined as cards matching the lead suit (the suit of the first card played), or all cards if no cards in-hand match the lead suit. 'Trump' is considered a suit, and the Jack of the same color as trump is considered trump (not its actual suit). 'Lowest ranked' is defined as: Jack of trump > Jack of same color as trump > (A > K > Q > T > 9) of trump > (A > K > Q > J > T > 9 of lead suit) > all other cards. – Dave – 2018-12-12T01:24:43.950
Agreed but its been 2 years go golf something else :) – jacksonecac – 2018-12-12T01:25:52.717
1@jacksonecac thanks for the problem, I had fun with it. – Dave – 2018-12-12T01:28:30.050