Bridge Training

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 given auctionInput axis.
  • @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

ExportSignatureDescription
parseTeaching(candidate?: string) => TeachingMode | nullNarrows 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, CanonicalDealShapetypesInput and output of the function above
teaching.ts
parseTeaching("auction"); // => "auction"
parseTeaching("invalid"); // => null
parseTeaching(); // => null

isTeachingMode("hld"); // => true
isTeachingMode(42); // => false

Editor 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:

QuestionEngine 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 surfaceengine.ctx.auctionsEnabled
The learner picks the contractengine.ctx.userControlsContract
teaching.ts
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; // => false

Canonical 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:

auctionInputStored auctionStored contractStored denomination
"sequence"The moves as given (null when empty)As givenAs given
"contract"nullGiven string if it parses, else derived from the auction, else nullnull
"trump"nullnullGiven denomination, else the suit of the resolved contract, else null
nullnullnullnull

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.

teaching.ts
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)

ExportDescription
DEFAULT_AUCTION_MODE"auction"
DEFAULT_TEACH_DUMMYtrue
AUCTIONSOption groups for the mode selector: with-auction (auction, sequence) and without-auction (the ten others), with defaultValue
TEACH_MODESFlat list of the twelve modes, derived from AUCTIONS
TEACHING_MODE_VALUESThe twelve modes as readonly TeachingMode[] (matches the type exactly)
isTeachingMode(value)unknown → type guard
PEDAGOGY_GROUP_IDSWITH_DUMMY_WITH_AUCTION and WITH_DUMMY_NO_AUCTION group identifiers
PEDAGOGY_GROUPSGroup definitions with their modes, used for filtering
TeachMode, PedagogyGroupId, PedagogyValue, PedagogyGrouptypes
teaching.ts
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.