type Board
type Board = Readonly<{ name: string; lattice: "square" | "triangle"; cells: readonly Cell[]; jumps: readonly Jump[]; }>;
Immutable hole lattice and all legal jump triples for a board.
@johnmorrisdotca/tobiishi 0.2.2 · 5 entry points · 51 exports
@johnmorrisdotca/tobiishiBoard boardOf Cell Challenge ChallengeDifficulty challengeOf ChallengePack classicEnglish classicTriangle Game gameCode gameFromCode generate generateTobiishiChallenge GoalChallenge GoalHole isGameSolved isGameStuck Jump jumpAt legalJumps makeBoard markHelped newGame pegCount rectangleBoard restart seededRandom Shape SHAPES Solution solve SQUARE_STEPS TOBIISHI_CHALLENGE_PACKS TRIANGLE_STEPS undo VERSION
type Board = Readonly<{ name: string; lattice: "square" | "triangle"; cells: readonly Cell[]; jumps: readonly Jump[]; }>;
Immutable hole lattice and all legal jump triples for a board.
boardOf(shape?: Shape): Board
A familiar lattice or a shaped outline. Shapes describe holes, never a different capture rule.
type Cell = Readonly<{ x: number; y: number }>;
A hole's stable coordinate within a board shape, independent of its drawing.
type Challenge = Readonly<{ game: Game; answer: readonly Jump[]; seed: string }>;
A starting position paired with its complete legal witness and seed.
type ChallengeDifficulty = "easy" | "medium" | "hard";
Requested witness length category; this is not a measured human rating.
challengeOf(shape: Shape, seed?: string, jumps?: number, goal?: Cell): Challenge
Generates a seeded challenge on a built-in shape, optionally fixing its final hole.
type ChallengePack = Readonly<{ title: Readonly<Record<"en" | "ja", string>>; shape: Shape; goals: readonly GoalHole[]; }>;
Curated goal choices for one supported board shape.
classicEnglish(): Challenge
Returns the classic centre-empty English game with its complete solution.
classicTriangle(): Challenge
Returns the full triangle with the apex empty and any final hole accepted.
type Game = Readonly<{ board: Board; start: readonly boolean[]; pegs: readonly boolean[]; target: number | null; history: readonly Jump[]; /** Whether a proved hint has been shown during this run. */ helped: boolean; }>;
Immutable peg position, target, move history, and assistance marker.
gameCode(game: Game): string
Versioned save: replay, rather than accepting a claimed final position.
gameFromCode(code: string): Game | null
Validates and replays a versioned save string, returning null if invalid.
generate(board: Board, seed: string, jumps?: number, goal?: number): Challenge
Grow backward from one peg. The reversed jumps are a proof, even on unusual boards.
generateTobiishiChallenge(packKey: Shape, goalId: string, difficulty: ChallengeDifficulty): GoalChallenge
Creates one fixed-goal puzzle with a complete, replayable legal answer.
type GoalChallenge = Challenge & Readonly<{ pack: Shape; packTitle: string; difficulty: ChallengeDifficulty; goal: GoalHole; }>;
Generated puzzle augmented with its pack, goal, and requested length category.
type GoalHole = Readonly<{ id: string; names: Readonly<Record<"en" | "ja", string>>; x: number; y: number }>;
Named goal hole and its localized menu labels.
isGameSolved(game: Game): boolean
Checks whether one peg remains at the required target, if any.
isGameStuck(game: Game): boolean
Checks whether no legal continuation remains before the goal is reached.
type Jump = Readonly<{ from: number; over: number; to: number }>;
A legal solitaire jump from an occupied hole over a peg to an empty hole.
jumpAt(game: Game, from: number, to: number): Game
Invalid jumps leave a game unchanged; a valid jump removes exactly one peg.
legalJumps(game: Game): Jump[]
Lists legal jumps from the current position.
makeBoard(name: string, cells: readonly Cell[], lattice?: Board["lattice"]): Board
Make a board from holes and a lattice; absent holes cannot be crossed.
markHelped(game: Game): Game
Mark an assisted run without changing pieces or history. Undo keeps this flag.
newGame(board: Board, pegs: readonly boolean[], target?: number | null): Game
Creates a validated immutable position with the given target hole, if any.
pegCount(game: Game): number
Counts pegs remaining on the board.
rectangleBoard(width: number, height: number): Board
Creates a square-lattice rectangle, including supported wide and tall boards.
restart(game: Game): Game
Restores the original peg arrangement and clears moves and assistance.
seededRandom(seed: string): () => number
Creates a deterministic pseudo-random stream from a text seed.
type Shape = "english" | "european" | "triangle" | "diamond" | "heart" | "star" | "hexagon" | "wide" | "tall";
Built-in board outlines supported by the player and challenge packs.
SHAPES: readonly Shape[]
Built-in shape names in player-menu order.
type Solution = { status: "solved" | "impossible" | "limit"; jumps: Jump[]; visited: number };
Bounded search result; limit distinguishes unfinished search from proof.
solve(game: Game, maxNodes?: number): Solution
A bounded depth-first proof search. A limit is never reported as impossibility.
SQUARE_STEPS: readonly [readonly [1, 0], readonly [-1, 0], readonly [0, 1], readonly [0, -1]]
Orthogonal direction steps used by square-lattice boards.
TOBIISHI_CHALLENGE_PACKS: Readonly<Record<Shape, Readonly<{ title: Readonly<Record<"en" | "ja", string>>; shape: Shape; goals: readonly GoalHole[]; }>>>
Named challenge pack metadata; each goal is a distinct hole with a legal witness.
TRIANGLE_STEPS: readonly [readonly [1, 0], readonly [-1, 0], readonly [0, 1], readonly [0, -1], readonly [1, 1], readonly [-1, -1]]
Six jump directions used by the triangular lattice.
undo(game: Game): Game
Returns the previous position, or the same game when history is empty.
VERSION: "0.2.2"
Current package API version.
@johnmorrisdotca/tobiishi/drawboundsOf draw escapeXml Material MATERIALS pointOf Theme THEMES
boundsOf(game: Game): { width: number; height: number; }
Returns the SVG view box size for the board.
draw(game: Game, options?: { material?: Material; theme?: Partial<Theme>; selected?: number | null; title?: string; }): string
A self-contained board drawing; no browser globals and no random SVG ids.
escapeXml(value: string): string
Escapes text for safe inclusion in XML attributes and content.
type Material = "stone" | "wood" | "glass";
Built-in board and peg palettes.
MATERIALS: readonly Material[]
Built-in palette names in player-menu order.
pointOf(game: Game, cell: number): { x: number; y: number; }
Maps a board cell index to its SVG centre point.
type Theme = { board: string; hole: string; peg: string; edge: string; accent: string };
SVG color properties that can be partially overridden by a caller.
THEMES: Record<Material, Theme>
Palette values used by the SVG renderer.
@johnmorrisdotca/tobiishi/playLanguage mount MountOptions Player STRINGS
type Language = keyof typeof STRINGS;
Supported player interface languages.
mount(host: HTMLElement, options?: MountOptions): Player
Mount one independent player. The host owns persistence through onChange and setGame.
type MountOptions = { game?: Game; challenge?: Challenge; shape?: Shape; seed?: string; challengeJumps?: number; language?: Language; material?: Material; theme?: Partial<Theme>; justBoard?: boolean; settingsHost?: HTMLElement; onChange?: (game: Game, code: string) => void; };
Initial puzzle, display choices, optional settings host, and persistence callback.
type Player = { getGame: () => Game; setGame: (game: Game) => void; destroy: () => void };
Controls for reading, replacing, or unmounting one player instance.
STRINGS: { readonly en: { readonly title: "Peg Solitaire"; readonly instructions: "Choose a peg, then an empty hole two spaces away. Jump over one peg to remove it. Leave one peg; if a hole is marked, finish there."; readonly newChallenge: "New challenge"; readonly undo: "Undo"; readonly restart: "Restart"; readonly hint: "Hint"; readonly remaining: "pegs left"; readonly won: "Solved — one peg remains!"; readonly st…
Localized English and Japanese labels used by the player.
@johnmorrisdotca/tobiishi/elementdefineTobiishi(tag?: string): void
Registers a custom element on explicit browser calls; importing this module alone is inert.
@johnmorrisdotca/tobiishi/element/defineこの日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。