Bridge Training
Bridge Core

Play

Trick evaluation, card follow rules, and play validation.

Import from @workspace/bridge-core/play.

Trick Evaluation

import { determineTrickWinner } from '@workspace/bridge-core/play';

const trick = {
  lead: 'N',
  cards: [
    { player: 'N', card: 'SA' },
    { player: 'E', card: 'SK' },
    { player: 'S', card: 'H2' },
    { player: 'W', card: 'S3' },
  ],
  winner: 'N', // will be determined
};

determineTrickWinner(trick, 'NT'); // 'N' (Ace of Spades wins in NT)
determineTrickWinner(trick, 'H');  // 'S' (Heart trumps Spades)

Card Follow Rules

import { validateCardFollowsRules } from '@workspace/bridge-core/play';

// Check if playing H2 is legal given the current trick and hand
validateCardFollowsRules('H2', hand, trickCards, 'NT');

Functions

FunctionDescription
determineTrickWinner(trick, trump)Determines which player wins a trick given the trump suit
validateCardFollowsRules(card, hand, trick, trump)Checks if playing a card is legal (must follow suit if possible)
validateTricks(tricks, trump)Validates a sequence of tricks
extractLeadFromTricks(tricks)Extracts the suit led in the first trick
hasPlayedSuit(player, suit, tricks)Checks if a player has played a specific suit in any trick

On this page