toJSONfunction
A game as JSON, two spaces deep, with the format's number first. fromJSON reads it back.
Import it
import { toJSON } from "@johnmorrisdotca/toranpu";
Definition
function toJSON<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 JSON, two spaces deep, with the format's number first. fromJSON reads it back.
Examples
import { newGame, toJSON } from "@johnmorrisdotca/toranpu";
const game = newGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 })!;
console.log(toJSON("hearts", game));{
"format": 1,
"generator": "toranpu 2.15.0",
"game": "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)