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!
9D
as the result has hearts set as trumps (although I don't think it affects this result). \$\endgroup\$