Skip to the content

Toranpuトランプ

Use a deck, play eleven games with computers, solve a solitaire, or display cards in your own design.

Toranpu is Japanese for playing cards. About the name

Contents

Reference · Klondike

BestFirstGametype

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 it

import type { BestFirstGame } from "@johnmorrisdotca/toranpu/klondike";

Also exported from: @johnmorrisdotca/toranpu/freecell, @johnmorrisdotca/toranpu/spider

Definition

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;
};

Members

NameTypeDescription
candidates(table: Table) => Move[]
play(table: Table, move: Move) => Table | null
settle (optional)((table: Table) => { table: Table; moves: Move[]; }) | undefined
won(table: Table) => boolean
key(table: Table) => string
distance(table: Table) => number

Examples

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

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/toranpu 2.15.0.