リファレンス
デッキの道具
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. |
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。