Reference
Games and state
import { … } from "@johnmorrisdotca/toranpu";
36.1 kB minified and gzipped, with everything it imports (measured with 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.
Exports
| Name | Kind | What it is |
|---|---|---|
allDifferent | function | Whether a list names no card twice. |
BIG_TWO_DEALS | constant | How many deals a game of Big Two may last. |
bigTwo | namespace | |
CARD_GAME_KINDS | constant | The eleven kinds by name, for code that would rather not type a string twice. |
CARD_GAME_LIST | constant | Every card game. |
CARD_GAME_RULES | constant | EVERY CARD GAME'S RULES, by kind: what a table plays and what the simulation plays out. |
CARD_GAME_TABLES | constant | Every game's table: the fewest, the most and the usual number of players, the lengths of game offered and the usual one. |
cardGameCodec | function | 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 | type | A game's keeping: encode writes it as text, decode reads it back or gives null. |
CardGameKind | type | THE CARD GAMES, and the tables each offers. |
CardGamePlays | type | Each card game's game and move, so its rules can be named with their own types. |
CardGameRules | type | WHAT EVERY CARD GAME'S RULES ANSWER, whatever the game. |
CardGameTable | type | What a game's table offers: how many may sit at it, and how long a game may last. |
CardId | type | A card by its short name: rank letter then suit letter, "QS", "TD", "AH" (cards.ts). |
cardOf | function | The card of this rank and suit. |
cardOfId | function | The deck's card for an id, for the deck's components to draw. |
CardRank | type | The deck's rank, ace low: 1 is the ace, 11 the jack, 12 the queen, 13 the king. |
CardSeats | type | Who sits in each seat: the name the set-up gave, and whether a computer plays it. |
cardShort | function | A card as a corner shows it: "Q♠", "10♦". |
cardsShort | function | Cards as corners show them, with a space between: "Q♠ 10♦ A♥". |
CardSuit | type | Clubs, diamonds, hearts, spades. |
cardText | function | A card's name in full: "queen of spades", or "スペードのクイーン" in Japanese. |
cardWords | function | "queen of spades", as a sentence and a screen reader say it. |
choices | function | Every way of choosing count of these cards, in the order they are given. |
cliLanguage | function | The language the command line speaks: --lang, or the environment's, or the system's; Japanese for ja…, English for anything else. |
CliResult | type | What the command line came to. |
CliSurroundings | type | What the command line is run in. |
computerSeats | function | 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 | constant | The scores a game of Crazy Eights may be played to. |
crazyEights | namespace | |
cribbage | namespace | |
CRIBBAGE_SIZES | constant | The scores a game of Cribbage may be played to: once round the board, or twice. |
CSV_COLUMNS | constant | The columns of the CSV, in order. |
dealRound | function | 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 | namespace | |
EUCHRE_SIZES | constant | The scores a game of Euchre may be played to. |
fillIn | function | Put values into a string's braces: fillIn("Bid {n}", { n: 3 }) is "Bid 3". |
fromCode | function | A game from its code or its JSON: the same as fromJSON, under the name that pairs with toCode. |
fromJSON | function | A game from text that toJSON or toCode wrote, whichever game it is. |
FULL_DECK | constant | Every card, in the deck's own order. |
gameName | function | A game's name: "Hearts", or "ハーツ" in Japanese. |
GameOf | type | A game of that kind, in progress. |
gameSays | function | A game in a line: what it is about, for a list of games. |
GIN_SIZES | constant | The scores a game of Gin Rummy may be played to. |
ginRummy | namespace | |
GO_FISH_SIZES | constant | Go Fish is one deal: its only size is 1. |
goFish | namespace | |
hearts | namespace | |
HEARTS_SIZES | constant | How long each game lasts, in its own terms (see above). |
isCard | function | Whether this is one of the fifty-two names. |
isCardList | function | A list of card names, checked for shape only: whether they are cards the game holds is the rules' to say. |
KeptCardGame | type | What every card game's state carries for its keeping. |
Language | type | The languages Toranpu speaks. |
languageOf | function | The language a tag such as ja-JP or en_US.UTF-8 names: Japanese for anything that starts ja, English otherwise. |
mixSeed | function | Two numbers folded into one seed, so each deal of a game (and each reshuffle within one) has its own order. |
MoveOf | type | A move in a game of that kind. |
moveText | function | 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 | type | How a move is put into words. |
namesList | function | Names in a list: "Ann, Ben", or "Ann、Ben" in Japanese. |
newGame | function | 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 | type | How to seat a new game. |
nextSeat | function | The next seat round the table, to the left: the order every game here plays in. |
OH_HELL_DEALS | constant | How many deals a game of Oh Hell may last: up to seven cards, or up and back down. |
ohHell | namespace | |
playComputers | function | Every computer move due, played in turn until a person is to move or the game is over. |
president | namespace | |
PRESIDENT_ROUNDS | constant | How many rounds a game of President may last. |
Random | type | A number in [0, 1), like Math.random, from a stream a seed fixes. |
randomSeed | function | A seed for a game nobody asked for by number: a whole number from 1 to 2³¹ − 1. |
RANK_LETTERS | constant | The rank letters, ace low: an index here plus one is the rank (A = 1, J = 11, Q = 12, K = 13). |
rankName | function | A rank as a sentence names one card of it: "queen", "seven"; in Japanese "クイーン", "7". |
rankOf | function | A card's rank, ace low: 1 to 13. |
rankWords | function | A rank named in the plural, as it is asked for: "sevens", "sixes", "queens". |
ReadGame | type | A game read back: which game it is, and the game itself. |
RecordedMove | type | One move of a record: which seat made it, and the move. |
recordOf | function | Every move of a game with the seat that made it, in order, found by playing the game through again from its seed. |
reshuffled | function | These cards shuffled again, the same way for the same seed and salt: a pile turned over to make a new stock. |
rulesFor | function | A game's rules by its kind, with its own game and move types. |
runCli | function | Run the command line. |
SAVE_FORMAT | constant | The shape of the JSON this package writes. |
savedGame | function | A game as the object toJSON writes: its table, its seed and its moves. |
SavedGame | type | A game as toJSON writes it. |
seededRandom | function | A stream of numbers in [0, 1) fixed by a seed. |
shuffled | function | A copy of the list in a random order (Fisher–Yates); the list given is left alone. |
shuffledDeck | function | 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 | namespace | |
SPADES_SIZES | constant | The scores a game of Spades may be played to. |
STRINGS | constant | Every string, in both languages. |
suitName | function | A suit's name: "spades", or "スペード" in Japanese. |
suitOf | function | A card's suit, as its letter: S, H, D or C. |
suitSymbol | function | A suit's symbol: ♠ ♥ ♦ ♣. |
suitWords | function | A suit's name: "spades". |
toCode | function | A game as its code: the one line its own rules' encode writes. |
toCSV | function | 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 | function | A game as JSON, two spaces deep, with the format's number first. |
ToranpuStrings | type | The names of the strings. |
toText | function | 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 | constant | The version of this package, as package.json has it. |
war | namespace | |
WAR_ROUNDS | constant | How many turns of the cards a game of War may last before the player holding more cards wins. |
without | function | The hand without these cards, or null when it does not hold every one of them. |