Bridge Core
Constants
Reusable constants for suits, ranks, players, bids, vulnerability, scoring, board numbering, and defaults.
Import from @workspace/bridge-core/constants.
Cards
Suits & Ranks
import { SUITS, SUIT, RANKS, NO_TRUMP, SUIT_SYMBOLS } from '@workspace/bridge-core/constants';
SUITS; // ['S', 'H', 'D', 'C']
SUIT.spades; // 'S'
SUIT.hearts; // 'H'
RANKS; // ['A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2']
NO_TRUMP; // 'NT'
SUIT_SYMBOLS; // { S: '♠', H: '♥', D: '♦', C: '♣', NT: 'SA' }Bid Constants
import { BID_LEVELS, BID_SUITS } from '@workspace/bridge-core/constants';
BID_LEVELS; // [1, 2, 3, 4, 5, 6, 7]
BID_SUITS; // ['C', 'D', 'H', 'S', 'NT']Special Bids & Counter Status
import { SPECIAL_BID, COUNTER_STATUS } from '@workspace/bridge-core/constants';
SPECIAL_BID.pass; // 'Pass'
SPECIAL_BID.double; // 'X'
SPECIAL_BID.redouble; // 'XX'
SPECIAL_BID.alert; // 'Alert'
COUNTER_STATUS.none; // 'none'
COUNTER_STATUS.doubled; // 'X'
COUNTER_STATUS.redoubled; // 'XX'Players
import { PLAYER, PLAYERS, PLAYERS_ORDER, PARTNERSHIP, LEAD_PLAYER, DECLARER_PLAYER } from '@workspace/bridge-core/constants';
PLAYER.north; // 'N'
PLAYER.east; // 'E'
PLAYER.south; // 'S'
PLAYER.west; // 'W'
PLAYERS; // ['N', 'E', 'S', 'W'] (clockwise order)
PLAYERS_ORDER; // Alias for PLAYERS
PARTNERSHIP.NS; // 'NS'
PARTNERSHIP.EW; // 'EW'
LEAD_PLAYER; // 'W' (default opening leader)
DECLARER_PLAYER; // 'S' (default declarer)Vulnerability
import { VULNERABILITY, VULNERABILITIES, DEFAULT_VULNERABILITY } from '@workspace/bridge-core/constants';
VULNERABILITY.none; // 'NONE'
VULNERABILITY.NS; // 'NS'
VULNERABILITY.EW; // 'EW'
VULNERABILITY.all; // 'ALL'
VULNERABILITY.unset; // 'UNSET'
VULNERABILITIES; // ['NONE', 'NS', 'EW', 'ALL']
DEFAULT_VULNERABILITY; // 'UNSET'Scoring
import { SCORING, SCORING_MODES, DEFAULT_SCORING_MODE } from '@workspace/bridge-core/constants';
SCORING.unset; // 'UNSET'
SCORING.TPP; // 'TPP' (Total Point Pairs)
SCORING.IMP; // 'IMP' (International Match Points)
DEFAULT_SCORING_MODE; // 'UNSET'
SCORING_MODES.defaultValue; // 'UNSET'
SCORING_MODES.options; // [{ value: 'UNSET' }, { value: 'TPP' }, { value: 'IMP' }]Defaults
import {
DEFAULT_DEALER,
DEFAULT_AUCTION_SEQUENCE,
DEFAULT_AUCTION_STATE,
DEFAULT_PLAY_STATE,
DEFAULT_LOCALE,
DEFAULT_TEACHING_MODE,
DEFAULT_BRIDGE_CONTEXT,
UNSET,
} from '@workspace/bridge-core/constants';
DEFAULT_DEALER; // 'N'
DEFAULT_AUCTION_SEQUENCE; // []
DEFAULT_AUCTION_STATE; // { sequence: [], dealer: 'N', lastBid: null }
DEFAULT_PLAY_STATE; // { tricks: [], formattedText: '' }
DEFAULT_LOCALE; // 'en'
DEFAULT_TEACHING_MODE; // 'auction'
DEFAULT_BRIDGE_CONTEXT; // { teachingMode: 'auction', locale: 'en' }
UNSET; // 'UNSET' (sentinel for undefined state)Locales
import { LOCALES, parseLocale } from '@workspace/bridge-core/constants';
LOCALES; // ['en', 'fr', 'es', 'ca', 'de', 'pt', 'el', 'nl', 'sv', 'pl']
parseLocale('fr'); // 'fr'
parseLocale('invalid'); // 'en' (fallback)
parseLocale(null, 'fr'); // 'fr' (custom fallback)Board Numbering
Standard bridge board numbering follows the Laws of Bridge. The dealer and vulnerability cycle through a 16-board pattern.
import {
dealerForBoard,
vulnerabilityForBoard,
boardNumberForDealerAndVulnerability,
BOARD_VULNERABILITY_CYCLE,
} from '@workspace/bridge-core/constants';
dealerForBoard(1); // 'N'
dealerForBoard(2); // 'E'
dealerForBoard(5); // 'N' (cycles every 4)
vulnerabilityForBoard(1); // 'None'
vulnerabilityForBoard(2); // 'NS'
vulnerabilityForBoard(4); // 'All'
boardNumberForDealerAndVulnerability('N', 'NONE'); // 1
boardNumberForDealerAndVulnerability('E', 'NS'); // 2
boardNumberForDealerAndVulnerability('N', 'UNSET'); // undefined| Function | Description |
|---|---|
dealerForBoard(boardNumber) | Returns the dealer (N, E, S, W) for a board number |
vulnerabilityForBoard(boardNumber) | Returns the PBN vulnerability label for a board number |
boardNumberForDealerAndVulnerability(dealer, vulnerability) | Returns the board number (1-16) for a dealer/vulnerability pair |
Utility Functions
mapSuitRecord
Creates a Record<Suit, T> from a mapper function.
import { mapSuitRecord } from '@workspace/bridge-core/constants';
const counts = mapSuitRecord((suit) => 0);
// { S: 0, H: 0, D: 0, C: 0 }mapPlayerRecord
Creates a Record<Player, T> from a mapper function.
import { mapPlayerRecord } from '@workspace/bridge-core/constants';
const scores = mapPlayerRecord((player) => 0);
// { N: 0, E: 0, S: 0, W: 0 }Core Config
Game variant configurations are available via the constants/* wildcard export.
import {
DEFAULT_CORE_CONFIG,
PETIT_BRIDGE_CONFIG,
NO_DUMMY_CONFIG,
MINIBRIDGE_CONFIG,
MINIBRIDGE_HLD_CONFIG,
getCoreConfigForMode,
} from '@workspace/bridge-core/constants/core-config';
DEFAULT_CORE_CONFIG; // 13 cards, all ranks, classic variant
PETIT_BRIDGE_CONFIG; // 10 cards, no auctions
NO_DUMMY_CONFIG; // 13 cards, no auctions, hidden dummy
MINIBRIDGE_CONFIG; // 13 cards, NT bids only
MINIBRIDGE_HLD_CONFIG; // 13 cards, contract chosen by creator
getCoreConfigForMode('petit-bridge'); // PETIT_BRIDGE_CONFIG
getCoreConfigForMode('auction'); // DEFAULT_CORE_CONFIG
getCoreConfigForMode(undefined); // DEFAULT_CORE_CONFIG| Config | Cards | Auctions | Notes |
|---|---|---|---|
DEFAULT_CORE_CONFIG | 13 | Full | Standard bridge |
PETIT_BRIDGE_CONFIG | 10 | Disabled | Simplified variant |
NO_DUMMY_CONFIG | 13 | Disabled | Hidden dummy |
MINIBRIDGE_CONFIG | 13 | NT only | Minibridge H |
MINIBRIDGE_HLD_CONFIG | 13 | Contract mode | Minibridge HD/HLD |