Trick-Taking Round
MediumOnline Assessment
Score a round of a four-player trick-taking card game in which every player follows a fixed plan.
Four players sit in seats 0, 1, 2, 3; play passes from seat s to seat (s + 1) % 4. Each card is a two-character string: a rank from 7 8 9 T J Q K A (lowest to highest in that order) followed by a suit from C D H S, such as TH or AS. Every player holds the same number of cards, and hands[s] lists seat s's cards in the order the player prefers to play them.
The round is a sequence of tricks until the hands are empty. In a trick every player plays exactly one card:
- The leader (seat
leaderfor the first trick) plays the first card still in their hand. Its suit is the led suit. - The other players follow in seat order. A player who still holds a card of the led suit must play the first such card in their list. A player with none plays the first card still in their hand, whatever its suit.
- Winning: if any card of the trump suit was played, the highest trump wins. Otherwise the highest card of the led suit wins. Cards of any other suit never win. All cards in a trick are distinct, so there are no ties.
- The winner leads the next trick.
Scoring: the winner of a trick collects the card points of its four cards: A = 11, T = 10, K = 4, Q = 3, J = 2, and 0 for 9, 8, 7. The winner of the last trick also gets a bonus of 10.
Input: hands, four lists of cards of equal length; trump, one of "C", "D", "H", "S", or "N" meaning there is no trump suit; leader, the seat that leads the first trick.
Output: a list of four integers, the total points collected by each seat.
Example 1
- Input:
- [[["AS","KD","7C"],["7S","8D","QH"],["8H","9D","TS"],["JC","QS","AD"]],"H",0]
- Output:
- [24,15,0,15]
- Explanation
- Trump is hearts and seat 0 leads. Trick 1: AS leads; seat 1 plays 7S, seat 2 must play TS even though 8H comes first in its list, and seat 3 must play QS rather than JC. No trump appears, so AS wins: 11 + 10 + 3 = 24 points for seat 0. Trick 2: KD leads; seats 1, 2, 3 follow with 8D, 9D, AD, and AD (seat 3) wins 15 points. Trick 3: seat 3 leads JC; seat 0 follows with 7C, but seats 1 and 2 hold no club and discard QH and 8H, both trumps. The higher trump QH wins: 2 + 3 = 5 plus the last-trick bonus 10, so seat 1 gets 15.
Example 2
- Input:
- [[["AH","7C"],["9D","TC"],["KS","QC"],["JS","8H"]],"N",2]
- Output:
- [0,0,40,0]
- Explanation
- There is no trump. Seat 2 leads KS; seat 3 follows with JS; seats 0 and 1 hold no spade and discard AH and 9D. Discards never win, so KS takes 4 + 2 + 11 = 17 points for seat 2 even though AH is the highest card on the table. Seat 2 then leads QC; seat 3 discards 8H, seat 0 follows with 7C and seat 1 with TC. TC is the highest club, so seat 1 takes 3 + 10 = 13 points plus the last-trick bonus of 10.
Example 3
- Input:
- [[["8H","AD","TC"],["JD","KH","7D"],["TD","AH","8S"],["7H","QD","9C"]],"D",3]
- Output:
- [26,20,15,0]
- Explanation
- Diamonds are trump and seat 3 leads. Trick 1: 7H leads; seat 0 plays 8H; seat 1 holds both JD and KH but must follow suit with KH (the first heart in its list); seat 2 plays AH. No trump was played, so AH wins 15 points for seat 2. Trick 2: seat 2 leads TD, a trump, so the led suit is the trump suit and players follow with QD, AD and JD; AD wins 26 points for seat 0. Trick 3: seat 0 leads TC; seat 1 cuts with 7D, seat 2 discards 8S, seat 3 follows with 9C. The lone trump wins: 10 + 10 bonus = 20 for seat 1.
Constraints
- hands has exactly 4 lists, each with the same length k, 1 ≤ k ≤ 8
- all 4k cards are distinct; each is a rank in 789TJQKA followed by a suit in CDHS
- trump is one of "C", "D", "H", "S", "N"
- 0 ≤ leader ≤ 3