Bridge Core
Rotation
Rotate hands, auction state, and vulnerability between players.
Import from @workspace/bridge-core/rotation.
Rotation functions move data clockwise around the table. This is used when changing the perspective (e.g., making a different player sit South) without altering the deal itself.
Hands Rotation
import { rotateHandsOnce, rotateHandsNTimes } from '@workspace/bridge-core/rotation';
// Single clockwise rotation: W→N, N→E, E→S, S→W
const rotated = rotateHandsOnce(hands);
// Rotate N times
const rotated3 = rotateHandsNTimes(hands, 3);| Function | Description |
|---|---|
rotateHandsOnce(hands) | Performs a single clockwise rotation of all four hands |
rotateHandsNTimes(hands, n) | Applies n clockwise rotations to the hands |
Auction State Rotation
Rotates both the dealer and all player assignments in the bid sequence.
import { rotateAuctionStateOnce, rotateAuctionStateNTimes } from '@workspace/bridge-core/rotation';
const rotatedAuction = rotateAuctionStateOnce(auctionState);
const rotatedAuction3 = rotateAuctionStateNTimes(auctionState, 3);| Function | Description |
|---|---|
rotateAuctionStateOnce(state) | Rotates the dealer and all bid players one position clockwise |
rotateAuctionStateNTimes(state, n) | Applies n rotations to the auction state |
Vulnerability Rotation
When hands are rotated an odd number of times, NS and EW swap positions. Vulnerability must be rotated to match.
import { rotateVulnerability, doesVulnerabilityNeedRotation } from '@workspace/bridge-core/rotation';
doesVulnerabilityNeedRotation('NS'); // true
doesVulnerabilityNeedRotation('EW'); // true
doesVulnerabilityNeedRotation('NONE'); // false
doesVulnerabilityNeedRotation('ALL'); // false
rotateVulnerability('NS'); // 'EW'
rotateVulnerability('EW'); // 'NS'
rotateVulnerability('NONE'); // 'NONE' (unchanged)
rotateVulnerability('ALL'); // 'ALL' (unchanged)| Function | Description |
|---|---|
doesVulnerabilityNeedRotation(vulnerability) | Returns true if the vulnerability is NS or EW |
rotateVulnerability(vulnerability) | Swaps NS and EW; leaves NONE and ALL unchanged |