リファレンス
ルール・地図・棋譜
import { … } from "@johnmorrisdotca/tenka";
最小化と gzip 圧縮をしたサイズは 14.9 kB(読み込むものをすべて含み、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.
エクスポート
| 名前 | 種類 | 概要 |
|---|---|---|
areNeighbours | 関数 | Whether two territories are neighbours, by land or by sea. |
armiesHeld | 関数 | How many armies an owner has on the map. |
attacksOpen | 関数 | Every 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. |
battleLosses | 関数 | WHO LOSES WHAT: the highest die of each side compared, then the next highest, as many pairs as the side with fewer dice threw. |
beginTurn | 関数 | A turn starting for seat: its armies worked out, nothing yet taken, nothing rolled. |
boardOf | 関数 | The 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. |
cardKind | 関数 | What a card shows: land, sea or air for a territory's card, in turn round the map; wild for a wild card. |
cardTerritory | 関数 | The territory a card shows, or null for a wild card. |
choiceNow | 関数 | A choice made on an earlier map, read against this one: only what still stands, and a number of armies the move can take. |
cleanTenkaName | 関数 | A name as the table typed it, tidied: spaces run together, trimmed, cut to TENKA_NAME_MOST. |
connectedOwn | 関数 | Every territory of the same owner reachable from this one through that owner's own territories, in order; never the territory itself. |
continentNameIn | 関数 | A continent's name in a table of strings, by its key ("northAmerica", "asia"…). |
continentsHeld | 関数 | The continents a seat holds every territory of. |
counted | 関数 | THE 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. |
decodeTenka | 関数 | A 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. |
defendDice | 関数 | The dice a defender holding armies throws: as many as allowed, since more never hurts the defence. |
encodeTenka | 関数 | A game as text to keep: its table and its moves. |
endOfTurn | 関数 | THE END OF A TURN: a card for a player who took a territory in it, then the next player still in. |
finished | 関数 | The game ended, with these seats winning. |
isSet | 関数 | Whether 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). |
isTenkaSeed | 関数 | Whether a number is a seed a game can be dealt from: a whole number from 0 to TENKA_SEED_MOST. |
isTenkaTable | 関数 | Whether a game this long for this many players is one Tenka is offered for. |
isTerritory | 関数 | Whether a number is a territory of the map. |
isWild | 関数 | Whether a card is one of the two wild cards. |
marksFor | 関数 | What the map lights up for a choice. |
mostAttackDice | 関数 | The most dice an attacker may throw from a territory holding armies: one army always stays behind. |
mustTrade | 関数 | Whether the player to move must trade cards before anything else: five or more in hand while reinforcing. |
nextRandom | 関数 | The next number from the random at state, in [0, 1), and the state after it. |
nextSeatIn | 関数 | The next player still in after seat, round the table; the neutral army never takes a turn. |
NO_CHOICE | 定数 | Nothing chosen: where a turn, and a table, start. |
playTenka | 関数 | The 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. |
randomBelow | 関数 | A whole number from 0 to below - 1, and the state after it. |
readTenkaMove | 関数 | A kept move read back, or null for anything that is not one. |
reinforcementFor | 関数 | THE ARMIES A TURN BRINGS: one for every three territories held, never fewer than three, and each continent held whole adds its bonus. |
replayTenka | 関数 | A game made again from its table and its moves, or null if any move could not have been made when it was. |
sensibleTenkaMove | 関数 | The computer player's move: one the rules accept, chosen as a person might. |
setsIn | 関数 | Every set a hand holds, each as its three cards smallest first, in order. |
shuffled | 関数 | A list in a random order (Fisher and Yates), and the state after it; the list given is left alone. |
startTenka | 関数 | A 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. |
tapTerritory | 関数 | What tapping territory does now: a new choice, and the move to make at once, if the tap is one. |
TENKA_ATTACK_DICE | 定数 | The most dice an attacker throws. |
TENKA_CARD_KINDS | 定数 | The three kinds a territory's card shows, in turn round the map, and the wild card that is any of them. |
TENKA_CONTINENTS | 定数 | The world's six continents, each with the territories in it. |
TENKA_CSV_COLUMNS | 定数 | The columns of the CSV export, in order. |
TENKA_DECK | 定数 | Every card in the game: the territories' cards, then the wild cards. |
TENKA_DEFEND_DICE | 定数 | The most dice a defender throws. |
TENKA_EXPORT_FORMAT | 定数 | The shape of the JSON this package writes. |
TENKA_FEWEST_PLAYERS | 定数 | The fewest at a table: two, joined by the neutral army. |
TENKA_LEAST_REINFORCEMENT | 定数 | The fewest armies a turn brings, however little is held. |
TENKA_LENGTHS | 定数 | The lengths of game startTenka takes, in rounds: 10, 20 and 60. |
TENKA_MAP_LIST | 定数 | The maps in the order a set-up offers them: the world first, the usual one. |
TENKA_MAPS | 定数 | Every map a game may be played on, by key. |
TENKA_MEDIUM_ROUNDS | 定数 | The medium game: twenty rounds, then the count. |
TENKA_MOST_PLAYERS | 定数 | The most at a table: six. |
TENKA_MOVES | 定数 | The kinds of move, by name: what goes in a move's kind. |
TENKA_MUST_TRADE_AT | 定数 | With this many cards in hand a player must trade before placing; after knocking somebody out, down to fewer than this. |
TENKA_NAME_MOST | 定数 | The longest name a seat keeps. |
TENKA_NEUTRAL | 定数 | The owner of the territories nobody at a table of two holds: the neutral army, which never takes a turn. |
TENKA_PHASES | 定数 | The phases of a turn, by name: compare game.phase with these rather than with text typed out. |
TENKA_PLACING | 定数 | How the starting armies are placed: scattered at random (auto), or by the players in turn (hand). |
TENKA_SEED_MOST | 定数 | The largest seed a game keeps: the random's state is one 32-bit number. |
TENKA_SHORT_ROUNDS | 定数 | The short game: ten rounds, then the count. |
TENKA_STARTING_ARMIES | 定数 | THE ARMIES EACH PLAYER STARTS WITH, by how many are playing: the standard table. |
TENKA_STRINGS | 定数 | The package's words in each language it speaks: TENKA_STRINGS.en, TENKA_STRINGS.ja. |
TENKA_TERRITORIES | 定数 | The world's territories: the map a game is played on unless it says otherwise. |
TENKA_TERRITORIES_PER_ARMY | 定数 | How many territories held bring one army each turn: three. |
TENKA_TERRITORY_CARD_BONUS | 定数 | The armies placed straight onto a territory the trader holds, when a card of the set shows it. |
TENKA_TERRITORY_COUNT | 定数 | How many territories the world has: forty-two. |
TENKA_TRADE_STEP | 定数 | How much more each set is worth than the last, once TENKA_TRADE_VALUES runs out: 20, 25, 30… |
TENKA_TRADE_VALUES | 定数 | WHAT 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_VERSION | 定数 | The version of this package, as package.json has it. |
TENKA_WILD | 定数 | The kind of a wild card, which stands for whatever a set needs. |
TENKA_WILD_CARDS | 定数 | How many wild cards are in the deck. |
TENKA_WORLD_ROUNDS | 定数 | The whole world: played to the last player standing, and counted after sixty rounds if nobody is. |
tenkaAgain | 関数 | The same table again, from nothing, with a new seed: a new deal, a new first player, new dice. |
TenkaCard | 型 | A territory's card (0–41) or a wild card (42, 43). |
TenkaCardKind | 型 | What a card shows: one of three kinds, or a wild card that stands for any of them. |
TenkaChoice | 型 | A choice made on the map and not yet a move: where from, where to, and how many armies (tapTerritory). |
tenkaContinent | 関数 | A continent of a map by its key. |
TenkaContinent | 型 | A continent: its name, the armies holding all of it is worth each turn, and its territories. |
TenkaContinentKey | 型 | A continent of any map, by key: the world's continents and Europe's regions. |
tenkaDailySeed | 関数 | Today's seed, the date as a number: 2026-10-01 is 20261001. |
tenkaDay | 関数 | The day a moment falls on, in UTC, written YYYY-MM-DD. |
tenkaDeckFor | 関数 | Every card of a game on this map: a card for each territory, numbered as the territories are, then the wild cards. |
TenkaEuropeRegionKey | 型 | Europe's eleven regions, by key: the continents of the Europe map. |
tenkaExported | 関数 | A game as the JSON export's object: its table, its moves, and where it stands. |
TenkaExported | 型 | A whole JSON export of one game: what tenkaToJSON writes and tenkaFromJSON reads. |
tenkaFromJSON | 関数 | A game from JSON that tenkaToJSON wrote, or text that encodeTenka did. |
TenkaGame | 型 | A game, as its moves make it. |
TenkaLocale | 型 | The languages the package speaks: English and Japanese. |
TenkaMap | 型 | A map as the rules read it: its territories, its continents and each territory's neighbours by land and by sea. |
TenkaMapKey | 型 | The maps a game may be played on. |
TenkaMapMarks | 型 | What the map lights up for a choice (marksFor): the territory chosen, what it can reach, and the target. |
tenkaMapOf | 関数 | The map a game is played on: the one it was started on, and the world for a game saved before there was a choice. |
TenkaMove | 型 | A move, as playTenka takes it. |
TenkaMoveKind | 型 | The kinds of move, by name. |
tenkaMoves | 関数 | Every move the player to move may make now, each one playTenka accepts. |
tenkaNeighbours | 関数 | A territory's neighbours, by land and by sea. |
tenkaOver | 関数 | Whether the game is over. |
TenkaOwner | 型 | Who holds a territory: a seat, or TENKA_NEUTRAL. |
TenkaPhase | 型 | Where a turn is. |
TenkaPlacing | 型 | Starting armies placed at random, or by hand in turn. |
tenkaPlayerName | 関数 | A seat's name as the table reads it: the one given, or "Player 3". |
tenkaRecord | 関数 | THE 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. |
TenkaRecordEntry | 型 | One move of a game's record, with what came of it: what the text and the CSV are written from. |
TenkaRoll | 型 | One 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. |
tenkaSay | 関数 | A line from a table of strings with its braces filled in: tenkaSay(strings.moveIn, { n: 3 }) is "Move 3 in". |
TenkaSeat | 型 | A player's place round the table: 0 for the first name given, up to 5. |
TenkaShapes | 型 | How the world is drawn, in map units (tenkaShapes.data.ts, written by scripts/map.mjs). |
tenkaStrings | 関数 | The table of strings for a locale with a page's own words laid over it. |
TenkaStrings | 型 | Every table word, including local embed error feedback. |
TenkaTerritoryData | 型 | One territory as the map script writes it: neighbours by land and by sea are indices into the same list. |
tenkaToCSV | 関数 | A game as CSV, a row to a move, for a spreadsheet: TENKA_CSV_COLUMNS. |
tenkaToJSON | 関数 | A game as JSON, two spaces deep, with the format's number first. |
tenkaToText | 関数 | A 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. |
TenkaTrade | 型 | The last set of cards traded in, for the table to see: by whom, for how many, and the territory that got two more. |
TenkaWorldContinentKey | 型 | The world's six continents, by key. |
territoriesHeld | 関数 | How many territories an owner holds. |
territoryNameIn | 関数 | A 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. |
throwDice | 関数 | count dice, highest first, and the state after them. |
tradeValue | 関数 | What the next set traded in is worth, when trades sets have been traded before it: 4, 6, 8, 10, 12, 15, 20, 25… |
writeTenkaMove | 関数 | A move as the short list it is kept as — and sent as, to the other devices at a table played on several. |
この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。