/** * A BEST-FIRST SEARCH for a card game played alone, shared by FreeCell's * solver and Spider's (`freecell/solve.ts`, `spider/solve.ts`). * * The table that looks nearest to won is opened next (`distance`, the lower * the nearer), ties in the order they were found, and every table is opened * once (`key`). It gives up after a fixed number of tables, never after a * fixed time, so the same deal gets the same answer on a phone, a desk and the * server — which is what lets a seed name "the first winnable deal from here" * in every browser alike. * * `settle` is what a game does by itself after every move (FreeCell's safe * cards sent home): its moves are part of the line, so a replay of the line * makes exactly the tables the search saw. * * @example * ```ts * import type { BestFirstGame } from "@johnmorrisdotca/toranpu/klondike"; * * const value: BestFirstGame = { candidates: (at) => at < 3 ? [1] : [], play: (at, move) => at + move, won: (at) => at === 3, key: String, distance: (at) => 3 - at }; * console.log(value.won(3)); * ``` */ export type BestFirstGame = { candidates: (table: Table) => Move[]; play: (table: Table, move: Move) => Table | null; settle?: (table: Table) => { table: Table; moves: Move[]; }; won: (table: Table) => boolean; key: (table: Table) => string; distance: (table: Table) => number; }; /** * A winning line from this table — every move a replay of it makes, the * settling ones included — or null when none was found within `budget` tables. * * @param game - The current native game; applying a move returns a new state. * @param start - The initial game or state before the recorded moves. * @param budget - Limits on the solver’s search work. * @returns A winning line from this table — every move a replay of it makes, the settling ones included — or null when none was found within `budget` tables. * * @example * ```ts * import { bestFirst } from "@johnmorrisdotca/toranpu/klondike"; * * console.log(bestFirst({ candidates: (at: number) => at < 3 ? [1] : [], play: (at: number, move: number) => at + move, won: (at: number) => at === 3, key: String, distance: (at: number) => 3 - at }, 0, 20)); * ``` */ export declare function bestFirst(game: BestFirstGame, start: Table, budget: number): { moves: Move[] | null; tables: number; };