Bridge Core
Auction
Bidding, contracts, and auction state management.
Naming Convention
Auction = the complete sequence of bids for a deal (domain entity). Bid = an individual bid/call. Bidding = UI/process (used in bridge-react, not here).
Import from @workspace/bridge-core/auction.
Bid Parsing
Type Guards
import { isBid, isBidLevel, isBidSuit, isRegularBid, isSpecialBid } from '@workspace/bridge-core/auction';
isBid('1H'); // true
isRegularBid('3NT'); // true
isSpecialBid('Pass'); // true
isBidLevel('4'); // true
isBidSuit('NT'); // trueParsing Functions
import { parseBid, splitBid, parseBidLevel, parseBidSuit } from '@workspace/bridge-core/auction';
parseBid('3NT'); // '3NT' (typed as Bid)
parseBid('Pass'); // 'Pass' (typed as Bid)
parseBid('1Z'); // null
splitBid('3NT'); // { level: 3, suit: 'NT' }
splitBid('Pass'); // nullContract Calculation
import { calculateContract } from '@workspace/bridge-core/auction';
// Returns a discriminated result with type 'confirmed' or 'candidate', or null
const result = calculateContract(sequence);
if (result?.type === 'confirmed') {
// Auction is complete — result.value is the final contract
}
if (result?.type === 'candidate') {
// Auction still in progress — result.value is the inferred contract
}Related Types
Prop
Type
Helper Functions
| Function | Description |
|---|---|
getLastEffectiveBid(sequence) | Finds the last regular (level+suit) bid in the sequence |
getInAuctionFirstBidOf(sequence, suit, team) | Finds the first bid of a suit by a partnership |
getDeclarer(auctionState) | Determines the declarer from the auction state |
Auction State
import { createInitialAuctionState, addBidToSequence, closeAuction } from '@workspace/bridge-core/auction';
let state = createInitialAuctionState({ dealer: 'N' });
state = addBidToSequence(state, '1H');
state = addBidToSequence(state, 'Pass');
state = addBidToSequence(state, '2H');
state = closeAuction(state); // Adds closing passes| Function | Description |
|---|---|
createInitialAuctionState(partial?) | Creates a fresh auction state |
addBidToSequence(state, bid, alertText?) | Adds a bid to the sequence |
rotateDealer(state) | Rotates the dealer to the next player |
setDealerPlayer(state, player) | Sets a specific dealer and reassigns players |
rotateToDeclarer(state, target) | Rotates so the declarer sits at the target position |
closeAuction(state) | Adds the necessary closing passes |
Validation
import { isValidBid, isAuctionComplete, isDoubleable } from '@workspace/bridge-core/auction';
isValidBid('2S', sequence, currentPlayer); // Can this bid be made?
isAuctionComplete(sequence); // Did the auction end with 3 passes?
isDoubleable(sequence, currentPlayer); // Can the current player double?| Function | Description |
|---|---|
isValidBid(bid, sequence, player) | Checks if a bid is legal in the current auction state |
isAuctionComplete(sequence) | Whether the auction ended (3 consecutive passes after a regular bid) |
isAuctionPassedOut(sequence) | Whether all 4 players passed (no contract) |
isAuctionCloseable(sequence) | Whether the auction can be closed (returns passes needed) |
isDoubleable(sequence, player) | Whether the current player can double |
isRedoubleable(sequence, player) | Whether the current player can redouble |
isBidAPass(bid) | Whether a bid is a pass |
Contract Level
import { determineContractLevel, isGameContract } from '@workspace/bridge-core/auction';
determineContractLevel(contract); // 'partial' | 'game' | 'small_slam' | 'grand_slam'
isGameContract(contract); // true for 3NT, 4H, 4S, 5C, 5D and aboveUtility Functions
| Function | Description |
|---|---|
flattenAuction(auction) | Flattens an Auction (by-player) into a BidInfo sequence |
flattenAuctionToArray(auction) | Flattens an Auction into a string array |
getCounterStatus(sequence) | Gets the current double/redouble status |
determineOpener(sequence) | Finds the first non-pass bidder |