The pack
wordChain
function wordChain(): Pack<{ wordChain: WordChainApi }>
The word-chain pack: word chain rules over the english-words lists. Pure logic, so it runs headless.
Helpers
createWordChain
function createWordChain(options: WordChainOptions): WordChain
Start a game. Throws a RangeError for options out of range: no players or more than 8, a name repeated, empty or over 40 characters, a bot seat that is not a player, a link, minimum length, clock or lives that is not a number of the right kind, a start that is not letters, or a word list with no word long enough.
Types
ChainDifficulty
type ChainDifficulty = 'easy' | 'medium' | 'hard'
How a computer player plays: easy short words and sometimes stumped, medium any word, hard words that leave few answers.
ChainEntry
interface ChainEntry
One word in the chain.
readonly word: string— The word, lower case.readonly player: number— The seat that played it.readonly points: number— Points it scored: a point a letter.
ChainLink
type ChainLink = 'last' | 'last-two' | number
How a word links to the one before: its first letters are the last 1 ('last'), 2 ('last-two') or n letters before.
ChainPlayer
interface ChainPlayer
One player as the game stands.
readonly name: string— The player's name.readonly bot: boolean— Played by the computer?readonly lives: number— Lives left; Infinity for no limit.readonly out: boolean— Out of the game (no lives left)?readonly score: number— Points scored: a point a letter.readonly words: number— Words played.
ChainResult
type ChainResult = | { readonly kind: 'word'; readonly player: number; readonly word: string; readonly points: number; readonly required: string } | { readonly kind: 'pass' | 'timeout' | 'stumped'; readonly player: number; readonly lives: number; readonly out: boolean; readonly required: string } | { readonly kind: 'time' }
What a move did.
WordChain
interface WordChain
A game of word chains. Make one with createWordChain.
observation(): WordChainView— The game as it stands.check(word: string, player?: number): { readonly ok: true } | Refusal— Wouldwordbe accepted fromplayer(default the current seat) now?{ ok: true }or the refusal. Changes nothing.play(word: string, player?: number): { readonly ok: true; readonly result: ChainResult } | Refusal— Play a word forplayer(default the current seat).pass(player?: number): { readonly ok: true; readonly result: ChainResult } | Refusal— Pass the turn forplayer(default the current seat), losing a life.advance(seconds: number): ReadonlyArray<ChainResult>— Letsecondsof game time pass: a turn whose time runs out costs its player a life and passes. Returns what happened, oldest first.autoStep(): { readonly ok: true; readonly result: ChainResult } | Refusal— The computer plays the current seat's turn by its difficulty: a word, or stumped (a pass). Refused when the game is over.hint(): string | null— A word the current seat could play now, the shortest (then alphabetical); null when there is none or the game is over.undo(): boolean— Take back the last word or pass (time is not given back). False when there is none.snapshot(): HistorySave<WordChainMove>— The game as a save: the seed and the moves. Restore it into a game made with the same options.restore(save: HistorySave<WordChainMove> | string): void— Replace this game with a save. Throws, changing nothing, when it does not replay.
WordChainApi
type WordChainApi = typeof rules
game.wordChain: every function and type this pack carries, as one namespace.
WordChainMove
type WordChainMove = | { readonly kind: 'word'; readonly word: string; readonly player?: number } | { readonly kind: 'pass'; readonly player?: number } | { readonly kind: 'bot' } | { readonly kind: 'advance'; readonly seconds: number }
A move. player is the seat that means to make it; a move by anyone else is refused. Without it, the current seat's.
WordChainOptions
interface WordChainOptions
How a game is set up. Only seed is required.
seed: number— Picks the start letter and the computer players' choices, as an unsigned 32-bit integer.players?: ReadonlyArray<string>— The players' names, 1 to 8, each at most 40 characters. Default['You', 'Computer']. One player is a solo "how long a chain" game.bots?: ReadonlyArray<number>— The seats the computer plays, by index. Default[1]with the default players, else none.difficulty?: ChainDifficulty— How the computer plays. Default'medium'.link?: ChainLink— How a word links to the one before. Default'last'.minLength?: number— Shortest word that counts, in letters. Default 3.words?: WordList | ReadonlyArray<string>— The words that count: a word list or an array. Default the English lexicon; a themed list makes a category game.timePerTurn?: number— Seconds for each turn; Infinity for no clock. Default 15.lives?: number— Lives each player starts with; a player with none is out. A whole number of 1 or more, or Infinity. Default 3.startLetter?: string— The letters the first word must start with. Default a seeded letter that starts many words.
WordChainView
interface WordChainView
The game as it stands.
readonly phase: 'playing' | 'over'—'playing'or'over'.readonly players: ReadonlyArray<ChainPlayer>— Every player, by seat.readonly current: number— The seat whose turn it is; -1 once the game is over.readonly required: string— The letters the next word must start with, lower case.readonly link: number— How many letters link a word to the one before.readonly minLength: number— Shortest word that counts.readonly timeLeft: number— Seconds left in this turn; Infinity with no clock.readonly timePerTurn: number— Seconds a turn has; Infinity with no clock.readonly chain: ReadonlyArray<ChainEntry>— The words played, oldest first.readonly answersLeft: number— How many words not yet played start withrequired: 0 is a dead end.readonly winners: ReadonlyArray<number>— Once the game is over, the seats still in it (in a solo game, none); empty while playing.readonly turns: number— Turns taken: words, passes and timeouts.


