toCodefunction
A game as its code: the one line its own rules' encode writes. Shorter than the JSON, and what Itsutsu keeps.
Import it
import { toCode } from "@johnmorrisdotca/toranpu";
Definition
function toCode<K extends CardGameKind>(kind: K, game: GameOf<K>): string
Parameters
| Name | Type | Description |
|---|---|---|
kind | K | The named card game or sound kind. |
game | GameOf<K> | The current native game; applying a move returns a new state. |
Returns
string
A game as its code: the one line its own rules' encode writes. Shorter than the JSON, and what Itsutsu keeps.
Examples
import { newGame, toCode } from "@johnmorrisdotca/toranpu";
const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!;
console.log(toCode("hearts", game));{"v":1,"g":"hearts","size":100,"players":["Aki","Ben","Cy","Dev"],"computers":[false,false,false,false],"seed":42,"moves":[]}What it prints (run when this page was built)