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 · Hearts

HeartsGametype

A GAME OF HEARTS: its table and moves (what is kept, KeptCardGame), and everything the moves make, read again from them whenever the game is. size is the score that ends the game: 50 or 100.

Import it

import type { HeartsGame } from "@johnmorrisdotca/toranpu/hearts";

Definition

type HeartsGame = KeptCardGame<HeartsMove> & {
    deal: number;
    phase: HeartsPhase;
    hands: CardId[][];
    passing: (CardId[] | null)[];
    received: CardId[][];
    trick: HeartsPlay[];
    lastTrick: {
        plays: HeartsPlay[];
        winner: number;
    } | null;
    played: CardId[];
    toPlay: number | null;
    heartsBroken: boolean;
    points: number[];
    scores: number[];
    dealScores: number[][];
    moon: number | null;
};

Members

NameTypeDescription
sizenumber
playersreadonly string[]
computersreadonly boolean[]
seednumber
movesreadonly HeartsMove[]
dealnumber

Which deal this is, from 0: it decides the way the cards are passed.

phaseHeartsPhase
handsstring[][]
passing(string[] | null)[]

The three cards each seat has chosen to pass this deal, or null while it has not.

receivedstring[][]

The three cards each seat was passed this deal, shown to that seat once the passing is done.

trickHeartsPlay[]

The trick on the table, in the order it was played.

lastTrick{ plays: HeartsPlay[]; winner: number; } | null

The trick before, and who took it: what a player may still look back at.

playedstring[]

Every card played in a finished trick this deal: what everybody at the table has seen.

toPlaynumber | null

Whose move it is; null once the game is over.

heartsBrokenboolean
pointsnumber[]

Each seat's points taken this deal, so far.

scoresnumber[]

Each seat's total before this deal.

dealScoresnumber[][]

Each finished deal's points, one row a deal.

moonnumber | null

The seat that took every point of the last finished deal, if one did.

Examples

import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu";
import type { HeartsGame } from "@johnmorrisdotca/toranpu/hearts";

const names = Array.from({ length: CARD_GAME_TABLES.hearts.defaultPlayers }, (_, seat) => `Seat ${seat + 1}`);
const game = newGame("hearts", { players: names, seed: 42 })!;
const value: HeartsGame = game;
console.log(value.phase);
passing

What it prints (run when this page was built)

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