BestFirstGame型
リファレンスの説明と例は英語です。見出しと目次は日本語です。
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.
インポート
import type { BestFirstGame } from "@johnmorrisdotca/toranpu/klondike";
ほかのエクスポート元: @johnmorrisdotca/toranpu/freecell, @johnmorrisdotca/toranpu/spider
定義
type BestFirstGame<Table, Move> = {
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;
};
メンバー
| 名前 | 型 | 説明 |
|---|---|---|
candidates | (table: Table) => Move[] | |
play | (table: Table, move: Move) => Table | null | |
settle (省略可) | ((table: Table) => { table: Table; moves: Move[]; }) | undefined | |
won | (table: Table) => boolean | |
key | (table: Table) => string | |
distance | (table: Table) => number |
例
import type { BestFirstGame } from "@johnmorrisdotca/toranpu/klondike";
const value: BestFirstGame<number, number> = { 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));true出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。