本文へ移動

Toranpuトランプ

デッキを使い、11種類のゲームでコンピューターと対戦し、ソリティアを解いたり、独自の絵柄でカードを表示したりできます。

「トランプ」は、日本語で playing cards を指す言葉です。 名前について(英語)

目次

リファレンス · ゲームと状態

cardGameCodec関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

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 { cardGameCodec } from "@johnmorrisdotca/toranpu";

定義

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>

引数

名前型説明
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.

戻り値

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.

例

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

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/toranpu 2.15.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。