Skip to the content

Tenka天下

Play seeded world conquest for two to six, with dice battles, cards, computer players and saved games.

Tenka means the world under heaven in Japanese. About the name

Contents

Reference

Rules, maps and records

import { … } from "@johnmorrisdotca/tenka";

14.9 kB minified and gzipped, with everything it imports (measured with esbuild)

Tenka 天下: the classic world-conquest game on a map of the modern world, for two to six players, as plain functions over plain data.

A game is a value. startTenka deals one from a seed, playTenka makes a move and returns the next game (or null for a move the rules refuse), and every shuffle, deal and die is drawn from the game's own seeded random, so a game replays exactly from its seed and its moves (encodeTenka, decodeTenka). Nothing here touches the DOM, a clock or Math.random.

The map's outlines, which only a board drawing the world needs, are their own entry, @johnmorrisdotca/tenka/shapes, and so is the table that draws and plays a game in plain DOM, @johnmorrisdotca/tenka/ui.

Exports

NameKindWhat it is
areNeighboursfunctionWhether two territories are neighbours, by land or by sea.
armiesHeldfunctionHow many armies an owner has on the map.
attacksOpenfunctionEvery attack open now: from each territory of theirs with armies to spare, on each neighbour somebody else holds, with each number of dice — and the same attack again and again until it is decided.
battleLossesfunctionWHO LOSES WHAT: the highest die of each side compared, then the next highest, as many pairs as the side with fewer dice threw.
beginTurnfunctionA turn starting for seat: its armies worked out, nothing yet taken, nothing rolled.
boardOffunctionThe map an argument names, and the world for anything that is not one: these functions are handed to an array's map and filter (deck.map(cardKind)), which pass an index where the map would go.
cardKindfunctionWhat a card shows: land, sea or air for a territory's card, in turn round the map; wild for a wild card.
cardTerritoryfunctionThe territory a card shows, or null for a wild card.
choiceNowfunctionA choice made on an earlier map, read against this one: only what still stands, and a number of armies the move can take.
cleanTenkaNamefunctionA name as the table typed it, tidied: spaces run together, trimmed, cut to TENKA_NAME_MOST.
connectedOwnfunctionEvery territory of the same owner reachable from this one through that owner's own territories, in order; never the territory itself.
continentNameInfunctionA continent's name in a table of strings, by its key ("northAmerica", "asia"…).
continentsHeldfunctionThe continents a seat holds every territory of.
countedfunctionTHE COUNT, when the last round is over: whoever holds the most territories wins; level on territories, whoever has more armies on the map; level on both, they share the win.
decodeTenkafunctionA kept game read back, or null for nothing kept, or for text that is not a game these rules can play out again: a browser's storage is somebody's to edit, and a half-understood game is worse than none.
defendDicefunctionThe dice a defender holding armies throws: as many as allowed, since more never hurts the defence.
encodeTenkafunctionA game as text to keep: its table and its moves.
endOfTurnfunctionTHE END OF A TURN: a card for a player who took a territory in it, then the next player still in.
finishedfunctionThe game ended, with these seats winning.
isSetfunctionWhether three cards make a set: three of one kind, one of each kind, or any two with a wild card (a wild card stands for whatever the set needs).
isTenkaSeedfunctionWhether a number is a seed a game can be dealt from: a whole number from 0 to TENKA_SEED_MOST.
isTenkaTablefunctionWhether a game this long for this many players is one Tenka is offered for.
isTerritoryfunctionWhether a number is a territory of the map.
isWildfunctionWhether a card is one of the two wild cards.
marksForfunctionWhat the map lights up for a choice.
mostAttackDicefunctionThe most dice an attacker may throw from a territory holding armies: one army always stays behind.
mustTradefunctionWhether the player to move must trade cards before anything else: five or more in hand while reinforcing.
nextRandomfunctionThe next number from the random at state, in [0, 1), and the state after it.
nextSeatInfunctionThe next player still in after seat, round the table; the neutral army never takes a turn.
NO_CHOICEconstantNothing chosen: where a turn, and a table, start.
playTenkafunctionThe game after the player to move makes move, or null when they may not: a move for another phase, a territory not theirs, a neighbour that is not one, dice they have not the armies for, a set that is not a set.
randomBelowfunctionA whole number from 0 to below - 1, and the state after it.
readTenkaMovefunctionA kept move read back, or null for anything that is not one.
reinforcementForfunctionTHE ARMIES A TURN BRINGS: one for every three territories held, never fewer than three, and each continent held whole adds its bonus.
replayTenkafunctionA game made again from its table and its moves, or null if any move could not have been made when it was.
sensibleTenkaMovefunctionThe computer player's move: one the rules accept, chosen as a person might.
setsInfunctionEvery set a hand holds, each as its three cards smallest first, in order.
shuffledfunctionA list in a random order (Fisher and Yates), and the state after it; the list given is left alone.
startTenkafunctionA NEW GAME, all of it drawn from seed: who goes first; the territories shuffled and dealt round the table one at a time from that player, each with one army on it (at a table of two, dealt three ways, the neutral army taking every third); the cards shuffled; and each player's starting armies (TENKA_STARTING_ARMIES) less the ones already on their territories — scattered at random when placing is auto, or left to be placed by hand, one at a time round the table.
tapTerritoryfunctionWhat tapping territory does now: a new choice, and the move to make at once, if the tap is one.
TENKA_ATTACK_DICEconstantThe most dice an attacker throws.
TENKA_CARD_KINDSconstantThe three kinds a territory's card shows, in turn round the map, and the wild card that is any of them.
TENKA_CONTINENTSconstantThe world's six continents, each with the territories in it.
TENKA_CSV_COLUMNSconstantThe columns of the CSV export, in order.
TENKA_DECKconstantEvery card in the game: the territories' cards, then the wild cards.
TENKA_DEFEND_DICEconstantThe most dice a defender throws.
TENKA_EXPORT_FORMATconstantThe shape of the JSON this package writes.
TENKA_FEWEST_PLAYERSconstantThe fewest at a table: two, joined by the neutral army.
TENKA_LEAST_REINFORCEMENTconstantThe fewest armies a turn brings, however little is held.
TENKA_LENGTHSconstantThe lengths of game startTenka takes, in rounds: 10, 20 and 60.
TENKA_MAP_LISTconstantThe maps in the order a set-up offers them: the world first, the usual one.
TENKA_MAPSconstantEvery map a game may be played on, by key.
TENKA_MEDIUM_ROUNDSconstantThe medium game: twenty rounds, then the count.
TENKA_MOST_PLAYERSconstantThe most at a table: six.
TENKA_MOVESconstantThe kinds of move, by name: what goes in a move's kind.
TENKA_MUST_TRADE_ATconstantWith this many cards in hand a player must trade before placing; after knocking somebody out, down to fewer than this.
TENKA_NAME_MOSTconstantThe longest name a seat keeps.
TENKA_NEUTRALconstantThe owner of the territories nobody at a table of two holds: the neutral army, which never takes a turn.
TENKA_PHASESconstantThe phases of a turn, by name: compare game.phase with these rather than with text typed out.
TENKA_PLACINGconstantHow the starting armies are placed: scattered at random (auto), or by the players in turn (hand).
TENKA_SEED_MOSTconstantThe largest seed a game keeps: the random's state is one 32-bit number.
TENKA_SHORT_ROUNDSconstantThe short game: ten rounds, then the count.
TENKA_STARTING_ARMIESconstantTHE ARMIES EACH PLAYER STARTS WITH, by how many are playing: the standard table.
TENKA_STRINGSconstantThe package's words in each language it speaks: TENKA_STRINGS.en, TENKA_STRINGS.ja.
TENKA_TERRITORIESconstantThe world's territories: the map a game is played on unless it says otherwise.
TENKA_TERRITORIES_PER_ARMYconstantHow many territories held bring one army each turn: three.
TENKA_TERRITORY_CARD_BONUSconstantThe armies placed straight onto a territory the trader holds, when a card of the set shows it.
TENKA_TERRITORY_COUNTconstantHow many territories the world has: forty-two.
TENKA_TRADE_STEPconstantHow much more each set is worth than the last, once TENKA_TRADE_VALUES runs out: 20, 25, 30…
TENKA_TRADE_VALUESconstantWHAT A SET OF CARDS IS WORTH, by how many sets anybody has traded in before it: 4, 6, 8, 10, 12, 15, and five more for every set after that — the escalating standard schedule.
TENKA_VERSIONconstantThe version of this package, as package.json has it.
TENKA_WILDconstantThe kind of a wild card, which stands for whatever a set needs.
TENKA_WILD_CARDSconstantHow many wild cards are in the deck.
TENKA_WORLD_ROUNDSconstantThe whole world: played to the last player standing, and counted after sixty rounds if nobody is.
tenkaAgainfunctionThe same table again, from nothing, with a new seed: a new deal, a new first player, new dice.
TenkaCardtypeA territory's card (0–41) or a wild card (42, 43).
TenkaCardKindtypeWhat a card shows: one of three kinds, or a wild card that stands for any of them.
TenkaChoicetypeA choice made on the map and not yet a move: where from, where to, and how many armies (tapTerritory).
tenkaContinentfunctionA continent of a map by its key.
TenkaContinenttypeA continent: its name, the armies holding all of it is worth each turn, and its territories.
TenkaContinentKeytypeA continent of any map, by key: the world's continents and Europe's regions.
tenkaDailySeedfunctionToday's seed, the date as a number: 2026-10-01 is 20261001.
tenkaDayfunctionThe day a moment falls on, in UTC, written YYYY-MM-DD.
tenkaDeckForfunctionEvery card of a game on this map: a card for each territory, numbered as the territories are, then the wild cards.
TenkaEuropeRegionKeytypeEurope's eleven regions, by key: the continents of the Europe map.
tenkaExportedfunctionA game as the JSON export's object: its table, its moves, and where it stands.
TenkaExportedtypeA whole JSON export of one game: what tenkaToJSON writes and tenkaFromJSON reads.
tenkaFromJSONfunctionA game from JSON that tenkaToJSON wrote, or text that encodeTenka did.
TenkaGametypeA game, as its moves make it.
TenkaLocaletypeThe languages the package speaks: English and Japanese.
TenkaMaptypeA map as the rules read it: its territories, its continents and each territory's neighbours by land and by sea.
TenkaMapKeytypeThe maps a game may be played on.
TenkaMapMarkstypeWhat the map lights up for a choice (marksFor): the territory chosen, what it can reach, and the target.
tenkaMapOffunctionThe map a game is played on: the one it was started on, and the world for a game saved before there was a choice.
TenkaMovetypeA move, as playTenka takes it.
TenkaMoveKindtypeThe kinds of move, by name.
tenkaMovesfunctionEvery move the player to move may make now, each one playTenka accepts.
tenkaNeighboursfunctionA territory's neighbours, by land and by sea.
tenkaOverfunctionWhether the game is over.
TenkaOwnertypeWho holds a territory: a seat, or TENKA_NEUTRAL.
TenkaPhasetypeWhere a turn is.
TenkaPlacingtypeStarting armies placed at random, or by hand in turn.
tenkaPlayerNamefunctionA seat's name as the table reads it: the one given, or "Player 3".
tenkaRecordfunctionTHE RECORD OF A GAME, move by move, with the dice and everything else each move brought: made by playing the game again from its seed.
TenkaRecordEntrytypeOne move of a game's record, with what came of it: what the text and the CSV are written from.
TenkaRolltypeOne roll of the dice — or the last of a run of them (blitz) — what each side threw, highest first, and what each lost in all.
tenkaSayfunctionA line from a table of strings with its braces filled in: tenkaSay(strings.moveIn, { n: 3 }) is "Move 3 in".
TenkaSeattypeA player's place round the table: 0 for the first name given, up to 5.
TenkaShapestypeHow the world is drawn, in map units (tenkaShapes.data.ts, written by scripts/map.mjs).
tenkaStringsfunctionThe table of strings for a locale with a page's own words laid over it.
TenkaStringstypeEvery table word, including local embed error feedback.
TenkaTerritoryDatatypeOne territory as the map script writes it: neighbours by land and by sea are indices into the same list.
tenkaToCSVfunctionA game as CSV, a row to a move, for a spreadsheet: TENKA_CSV_COLUMNS.
tenkaToJSONfunctionA game as JSON, two spaces deep, with the format's number first.
tenkaToTextfunctionA game as plain text, a line to a move, for a chat or a log: who placed what where, every throw of the dice, every territory taken, and how it ended.
TenkaTradetypeThe last set of cards traded in, for the table to see: by whom, for how many, and the territory that got two more.
TenkaWorldContinentKeytypeThe world's six continents, by key.
territoriesHeldfunctionHow many territories an owner holds.
territoryNameInfunctionA territory's name in a table of strings, by its key (TENKA_TERRITORIES[n].key, such as "alaska"); "" for a key that is no territory's.
throwDicefunctioncount dice, highest first, and the state after them.
tradeValuefunctionWhat the next set traded in is worth, when trades sets have been traded before it: 4, 6, 8, 10, 12, 15, 20, 25…
writeTenkaMovefunctionA move as the short list it is kept as — and sent as, to the other devices at a table played on several.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/tenka 2.2.0.