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 · React components

CardGameStatetype

A card game in React state: the game, the moves the person to play may make, and play to make one. Computers take their turns by themselves, one move every computerDelay milliseconds, so a person can follow them. Drawing the table is yours: this holds the game and nothing else.

const table = useCardGame("crazyEights", { players: ["You", "Ann"], computers: [false, true] });
table.moves.map((move) => <button onClick={() => table.play(move)}>…</button>);

Import it

import type { CardGameState } from "@johnmorrisdotca/toranpu/react";

Definition

type CardGameState<K extends CardGameKind> = {
    game: GameOf<K> | null;
    toPlay: number | null;
    computerToPlay: boolean;
    moves: readonly MoveOf<K>[];
    over: boolean;
    winners: readonly number[];
    play: (move: MoveOf<K>) => boolean;
    restart: (options?: Partial<NewGameOptions>) => void;
};

Members

NameTypeDescription
gameGameOf<K> | null

The game now, or null when the table was one the game is not offered for.

toPlaynumber | null

The seat to move, or null once the game is over.

computerToPlayboolean

Whether the seat to move is a computer's.

movesreadonly MoveOf<K>[]

The moves the seat to move may make: none while a computer is thinking or once the game is over.

overboolean
winnersreadonly number[]

Every seat that won, once the game is over.

play(move: MoveOf<K>) => boolean

Make a move for the person to play. Returns false for a move the rules refuse.

restart(options?: Partial<NewGameOptions>) => void

Deal a new game with the same table and a new seed, or the options given.

Examples

import type { CardGameState } from "@johnmorrisdotca/toranpu/react";
import { useCardGame } from "@johnmorrisdotca/toranpu/react";

function Table() {
  const value: CardGameState<"hearts"> = useCardGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 });
  console.log(value.moves.length);
  return null;
}
console.log(Table.name);

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