Teaching
Public teaching helpers — mode parsing and canonical deal shape — the engine flags that replace mode predicates, and the teaching constants.
Teaching logic lives in two sub-paths:
@workspace/bridge/teaching— context-free functions: parsing a stored mode, and normalising a deal for a givenauctionInputaxis.@workspace/bridge/constants— the mode catalogue, defaults and pedagogy groups.
The TeachingMode type itself is exported from @workspace/bridge/types; the per-mode rules are on Game Modes. There is no teaching module on the engine: mode-derived flags are read from engine.ctx.
@workspace/bridge/teaching
| Export | Signature | Description |
|---|---|---|
parseTeaching | (candidate?: string) => TeachingMode | null | Narrows a string to a valid mode; null otherwise (and for no argument) |
canonicalizeDealShapeForMode | <TMove extends { bid: string }>(input: DealShapeInput<TMove>) => CanonicalDealShape<TMove> | Write-side normalisation of auction / contract / denomination for the active auctionInput |
DealShapeInput, CanonicalDealShape | types | Input and output of the function above |
parseTeaching("auction"); // => "auction"
parseTeaching("invalid"); // => null
parseTeaching(); // => null
isTeachingMode("hld"); // => true
isTeachingMode(42); // => falseEditor input per mode
What the editor captures for a mode is a property of the mode, so it is read from the engine built for that mode rather than from a predicate taking the mode:
| Question | Engine read |
|---|---|
Full bid sequence (auction, sequence) | engine.ctx.auctionInput === "sequence" |
Trump picker (show-trump, show-trump-goal) | engine.ctx.auctionInput === "trump" |
Contract selector (show-contract, h, hd, hld, tht) | engine.ctx.auctionInput === "contract" |
| Any auction surface | engine.ctx.auctionsEnabled |
| The learner picks the contract | engine.ctx.userControlsContract |
const showTrump = createBridgeEngine(
createBridgeContext({ teachingMode: "show-trump" })
);
showTrump.ctx.auctionInput === "sequence"; // => false (no bid sequence to capture)
showTrump.ctx.auctionInput === "trump"; // => true (trump picker)
showTrump.ctx.userControlsContract; // => falseCanonical deal shape
Deals are stored with only the auction concept the mode owns. canonicalizeDealShapeForMode takes the engine's auctionInput axis plus whatever the form captured and returns the shape to persist:
auctionInput | Stored auction | Stored contract | Stored denomination |
|---|---|---|---|
"sequence" | The moves as given (null when empty) | As given | As given |
"contract" | null | Given string if it parses, else derived from the auction, else null | null |
"trump" | null | null | Given denomination, else the suit of the resolved contract, else null |
null | null | null | null |
DealShapeInput<TMove> has auctionInput: AuctionInput, auction: { first: Player; moves: readonly TMove[] } | null, contract: string | null, denomination: Denomination | null. CanonicalDealShape<TMove> has the same three data fields with a mutable moves array.
const engine = createBridgeEngine(
createBridgeContext({ teachingMode: "show-trump" })
);
canonicalizeDealShapeForMode({
auctionInput: engine.ctx.auctionInput, // "trump" for show-trump
auction: { first: "N", moves: [{ bid: "1S" }, { bid: "Pass" }] },
contract: "4S",
denomination: null,
});
// => { auction: null, contract: null, denomination: "S" }Teaching constants (@workspace/bridge/constants)
| Export | Description |
|---|---|
DEFAULT_AUCTION_MODE | "auction" |
DEFAULT_TEACH_DUMMY | true |
AUCTIONS | Option groups for the mode selector: with-auction (auction, sequence) and without-auction (the ten others), with defaultValue |
TEACH_MODES | Flat list of the twelve modes, derived from AUCTIONS |
TEACHING_MODE_VALUES | The twelve modes as readonly TeachingMode[] (matches the type exactly) |
isTeachingMode(value) | unknown → type guard |
PEDAGOGY_GROUP_IDS | WITH_DUMMY_WITH_AUCTION and WITH_DUMMY_NO_AUCTION group identifiers |
PEDAGOGY_GROUPS | Group definitions with their modes, used for filtering |
TeachMode, PedagogyGroupId, PedagogyValue, PedagogyGroup | types |
DEFAULT_AUCTION_MODE; // => "auction"
AUCTIONS.options.map((group) => group.id); // => ["with-auction", "without-auction"]
TEACHING_MODE_VALUES.length; // => 12
PEDAGOGY_GROUPS.map((group) => group.id);
// => ["with-dummy-with-auction", "with-dummy-no-auction"]PedagogyGroup
Prop
Type
PedagogyValue is PedagogyGroupId | TeachingMode: a filter can target a whole group or one mode.