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

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 in CARD_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

NameKindWhat it is
allDifferentfunctionWhether a list names no card twice.
BIG_TWO_DEALSconstantHow many deals a game of Big Two may last.
bigTwonamespace
CARD_GAME_KINDSconstantThe eleven kinds by name, for code that would rather not type a string twice.
CARD_GAME_LISTconstantEvery card game.
CARD_GAME_RULESconstantEVERY CARD GAME'S RULES, by kind: what a table plays and what the simulation plays out.
CARD_GAME_TABLESconstantEvery game's table: the fewest, the most and the usual number of players, the lengths of game offered and the usual one.
cardGameCodecfunctionThe 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.
CardGameCodectypeA game's keeping: encode writes it as text, decode reads it back or gives null.
CardGameKindtypeTHE CARD GAMES, and the tables each offers.
CardGamePlaystypeEach card game's game and move, so its rules can be named with their own types.
CardGameRulestypeWHAT EVERY CARD GAME'S RULES ANSWER, whatever the game.
CardGameTabletypeWhat a game's table offers: how many may sit at it, and how long a game may last.
CardIdtypeA card by its short name: rank letter then suit letter, "QS", "TD", "AH" (cards.ts).
cardOffunctionThe card of this rank and suit.
cardOfIdfunctionThe deck's card for an id, for the deck's components to draw.
CardRanktypeThe deck's rank, ace low: 1 is the ace, 11 the jack, 12 the queen, 13 the king.
CardSeatstypeWho sits in each seat: the name the set-up gave, and whether a computer plays it.
cardShortfunctionA card as a corner shows it: "Q♠", "10♦".
cardsShortfunctionCards as corners show them, with a space between: "Q♠ 10♦ A♥".
CardSuittypeClubs, diamonds, hearts, spades.
cardTextfunctionA card's name in full: "queen of spades", or "スペードのクイーン" in Japanese.
cardWordsfunction"queen of spades", as a sentence and a screen reader say it.
choicesfunctionEvery way of choosing count of these cards, in the order they are given.
cliLanguagefunctionThe language the command line speaks: --lang, or the environment's, or the system's; Japanese for ja…, English for anything else.
CliResulttypeWhat the command line came to.
CliSurroundingstypeWhat the command line is run in.
computerSeatsfunctionThe 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_SIZESconstantThe scores a game of Crazy Eights may be played to.
crazyEightsnamespace
cribbagenamespace
CRIBBAGE_SIZESconstantThe scores a game of Cribbage may be played to: once round the board, or twice.
CSV_COLUMNSconstantThe columns of the CSV, in order.
dealRoundfunctionDeals 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).
euchrenamespace
EUCHRE_SIZESconstantThe scores a game of Euchre may be played to.
fillInfunctionPut values into a string's braces: fillIn("Bid {n}", { n: 3 }) is "Bid 3".
fromCodefunctionA game from its code or its JSON: the same as fromJSON, under the name that pairs with toCode.
fromJSONfunctionA game from text that toJSON or toCode wrote, whichever game it is.
FULL_DECKconstantEvery card, in the deck's own order.
gameNamefunctionA game's name: "Hearts", or "ハーツ" in Japanese.
GameOftypeA game of that kind, in progress.
gameSaysfunctionA game in a line: what it is about, for a list of games.
GIN_SIZESconstantThe scores a game of Gin Rummy may be played to.
ginRummynamespace
GO_FISH_SIZESconstantGo Fish is one deal: its only size is 1.
goFishnamespace
heartsnamespace
HEARTS_SIZESconstantHow long each game lasts, in its own terms (see above).
isCardfunctionWhether this is one of the fifty-two names.
isCardListfunctionA list of card names, checked for shape only: whether they are cards the game holds is the rules' to say.
KeptCardGametypeWhat every card game's state carries for its keeping.
LanguagetypeThe languages Toranpu speaks.
languageOffunctionThe language a tag such as ja-JP or en_US.UTF-8 names: Japanese for anything that starts ja, English otherwise.
mixSeedfunctionTwo numbers folded into one seed, so each deal of a game (and each reshuffle within one) has its own order.
MoveOftypeA move in a game of that kind.
moveTextfunctionA move in words, for any of the eleven games: moveText("hearts", { play: "QS" }) is "Play Q♠", and with { form: "did" } it is "plays Q♠".
MoveTextOptionstypeHow a move is put into words.
namesListfunctionNames in a list: "Ann, Ben", or "Ann、Ben" in Japanese.
newGamefunctionA 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).
NewGameOptionstypeHow to seat a new game.
nextSeatfunctionThe next seat round the table, to the left: the order every game here plays in.
OH_HELL_DEALSconstantHow many deals a game of Oh Hell may last: up to seven cards, or up and back down.
ohHellnamespace
playComputersfunctionEvery computer move due, played in turn until a person is to move or the game is over.
presidentnamespace
PRESIDENT_ROUNDSconstantHow many rounds a game of President may last.
RandomtypeA number in [0, 1), like Math.random, from a stream a seed fixes.
randomSeedfunctionA seed for a game nobody asked for by number: a whole number from 1 to 2³¹ − 1.
RANK_LETTERSconstantThe rank letters, ace low: an index here plus one is the rank (A = 1, J = 11, Q = 12, K = 13).
rankNamefunctionA rank as a sentence names one card of it: "queen", "seven"; in Japanese "クイーン", "7".
rankOffunctionA card's rank, ace low: 1 to 13.
rankWordsfunctionA rank named in the plural, as it is asked for: "sevens", "sixes", "queens".
ReadGametypeA game read back: which game it is, and the game itself.
RecordedMovetypeOne move of a record: which seat made it, and the move.
recordOffunctionEvery move of a game with the seat that made it, in order, found by playing the game through again from its seed.
reshuffledfunctionThese cards shuffled again, the same way for the same seed and salt: a pile turned over to make a new stock.
rulesForfunctionA game's rules by its kind, with its own game and move types.
runClifunctionRun the command line.
SAVE_FORMATconstantThe shape of the JSON this package writes.
savedGamefunctionA game as the object toJSON writes: its table, its seed and its moves.
SavedGametypeA game as toJSON writes it.
seededRandomfunctionA stream of numbers in [0, 1) fixed by a seed.
shuffledfunctionA copy of the list in a random order (Fisher–Yates); the list given is left alone.
shuffledDeckfunctionThe 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.
spadesnamespace
SPADES_SIZESconstantThe scores a game of Spades may be played to.
STRINGSconstantEvery string, in both languages.
suitNamefunctionA suit's name: "spades", or "スペード" in Japanese.
suitOffunctionA card's suit, as its letter: S, H, D or C.
suitSymbolfunctionA suit's symbol: ♠ ♥ ♦ ♣.
suitWordsfunctionA suit's name: "spades".
toCodefunctionA game as its code: the one line its own rules' encode writes.
toCSVfunctionA 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.
toJSONfunctionA game as JSON, two spaces deep, with the format's number first.
ToranpuStringstypeThe names of the strings.
toTextfunctionA game as a record a person can read: a heading, a numbered line a move with who made it, and how it stands.
VERSIONconstantThe version of this package, as package.json has it.
warnamespace
WAR_ROUNDSconstantHow many turns of the cards a game of War may last before the player holding more cards wins.
withoutfunctionThe hand without these cards, or null when it does not hold every one of them.

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