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>
引数
| 名前 | 型 | 説明 |
|---|---|---|
game | string | 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出力(このページを作ったときに実行した結果)
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。