The pack
letterBox
function letterBox(): Pack<{ letterBox: LetterBoxApi }>
The letter-box pack: letter box chain rules over the english-words lists. Pure logic, so it runs headless.
Helpers
createLetterBox
function createLetterBox(options: LetterBoxOptions): LetterBox
Make a letter box puzzle. Throws a RangeError for options out of range: fewer than 2 sides, a side of no letters, a set board with a letter twice or a character other than a letter, or no generated board in the tries allowed.
letterBoxPlayable
function letterBoxPlayable(word: string, sides: ReadonlyArray<string>): boolean
Can word be played on a board with these sides: every letter on the board, and no two letters in a row from
the same side? Case does not matter; a word with characters other than letters cannot.
Types
BoxLetter
interface BoxLetter
One letter on the board.
readonly letter: string— The letter, lower case.readonly side: number— Its side, from 0.readonly index: number— Its place on the board, from 0, side by side: the index a trace uses.readonly used: boolean— Used by a word played?
LetterBox
interface LetterBox
A letter box puzzle. Make one with createLetterBox.
observation(): LetterBoxView— The board as it stands.spell(path: ReadonlyArray<number>): string | null— What a trace spells, or null for an index off the board.check(word: string): { readonly ok: true } | Refusal— Wouldwordbe accepted now?{ ok: true }, or the refusal with a reason a player can be shown. Changes nothing.play(word: string): { readonly ok: true; readonly result: LetterBoxResult } | Refusal— Play a typed word.trace(path: ReadonlyArray<number>): { readonly ok: true; readonly result: LetterBoxResult } | Refusal— Play a traced word: board indices, side by side.undo(): boolean— Take back the last word. False when none is played.hint(): { readonly word: string; readonly remaining: number } | null— The next word of a shortest way to finish from here, and how many words that way takes from here; null when solved or no way is found.solve(): ReadonlyArray<string>— A shortest solution of the whole board, from the start. Empty when none is found within reach.words(): ReadonlyArray<string>— Every word on the list that can be played on this board, longest first.snapshot(): HistorySave<LetterBoxMove>— The game as a save: the seed and the moves. Restore it into a game made with the same options.restore(save: HistorySave<LetterBoxMove> | string): void— Replace this game's moves with a save. Throws, changing nothing, when it does not replay.
LetterBoxApi
type LetterBoxApi = typeof rules
game.letterBox: every function and type this pack carries, as one namespace.
LetterBoxMove
type LetterBoxMove = { readonly kind: 'word'; readonly word: string } | { readonly kind: 'trace'; readonly path: ReadonlyArray<number> }
A move: a word typed, or traced as board indices.
LetterBoxOptions
interface LetterBoxOptions
How a board is made. Only seed is required.
seed: number— Picks the board whenboarddoes not give it, as an unsigned 32-bit integer.sides?: number— Sides of the box. Default 4, or the set board's count. At least 2.perSide?: number— Letters on each side. Default 3, or the set board's.minLength?: number— Shortest word that counts, in letters. Default 3.maxWords?: number— The goal: solve the board in this many words or fewer. A generated board can always be solved in it. Default 5.words?: WordList— The words that count. Default the English lexicon.board?: ReadonlyArray<string>— A set board instead of a generated one: one string of letters a side (['abc', 'def', 'ghi', 'jkl']), every letter different.minPar?: number— Fewest words a generated board must need: default 2, so no single word clears it.attempts?: number— Pairs of words tried when generating. Default 400.
LetterBoxResult
interface LetterBoxResult
What a word did.
readonly word: string— The word, lower case.readonly newLetters: ReadonlyArray<string>— Letters it used for the first time, in board order.readonly solved: boolean— Is the board solved now?
LetterBoxView
interface LetterBoxView
The board as it stands.
readonly phase: 'playing' | 'solved'—'playing', or'solved'once every letter is used.readonly sides: ReadonlyArray<ReadonlyArray<string>>— Each side's letters, in order.readonly letters: ReadonlyArray<BoxLetter>— Every letter, side by side, with whether it is used.readonly used: ReadonlyArray<string>— The letters used so far, in board order.readonly left: ReadonlyArray<string>— The letters still to use, in board order.readonly words: ReadonlyArray<string>— The words played, in order.readonly start: string | null— The letter the next word must start with; null before the first word.readonly par: number | null— The fewest words that solve the board from the start, or null when none does within the solver's reach.readonly goal: number— The goal,maxWords.readonly playable: number— How many words on the list can be played on this board.


