Bridge Core
Player
Player navigation, rotation, and partnerships.
Import from @workspace/bridge-core/player.
Navigation
import { getNextPlayer, getCurrentPlayer, getPlayersFromDealer } from '@workspace/bridge-core/player';
getNextPlayer('N'); // 'E' (clockwise)
getCurrentPlayer('N', 3); // Player after 3 bids from North
getPlayersFromDealer('N'); // ['N', 'E', 'S', 'W']
getPlayersInTrickOrder('E'); // ['E', 'S', 'W', 'N']| Function | Description |
|---|---|
isPlayer(value) | Type guard — checks if a string is a valid Player |
getNextPlayer(player) | Returns the next player clockwise |
getCurrentPlayer(dealer, n) | Returns the player after n positions from dealer |
getPlayersFromDealer(dealer) | Returns all 4 players in order starting from dealer |
getPlayersInTrickOrder(lead) | Returns all 4 players in trick play order |
Rotation
import { rotatePlayer, rotatePlayerNTimes, getRotationCountToTarget } from '@workspace/bridge-core/player';
rotatePlayer('N'); // 'E'
rotatePlayerCounterClockwise('E'); // 'N'
rotatePlayerNTimes('N', 2); // 'S'
getRotationCountToTarget('N', 'W'); // 3| Function | Description |
|---|---|
rotatePlayer(player) | Rotates one position clockwise |
rotatePlayerCounterClockwise(player) | Rotates one position counter-clockwise |
rotatePlayerNTimes(player, n) | Rotates n positions clockwise |
getRotationCountToTarget(from, to) | Number of clockwise rotations needed |
Partnerships
import { getPartnership, getPlayerSide } from '@workspace/bridge-core/player';
getPartnership('N'); // 'NS'
getPartnership('E'); // 'EW'| Function | Description |
|---|---|
getPartnership(player) | Returns "NS" or "EW" |
getPlayerSide(player) | Returns "attack" or "defense" |