The pack
wordLadder
function wordLadder(): Pack<{ wordLadder: WordLadderApi }>
The word-ladder pack: word ladder puzzles over the english-words lists. Pure logic, so it runs headless.
Helpers
createWordLadder
function createWordLadder(options: WordLadderOptions): WordLadder
Make a ladder: a generated puzzle from seed, or the one start and goal set. Throws a RangeError for options out
of range: a set word not in the list or not reachable, a step range with no puzzle in it, a limit below par.
ladderNeighbours
function ladderNeighbours(word: string, words: WordList = englishLexicon(), moves: LadderMoves = 'change'): string[]
Every word one step from word in words (default the English lexicon) under moves (default 'change'): one
letter changed, or with 'edit' also one added or taken away. Shortest first, then alphabetical; word itself is
left out, and it need not be in the list. Empty for anything but letters.
solveLadder
function solveLadder(start: string, goal: string, words: WordList = englishLexicon(), moves: LadderMoves = 'change', avoid: Iterable<string> = []): string[] | null
A shortest ladder from start to goal in words (default the English lexicon) under moves (default 'change'),
both ends included, never through a word in avoid; null when there is none. Ties go to the alphabetically first
words, so the answer is always the same. Neither end need be in the list.
Types
LadderMoves
type LadderMoves = 'change' | 'edit'
What one step may do: 'change' one letter (the length stays), or 'edit': change, add or take away one letter.
LadderRung
interface LadderRung
One word on the ladder, and where it changed.
readonly word: string— The word, lower case.readonly changed: ReadonlyArray<number>— The positions inwordthat differ from the rung before: the changed letter, or an added one. Empty for the start word and for a step that took a letter away.
StepResult
interface StepResult
What a step did.
readonly rung: LadderRung— The rung it added.readonly phase: WordLadderView['phase']— The phase after it.readonly remaining: number | null— The fewest steps left to the goal from the new word, or null when there is no way.
WordLadder
interface WordLadder
A word ladder. Make one with createWordLadder.
observation(): WordLadderView— The ladder as it stands.check(word: string): { readonly ok: true } | Refusal— Would a step towordbe accepted now?{ ok: true }, or the refusal with a reason a player could be shown. Changes nothing.step(word: string): { readonly ok: true; readonly result: StepResult } | Refusal— Step toword. Refused, changing nothing, whencheckwould refuse it.undo(): boolean— Take back the last step. False when there is none.hint(): { readonly word: string | null; readonly remaining: number | null; readonly reason: string }— The next word on a shortest way from the last word to the goal, not using a word on the ladder again; null when there is none or the ladder is over.autoStep(): { readonly ok: true; readonly result: StepResult } | Refusal— Playhint()'s word. Refused when there is none.solve(from?: string): string[] | null— A shortest ladder to the goal, as words with both ends: from the last word avoiding the words already on the ladder (no argument), or from any word in the list (from). Null when there is no way.snapshot(): HistorySave<WordLadderMove>— The ladder as a save: the seed and the steps. Restore it into a ladder made with the same options.restore(save: HistorySave<WordLadderMove> | string): void— Replace this ladder's steps with a save. Throws, changing nothing, when the save does not replay.
WordLadderApi
type WordLadderApi = typeof rules
game.wordLadder: every function and type this pack carries, as one namespace.
WordLadderMove
type WordLadderMove = { … }
A move: one step to a word.
readonly kind: 'step'readonly word: string
WordLadderOptions
interface WordLadderOptions
How a ladder is set up. Only seed is required; the default is a four-letter puzzle of 3 to 6 steps.
seed: number— Picks the puzzle whenstartandgoaldo not set it, as an unsigned 32-bit integer.length?: number— Letters in a generated puzzle's start and goal. Default 4, or the length ofstart.minSteps?: number— Fewest steps the shortest ladder of a generated puzzle may take. Default 3.maxSteps?: number— Most steps the shortest ladder of a generated puzzle may take. Default 6.start?: string— The start word of a set puzzle; givegoalwith it. Must be in the word list.goal?: string— The goal word of a set puzzle; givestartwith it. Must be in the word list and reachable.words?: WordList— The words a step may be. Default the English lexicon.moves?: LadderMoves— What one step may do. Default'change'.limit?: number— Most steps allowed before the ladder is lost: a whole number no smaller than the puzzle's par, or Infinity (the default).attempts?: number— Start words tried when generating. Default 60.
WordLadderView
interface WordLadderView
The ladder as it stands.
readonly phase: 'playing' | 'won' | 'lost'—'playing','won'(the goal is reached) or'lost'(the step limit is used up).readonly start: string— The start word.readonly goal: string— The goal word.readonly rungs: ReadonlyArray<LadderRung>— Every word so far, the start first.readonly par: number— The fewest steps from the start to the goal.readonly remaining: number | null— The fewest steps from the last word to the goal without using a word on the ladder again; null when there is no way. 0 once won.readonly steps: number— Steps taken.readonly limit: number— Most steps allowed; Infinity for no limit.readonly moves: LadderMoves— What one step may do.


