Factories
Compact-string factories that build hands, auctions, contracts, plays and whole boards for seeds and tests.
Import from @workspace/bridge/factories. The string factories parse a terse string into a domain value and throw an Error on malformed input. They are the primitives the testing builders wrap; reach for them directly when a one-liner is enough.
Hands
| Function | Signature | Description |
|---|---|---|
createHands | (input: HandsInput) => HandsData<string> | Builds four hands. Omitted players receive the remaining cards deterministically: suits S to C, ranks descending, dealt round-robin. Throws on a duplicate card. |
HandsInput is Partial<Record<Player, string>> of compact hand strings.
const hands: HandsData<string> = createHands({
N: "AKQ2.KQ3.A54.K32",
S: "T654.JT9.KJ6.A76",
});
// E and W receive the remaining 26 cards deterministicallyAuction
createAuction(str: string, options?: AuctionOptions): Auction parses space-separated calls (P, D/Dbl, R/Rdbl accepted) from options.dealer, South by default; Alert flags the previous call. Random auctions are test fixtures: createRandomAuction lives in the testing toolkit.
AuctionOptions
Prop
Type
Board
createBoardGame(input: BoardGameInput): BoardGameResult composes the factories above and derives the analysis, the contract and the declarer. hands takes two compact hands for North and South, or four for N, E, S, W, separated by " / ". Without auction, the declarer defaults to South and contract is null. The vulnerability, scoring and teaching fields are accepted but not read: they do not appear in the result.
BoardGameInput
Prop
Type
BoardGameResult
Prop
Type
const board: BoardGameResult = createBoardGame({
hands: "AKJ52.AKT84.7.K3 / Q74.QJ73.A52.J96",
auction: "1H P 2H P 4H P P P",
play: "SA S4 S3 S6",
dealer: "S",
});
board.contract; // { level: 4, suit: "H", doubled: "none" }
board.declarer; // "S"
board.analysis.N.points; // HCP of North