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 · Gin Rummy

GIN_RUMMY_RULESconstant

Gin Rummy as one CardGameRules: everything a table asks of the game.

Import it

import { GIN_RUMMY_RULES } from "@johnmorrisdotca/toranpu/gin-rummy";

Definition

const GIN_RUMMY_RULES: CardGameRules<GinGame, GinMove> = {
    start: startGin,
    moves: ginMoves,
    play: playGin,
    over: (game) => game.phase === "over",
    winners: ginWinners,
    encode: encodeGin,
    decode: decodeGin,
    toPlay: (game) => game.toPlay,
    computer: ginComputer,
    seats: (game) => ({ players: game.players, computers: game.computers }),
    sensible: ginSensible,
}

Members

NameTypeDescription
start(size: number, players: readonly string[], _reserved?: unknown, seed?: number, computers?: readonly boolean[]) => GinGame | null

A new game for these players (one name a seat) at this size, or null for a table the game is not offered for. size is how long the game lasts in its own terms (CARD_GAME_TABLES). The deal is shuffled from seed, so a seed and the moves make the same game again anywhere; computers says, one a seat, which seats a computer plays. The third argument is unused and reserved: it keeps the signature of a table of games that are played in a language (a word game), so these rules sit in such a table unchanged.

moves(game: GinGame) => readonly GinMove[]

Every move the player to move may make now; none once the game is over.

play(game: GinGame, move: GinMove) => GinGame | null

The game after that move, or null for a move that may not be made.

over(game: GinGame) => boolean
winners(game: GinGame) => readonly number[]

On a game that is over, every seat that won: more than one for a partnership or a tie.

encode(game: GinGame) => string

The game as text: its table, seed and moves, never a hand (cardGameCodec).

decode(text: string | null) => GinGame | null

Text read back into the game it records, or null for anything these rules cannot play out again.

toPlay(game: GinGame) => number | null

The seat to move, or null once the game is over.

computer(game: GinGame) => GinMove

The move a computer in the seat to move makes: always one of moves(game).

seats(game: GinGame) => CardSeats

Who sits where, and which seats a computer plays.

sensible (optional)((game: GinGame, random: () => number) => GinMove) | undefined

For a game a player choosing uniformly at random would almost never finish (Gin Rummy, where random play rarely knocks), a random move a sensible player might make, for tests and simulations. Always one of moves(game). Absent where random play ends by itself.

Examples

import { GIN_RUMMY_RULES } from "@johnmorrisdotca/toranpu/gin-rummy";
console.log(Object.keys(GIN_RUMMY_RULES));
[
  'start',    'moves',
  'play',     'over',
  'winners',  'encode',
  'decode',   'toPlay',
  'computer', 'seats',
  'sensible'
]

What it prints (run when this page was built)

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