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

SpadesGametype

A GAME OF SPADES: its table and moves (what is kept, KeptCardGame), and everything the moves make, read again from them whenever the game is. Four seats in two partnerships, sitting across from each other: seats 0 and 2 against 1 and 3. size is the score that ends the game: 200, 300 or 500.

Import it

import type { SpadesGame } from "@johnmorrisdotca/toranpu/spades";

Definition

type SpadesGame = KeptCardGame<SpadesMove> & {
    deal: number;
    phase: SpadesPhase;
    hands: CardId[][];
    bids: (number | null)[];
    trick: SpadesPlay[];
    lastTrick: {
        plays: SpadesPlay[];
        winner: number;
    } | null;
    played: CardId[];
    toPlay: number | null;
    spadesBroken: boolean;
    tricks: number[];
    scores: [
        number,
        number
    ];
    bags: [
        number,
        number
    ];
    dealScores: SpadesDealScore[];
};

Members

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

Which deal this is, from 0: the deal moves one seat round each time.

phaseSpadesPhase
handsstring[][]
bids(number | null)[]

Each seat's bid this deal, 0 for nil, or null while it has not bid.

trickSpadesPlay[]

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

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

The trick before, and who took it.

playedstring[]

Every card played in a finished trick this deal.

toPlaynumber | null

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

spadesBrokenboolean

Whether a spade has been played on another suit (or led from a hand of nothing else) this deal.

tricksnumber[]

The tricks each seat has taken this deal.

scores[number, number]

Each partnership's score, before this deal: seats 0 and 2, then 1 and 3.

bags[number, number]

Each partnership's overtricks carried towards the next ten.

dealScoresSpadesDealScore[]

Each finished deal, one row a deal.

Examples

import { CARD_GAME_TABLES, newGame } from "@johnmorrisdotca/toranpu";
import type { SpadesGame } from "@johnmorrisdotca/toranpu/spades";

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

What it prints (run when this page was built)

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