YaCG: #3 "no elephant were harmed..."
Description:
After some days playing yacg they went to the village fast-food. gDongald, the boss, was a stranger came longtime ago from a far-far eastern country, beyond mountains and seas.
They learned yacg to him, he gave them some junk-food and they played together for a while...
Suddenly, gDongald threw furiously down his yellow-yak-tail wig and yelled " gRrr! " which means " Buaaaah! Why is the world so cruel to me ? I've got aces but never from the led suit ! ! ! ".
And all others nodded grumbling " gG! gG! gG! " which means " Oh, man! You're sooo right! ".
Rules
YaCg is a trick-taking game ie a game in which series of rounds, called "tricks", are played. At the end of a "trick" the winner of the trick "takes" it (and becomes the "trick-taker").
A standard 52-card pack is used. The cards in each suit rank from highest to lowest: A K Q J 10 9 8 7 6 5 4 3 2
.
The leader (==1st player) leads to the first trick. He may lead any card in his hand. Each other players must FOLLOW suit by playing a card of the suit led if he has one.
trump rule
A player with no card of the suit led may "discard" any card OR play a trump card ie a card of suit defined as trump at start of the game. If at least one trump card is played the trick is won by the highest trump card else the highest led suit card.
Examples
["2H","8H","KD","KH"] // --> "KD" may win IF trump is "D" else "KH" is the highest of "H" (which is led suit)
["2H","8C","JD","2S"] // --> "2S" wins IF trump is "S" else "2H" wins
Task
Code a function winnerOfTrick( cards, players, trump )
which return the name of the "trick-taker" ie the one who wins the trick.
Input
cards
is an array of card-codes of the form "RS" where :- "R" is the rank of the card ( one of
A, K, Q, J, T (for 10), 9, 8, 7, 6, 5, 4, 3 or 2
) - "S" is the *suit * of the card (one of
"H" (Hearts), "C" (Clubs), "D" (Diamonds) and "S" (Spades)
)
eg :
[ "2H", "3H", "4C", "KD", "AS" ]
- "R" is the rank of the card ( one of
players
is an array of yagc-fanatic yak-boys/girls.eg :
[ "ALgichh", "Bdobd", "Charmolg", "Dbrang", "Erming" ]
trump
is a string of the form "X" where "X" is the suit defined as trump (one of"H" (Hearts), "C" (Clubs), "D" (Diamonds) and "S" (Spades)
)
Output
- a string of the form "
Bdobd wins
".
Examples:
winnerOfTrick( ["2D", "3D", "4S"], ["GgbA", "mZoIs", "S'Lg"], "C" ) // -> "mZoIs wins" ("3D" is the highest "D" and "C" is the trump suit)
winnerOfTrick( ["2D", "2H", "2S"], ["GgbA", "mZoIs", "S'Lg"], "S" ) // -> "S'Lg wins" ("2D" is the highest "D" BUT "2S" is a trump)
winnerOfTrick( ["2D", "KH", "QH"], ["mZoIs", "GgbA", "S'Lg"], "H" ) // -> "GgbA wins" ("KH" is the highest trump)
"* gHappy gCoding ! *"
(_____)"""._ gBooo _ (><) |--* (_)>>>o / \\ ^^ " " " ^^ - - - - - - - - - - - - - - - - - - - - - - - - - - - a yak playing a trump
Similar Kata:
Stats:
Created | Jul 26, 2017 |
Published | Jul 26, 2017 |
Warriors Trained | 114 |
Total Skips | 10 |
Total Code Submissions | 252 |
Total Times Completed | 43 |
JavaScript Completions | 43 |
Total Stars | 4 |
% of votes with a positive feedback rating | 98% of 25 |
Total "Very Satisfied" Votes | 24 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |