Bridge Core
Overview
Core bridge game rules, types, and utilities.
@workspace/bridge-core is the shared package for bridge domain logic. Its only runtime dependency is zod (for validation schemas); all other code is pure functions for game rules, type definitions, parsers, and validation.
Quick Start
import { createBridgeEngine } from '@workspace/bridge-core';
const engine = createBridgeEngine({ teachingMode: 'auction', locale: 'fr' });
// Use the engine modules
engine.hands.areComplete(hands);
engine.auction.calculateContract(sequence);
engine.notation.parseRanks("RDV"); // ["K", "Q", "J"]
engine.teaching.areAuctionsEnabled(auctionMode, teachDummy);Sub-path Exports
The package exposes granular sub-path exports for tree-shaking:
| Import Path | Description |
|---|---|
@workspace/bridge-core | Engine factory + all types |
@workspace/bridge-core/engine | BridgeEngine factory and config types |
@workspace/bridge-core/constants | Game constants, defaults, and teaching mode constants |
@workspace/bridge-core/factories | Board game factories |
@workspace/bridge-core/types | All TypeScript type definitions |
@workspace/bridge-core/errors | Error types and factories |
@workspace/bridge-core/pbn | PBN file parser and serializer |
@workspace/bridge-core/schemas/* | Zod validation schemas |
@workspace/bridge-core/utils/player | Player navigation, rotation, partnerships |
@workspace/bridge-core/utils/card | Card parsing, type guards, sorting |
@workspace/bridge-core/utils/auction | Bidding, contracts, auction state |
@workspace/bridge-core/utils/hands | Hand queries, transforms, analysis |
@workspace/bridge-core/utils/play | Trick evaluation, card follow rules |
@workspace/bridge-core/utils/notation | Locale-aware rank parsing, formatting, suit mappings |
@workspace/bridge-core/utils/teaching | Teaching logic (pure functions) |
@workspace/bridge-core/utils/rotation | Deal/hands/auction rotation |
@workspace/bridge-core/utils/format | Display formatting |
@workspace/bridge-core/utils/validation | Full deal validation |
Architecture
The package is organized in layers:
- Foundation — Types, constants, errors
- Primitives — Player, card, format (stateless utilities)
- Domain — Auction, hands, play, teaching (game rules)
- Cross-cutting — Rotation, validation, schemas, utils
- Integration — Engine (composes all modules via
BridgeContext)
Package Structure
auction-contract.ts
auction-state.ts
auction-validation.ts
bid-parsing.ts
contract-level.ts
flattenAuction.ts
index.ts
required-tricks.ts
card-parsing.ts
card-sort.ts
index.ts
bids.ts
board-numbering.ts
book.ts
cards.ts
core-config.ts
defaults.ts
index.ts
locale.ts
pbn.ts
players.ts
result.ts
scoring.ts
teaching.ts
unset.ts
vulnerability.ts
engine.ts
index.ts
types.ts
auction-module.ts
constants-module.ts
context-module.ts
format-module.ts
hands-module.ts
notation-module.ts
parse-module.ts
pbn-module.ts
play-module.ts
player-module.ts
rotation-module.ts
schemas-module.ts
stats-module.ts
validation-module.ts
factories.ts
index.ts
pbn.ts
types.ts
create-auction.ts
create-board-game.ts
create-contract.ts
create-hands.ts
create-play.ts
create-random-auction.ts
index.ts
types.ts
contract.ts
hands-analysis.ts
hands-converts.ts
hands-distribution.ts
hands-queries.ts
hands-transforms.ts
hands-validation.ts
index.ts
index.ts
serialize-deal-to-lin.ts
format-ranks.ts
index.ts
parse-ranks.ts
rank-formatters.ts
rank-mappings.ts
suit-mappings.ts
types.ts
parseContract.ts
parseScoring.ts
parseVulnerability.ts
convert-deal-to-pbn-deal.ts
convert-pbn-deal.ts
create-empty-deal.ts
detect-deal-comments.ts
dup-to-pbn.ts
encoding.ts
handle-pbn-data.ts
parse-pbn-file.ts
parser-state.ts
pbn-notes.ts
pbn-tokenizer.ts
pbn.ts
preprocess-pbn-comment.ts
serialize-pbn-file.ts
utils.ts
parse-contract.ts
parse-player-tag.ts
parse-player.ts
parse-result.ts
parse-scoring.ts
parse-teaching.ts
parse-vulnerability.ts
schema.ts
format-contract.ts
format-scoring.ts
format-vulnerability.ts
parse-contract.ts
parse-pbn-auction.ts
parse-pbn-play.ts
serialize-auction.ts
serialize-comment.ts
serialize-hand.ts
serialize-header.ts
serialize-play.ts
serialize-tags.ts
index.ts
play-queries.ts
play-tricks.ts
index.ts
player-navigation.ts
player-rotation.ts
player-team.ts
index.ts
rotation-comments.ts
rotation-data.ts
rotation-deal.ts
rotation-vulnerability.ts
auction.ts
bid.ts
card.ts
deal.ts
game-params.ts
hands.ts
play.ts
player.ts
scoring.ts
teach-params.ts
vulnerability.ts
index.ts
parse-teaching.ts
teaching-logic.ts
index.ts
make-deal.ts
Analysis.ts
Auction.ts
Bid.ts
Config.ts
Contract.ts
Deal.ts
Hands.ts
Locale.ts
PBN.ts
Play.ts
Player.ts
Scoring.ts
TeachingMode.ts
Vulnerability.ts
index.ts
auction.ts
card.ts
computeHCP.ts
format.ts
hands.ts
handsToPBN.ts
index.ts
notation.ts
play.ts
player.ts
rotation.ts
scoring.ts
seededRandom.ts
teaching.ts
validation.ts
vulnerability.ts
deal-validation.ts
validation.ts