Given the trump suit and the 52 cards played across 13 tricks, determine which team won and by how many tricks above six.
Medium4SimulationImplementationGame theoryNo attempts yetTime limit8sMemory limit512 MBWhist is a game played by four players with a standard deck of playing cards. The players sit around a table in the north, east, south, and west seats. Players who sit opposite each other form a team, so there are two teams, the north-south team and the east-west team.
A standard deck holds 52 cards, and every card carries one rank and one suit. The rank gives the strength of the card and runs, from lowest to highest, 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace. The suit is the type of symbol printed on the card: spades, hearts, diamonds, or clubs. The deck contains exactly one card for every pair of a rank and a suit, which gives 52 cards.
One of the four players is the dealer. The dealer shuffles the deck and deals all the cards face down, one at a time, clockwise, starting with the player to the dealer's left. Each player receives thirteen cards. The last card dealt belongs to the dealer and is turned face up. The suit of that card is called trumps and has the special effect described below.
A deal consists of thirteen tricks. Each team tries to win more tricks than the other team. The player to the dealer's left leads the first trick by playing a card from hand, then the other three players play one card each in clockwise order. The suit of the first card played in a trick is the led suit. A player who still holds a card of the led suit has to play that suit, and may play any card otherwise. If no trump is played in a trick, the trick is won by the highest card of the led suit. If a trump is played, the trick is won by the highest trump. The winner of a trick leads the next one, and the rest of the deal is played the same way. After the thirteen tricks, the team that won more tricks scores one point for every trick in excess of six.
Given the record of a deal, write a program that reports the winning team and their score.
The input is a sequence of datasets. Each dataset describes one deal and has the following format.
Trump
CardN,1 CardN,2 ... CardN,13
CardE,1 CardE,2 ... CardE,13
CardS,1 CardS,2 ... CardS,13
CardW,1 CardW,2 ... CardW,13
Trump is the trump suit. CardN,i, CardE,i, CardS,i, and CardW,i are the cards played in the i-th trick by the north, east, south, and west players. Each card is written with two characters, the first for the rank and the second for the suit.
The rank is one of 2, 3, 4, 5, 6, 7, 8, 9, T (10), J (jack), Q (queen), K (king), A (ace). The suit is one of S (spades), H (hearts), D (diamonds), C (clubs).
Assume that the west player dealt the cards, so the north player leads the first trick. The input contains no illegal play.
The input ends with a line holding a single #. That line is not a dataset and is not processed.
For each dataset, print the winning team and their score for the deal on one line, separated by a single space. The winning team is either NS (the north-south team) or EW (the east-west team). Print no other character and no extra whitespace.
In the first dataset of the first example, the tricks are won, in order, by east, north, south, east, south, north, west, north, east, west, east, east, north.