本文へ移動

Toranpuトランプ

デッキを使い、11種類のゲームでコンピューターと対戦し、ソリティアを解いたり、独自の絵柄でカードを表示したりできます。

「トランプ」は、日本語で playing cards を指す言葉です。 名前について(英語)

目次

リファレンス

デッキの道具

import { … } from "@johnmorrisdotca/toranpu/deck";

最小化と gzip 圧縮をしたサイズは 1.5 kB(読み込むものをすべて含み、esbuild で計測)

リファレンスの説明と例は英語です。見出しと目次は日本語です。

The deck on its own: fifty-two cards as objects ({ suit, rank }), a seeded shuffle, dealing, one-character and two-character codes, and the names a card is written and spoken by. For a solitaire or any game of your own.

エクスポート

名前種類概要
Card型A card as an object: its suit and its rank.
CARD_ALPHABET定数The fifty-two characters a card is written as, in deck order: spades A–K are A–M, hearts N–Z, diamonds a–m, clubs n–z.
cardAt関数The card at a place in a fresh deck, 0 to 51.
cardCode関数One character for a card (CARD_ALPHABET).
CardCode型A card as ONE character, A–Z then a–z (cardCode): a whole deck is a fifty-two-character string, so a deal travels in a saved game, an address and a move list without any separator to parse.
cardFromCode関数The card a character names, or null for one that names none — a kept string is read, never trusted.
cardFromId関数The card a two-character id names, or null.
cardId関数"QS", "TH", "AC": the two-character id card players write, rank then suit, with T for the ten.
cardIndex関数The card's place in a fresh deck, 0 to 51.
cardName関数"queen of hearts": the name a screen reader says.
cardShortName関数"Q♥": the short name a corner shows.
colourOf関数A card's colour: red for hearts and diamonds, black for spades and clubs.
dealAll関数Deal the whole deck round the table: the first hands get one more where it does not divide evenly.
dealRound関数Deal one card at a time round the table, as a dealer does: hands hands of each cards, dealt from the top (the start of the array), and what is left.
DECK_SIZE定数How many cards a deck holds: fifty-two.
freshDeck関数A fresh deck in the order a new pack is sorted: spades ace to king, then hearts, diamonds, clubs.
isRed関数Whether a card is a heart or a diamond.
isWholeDeck関数Whether a string is a whole deck: fifty-two cards, each exactly once.
Random型A number in [0, 1), like Math.random, from a stream a seed fixes.
Rank型Ace is 1 and King 13.
RANK_DISPLAY定数How each rank is written: short (A, 10, K) and as a word (ace, ten, king).
RankDisplay型How a rank is written: A, 2…10, J, Q, K, and in a sentence.
RANKS定数The ranks in order, ace low: 1 (the ace) to 13 (the king).
readCards関数A string of card characters read back, or null if any character names no card.
sameCard関数Whether two card objects are the same card.
seededRandom関数A stream of numbers in [0, 1) fixed by a seed.
shuffled関数A copy of the list in a random order (Fisher–Yates); the list given is left alone.
shuffledDeck関数A deck shuffled from a seed: the same seed, the same order, in every browser and every test.
sortedHand関数A hand sorted by suit (the fresh-deck order) and then by rank: how a player arranges one.
Suit型One of the four suits, by name.
SUIT_DISPLAY定数How each suit is written and drawn: its symbol, its name and its colour.
SuitColour型A suit's colour, which Klondike's alternating runs and Crazy Eights' matches both read.
SuitDisplay型How a suit is written and drawn.
SUITS定数The suits in the order a fresh deck is sorted and a foundation row is laid out: spades, hearts, diamonds, clubs — black, red, red, black, so no two neighbours on a row of four look alike.
take関数Take count from the top: what was taken, and what is left.
writeCards関数A run of cards as a string, one character each.

ソースを見るGitHub で編集@johnmorrisdotca/toranpu 2.15.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。