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 · Games and state

cardGameCodecfunction

The keeping for one game: game names it, so one game's text is never read as another's; start and play are its rules; isMove checks a move's shape before the rules are asked about it.

Import it

import { cardGameCodec } from "@johnmorrisdotca/toranpu";

Definition

function cardGameCodec<S extends KeptCardGame<M>, M>(game: string, start: (size: number, players: readonly string[], language: undefined, seed: number, computers: readonly boolean[]) => S | null, play: (state: S, move: M) => S | null, isMove: (value: unknown) => value is M): CardGameCodec<S>

Parameters

NameTypeDescription
gamestring

The short game name recorded in the saved format.

start(size: number, players: readonly string[], language: undefined, seed: number, computers: readonly boolean[]) => S | null

The native function that starts a game from size, names, seed and computer flags.

play(state: S, move: M) => S | null

The native function that applies one legal move and returns the next game.

isMove(value: unknown) => value is M

The game-specific structural validator for a move.

Returns

CardGameCodec<S>

The keeping for one game: game names it, so one game's text is never read as another's; start and play are its rules; isMove checks a move's shape before the rules are asked about it.

Examples

import { CARD_GAME_TABLES, cardGameCodec, newGame } from "@johnmorrisdotca/toranpu";
import { encodeWar, isWarMove, playWar, startWar } from "@johnmorrisdotca/toranpu/war";

const names = Array.from({ length: CARD_GAME_TABLES.war.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`);
let game = newGame("war", { players: names, seed: 42 })!;
console.log(cardGameCodec("war", startWar, playWar, isWarMove).decode(encodeWar(game))?.phase);
playing

What it prints (run when this page was built)

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