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 · Big Two

BIG_TWO_RULESconstant

Big Two as one CardGameRules: everything a table asks of the game.

Import it

import { BIG_TWO_RULES } from "@johnmorrisdotca/toranpu/big-two";

Definition

const BIG_TWO_RULES: CardGameRules<BigTwoGame, ClimbMove> = {
    start: startBigTwo,
    moves: bigTwoMoves,
    play: playBigTwo,
    over: (game) => game.phase === "over",
    winners: bigTwoWinners,
    encode: encodeBigTwo,
    decode: decodeBigTwo,
    toPlay: (game) => game.toPlay,
    computer: bigTwoComputer,
    seats: (game) => ({ players: game.players, computers: game.computers }),
}

Members

NameTypeDescription
start(size: number, players: readonly string[], _reserved?: unknown, seed?: number, computers?: readonly boolean[]) => BigTwoGame | 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: BigTwoGame) => readonly ClimbMove[]

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

play(game: BigTwoGame, move: ClimbMove) => BigTwoGame | null

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

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

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

encode(game: BigTwoGame) => string

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

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

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

toPlay(game: BigTwoGame) => number | null

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

computer(game: BigTwoGame) => ClimbMove

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

seats(game: BigTwoGame) => CardSeats

Who sits where, and which seats a computer plays.

sensible (optional)((game: BigTwoGame, random: () => number) => ClimbMove) | 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 { BIG_TWO_RULES } from "@johnmorrisdotca/toranpu/big-two";
console.log(Object.keys(BIG_TWO_RULES));
[
  'start',    'moves',
  'play',     'over',
  'winners',  'encode',
  'decode',   'toPlay',
  'computer', 'seats'
]

What it prints (run when this page was built)

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