リファレンス
ゲームと状態
import { … } from "@johnmorrisdotca/toranpu";
最小化と gzip 圧縮をしたサイズは 36.1 kB(読み込むものをすべて含み、esbuild で計測)
リファレンスの説明と例は英語です。見出しと目次は日本語です。
Toranpu トランプ: a deck of playing cards and eleven card games to play with it, each with a computer player.
- Every game by name:
newGame,rulesFor,playComputers, and every game's rules inCARD_GAME_RULES. - Each game's own functions and types, as a namespace here (
hearts,spades…) or from its own entry point (@johnmorrisdotca/toranpu/hearts). - The cards the games deal, as two-letter ids ("QS", "TD"), and the helpers every game shares: dealing, seats, choices, the saved-game format.
- The deck as card objects, for a game of your own:
@johnmorrisdotca/toranpu/deck. - Any game written out and read back (
toJSON,fromJSON,toCode,toText,toCSV), and the games, cards and moves in words, in English and Japanese (gameName,cardText,moveText,STRINGS). - The command line as a function:
runCli.
エクスポート
| 名前 | 種類 | 概要 |
|---|---|---|
allDifferent | 関数 | Whether a list names no card twice. |
BIG_TWO_DEALS | 定数 | How many deals a game of Big Two may last. |
bigTwo | 名前空間 | |
CARD_GAME_KINDS | 定数 | The eleven kinds by name, for code that would rather not type a string twice. |
CARD_GAME_LIST | 定数 | Every card game. |
CARD_GAME_RULES | 定数 | EVERY CARD GAME'S RULES, by kind: what a table plays and what the simulation plays out. |
CARD_GAME_TABLES | 定数 | Every game's table: the fewest, the most and the usual number of players, the lengths of game offered and the usual one. |
cardGameCodec | 関数 | The keeping for one game: game names it, so one game's text is never read as another's; start and play are its rules; isMove checks a move's shape before the rules are asked about it. |
CardGameCodec | 型 | A game's keeping: encode writes it as text, decode reads it back or gives null. |
CardGameKind | 型 | THE CARD GAMES, and the tables each offers. |
CardGamePlays | 型 | Each card game's game and move, so its rules can be named with their own types. |
CardGameRules | 型 | WHAT EVERY CARD GAME'S RULES ANSWER, whatever the game. |
CardGameTable | 型 | What a game's table offers: how many may sit at it, and how long a game may last. |
CardId | 型 | A card by its short name: rank letter then suit letter, "QS", "TD", "AH" (cards.ts). |
cardOf | 関数 | The card of this rank and suit. |
cardOfId | 関数 | The deck's card for an id, for the deck's components to draw. |
CardRank | 型 | The deck's rank, ace low: 1 is the ace, 11 the jack, 12 the queen, 13 the king. |
CardSeats | 型 | Who sits in each seat: the name the set-up gave, and whether a computer plays it. |
cardShort | 関数 | A card as a corner shows it: "Q♠", "10♦". |
cardsShort | 関数 | Cards as corners show them, with a space between: "Q♠ 10♦ A♥". |
CardSuit | 型 | Clubs, diamonds, hearts, spades. |
cardText | 関数 | A card's name in full: "queen of spades", or "スペードのクイーン" in Japanese. |
cardWords | 関数 | "queen of spades", as a sentence and a screen reader say it. |
choices | 関数 | Every way of choosing count of these cards, in the order they are given. |
cliLanguage | 関数 | The language the command line speaks: --lang, or the environment's, or the system's; Japanese for ja…, English for anything else. |
CliResult | 型 | What the command line came to. |
CliSurroundings | 型 | What the command line is run in. |
computerSeats | 関数 | The seats a computer plays, one a seat, from what the set-up said: a seat it said nothing about is a person's. |
CRAZY_EIGHTS_SIZES | 定数 | The scores a game of Crazy Eights may be played to. |
crazyEights | 名前空間 | |
cribbage | 名前空間 | |
CRIBBAGE_SIZES | 定数 | The scores a game of Cribbage may be played to: once round the board, or twice. |
CSV_COLUMNS | 定数 | The columns of the CSV, in order. |
dealRound | 関数 | Deals the cards one at a time round the table, from the first seat, as a dealer does: each to a seat, or every card when each is absent (so some seats hold one more than others). |
euchre | 名前空間 | |
EUCHRE_SIZES | 定数 | The scores a game of Euchre may be played to. |
fillIn | 関数 | Put values into a string's braces: fillIn("Bid {n}", { n: 3 }) is "Bid 3". |
fromCode | 関数 | A game from its code or its JSON: the same as fromJSON, under the name that pairs with toCode. |
fromJSON | 関数 | A game from text that toJSON or toCode wrote, whichever game it is. |
FULL_DECK | 定数 | Every card, in the deck's own order. |
gameName | 関数 | A game's name: "Hearts", or "ハーツ" in Japanese. |
GameOf | 型 | A game of that kind, in progress. |
gameSays | 関数 | A game in a line: what it is about, for a list of games. |
GIN_SIZES | 定数 | The scores a game of Gin Rummy may be played to. |
ginRummy | 名前空間 | |
GO_FISH_SIZES | 定数 | Go Fish is one deal: its only size is 1. |
goFish | 名前空間 | |
hearts | 名前空間 | |
HEARTS_SIZES | 定数 | How long each game lasts, in its own terms (see above). |
isCard | 関数 | Whether this is one of the fifty-two names. |
isCardList | 関数 | A list of card names, checked for shape only: whether they are cards the game holds is the rules' to say. |
KeptCardGame | 型 | What every card game's state carries for its keeping. |
Language | 型 | The languages Toranpu speaks. |
languageOf | 関数 | The language a tag such as ja-JP or en_US.UTF-8 names: Japanese for anything that starts ja, English otherwise. |
mixSeed | 関数 | Two numbers folded into one seed, so each deal of a game (and each reshuffle within one) has its own order. |
MoveOf | 型 | A move in a game of that kind. |
moveText | 関数 | A move in words, for any of the eleven games: moveText("hearts", { play: "QS" }) is "Play Q♠", and with { form: "did" } it is "plays Q♠". |
MoveTextOptions | 型 | How a move is put into words. |
namesList | 関数 | Names in a list: "Ann, Ben", or "Ann、Ben" in Japanese. |
newGame | 関数 | A new game of that kind, or null when the game is not offered for that table (too many players, or a size it does not play to). |
NewGameOptions | 型 | How to seat a new game. |
nextSeat | 関数 | The next seat round the table, to the left: the order every game here plays in. |
OH_HELL_DEALS | 定数 | How many deals a game of Oh Hell may last: up to seven cards, or up and back down. |
ohHell | 名前空間 | |
playComputers | 関数 | Every computer move due, played in turn until a person is to move or the game is over. |
president | 名前空間 | |
PRESIDENT_ROUNDS | 定数 | How many rounds a game of President may last. |
Random | 型 | A number in [0, 1), like Math.random, from a stream a seed fixes. |
randomSeed | 関数 | A seed for a game nobody asked for by number: a whole number from 1 to 2³¹ − 1. |
RANK_LETTERS | 定数 | The rank letters, ace low: an index here plus one is the rank (A = 1, J = 11, Q = 12, K = 13). |
rankName | 関数 | A rank as a sentence names one card of it: "queen", "seven"; in Japanese "クイーン", "7". |
rankOf | 関数 | A card's rank, ace low: 1 to 13. |
rankWords | 関数 | A rank named in the plural, as it is asked for: "sevens", "sixes", "queens". |
ReadGame | 型 | A game read back: which game it is, and the game itself. |
RecordedMove | 型 | One move of a record: which seat made it, and the move. |
recordOf | 関数 | Every move of a game with the seat that made it, in order, found by playing the game through again from its seed. |
reshuffled | 関数 | These cards shuffled again, the same way for the same seed and salt: a pile turned over to make a new stock. |
rulesFor | 関数 | A game's rules by its kind, with its own game and move types. |
runCli | 関数 | Run the command line. |
SAVE_FORMAT | 定数 | The shape of the JSON this package writes. |
savedGame | 関数 | A game as the object toJSON writes: its table, its seed and its moves. |
SavedGame | 型 | A game as toJSON writes it. |
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 | 関数 | The deck shuffled for one deal of one game: the same seed and deal always the same order, so a game kept as its seed and moves deals itself again exactly, and reloading can never re-deal a hand somebody has seen. |
spades | 名前空間 | |
SPADES_SIZES | 定数 | The scores a game of Spades may be played to. |
STRINGS | 定数 | Every string, in both languages. |
suitName | 関数 | A suit's name: "spades", or "スペード" in Japanese. |
suitOf | 関数 | A card's suit, as its letter: S, H, D or C. |
suitSymbol | 関数 | A suit's symbol: ♠ ♥ ♦ ♣. |
suitWords | 関数 | A suit's name: "spades". |
toCode | 関数 | A game as its code: the one line its own rules' encode writes. |
toCSV | 関数 | A game's moves as CSV for a spreadsheet: a header, then a row a move, with its number from 1, the seat from 1 and its player, the kind of move (play, bid, pass…), the cards it names as two-letter ids with spaces between, the move itself as JSON, and the move in English. |
toJSON | 関数 | A game as JSON, two spaces deep, with the format's number first. |
ToranpuStrings | 型 | The names of the strings. |
toText | 関数 | A game as a record a person can read: a heading, a numbered line a move with who made it, and how it stands. |
VERSION | 定数 | The version of this package, as package.json has it. |
war | 名前空間 | |
WAR_ROUNDS | 定数 | How many turns of the cards a game of War may last before the player holding more cards wins. |
without | 関数 | The hand without these cards, or null when it does not hold every one of them. |
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。