Reference
Rules, games and records
import { … } from "@johnmorrisdotca/sugoroku";
11.6 kB minified and gzipped, with everything it imports (measured with esbuild)
Pure backgammon and variant rules, legal turns, cube and match scoring, dice, records and computer choices.
Exports
| Name | Kind | What it is |
|---|---|---|
agreeDraw | function | The game drawn by agreement. |
allHome | function | Whether every checker of side still in play is in its home board (own points 1 to 6): the condition for bearing off. |
applyMove | function | The position after a move. |
BAR | constant | The number a move's from has when a checker comes from the bar (or from off the board at the start of a race). |
beaverDouble | function | Beaver: the side that was doubled redoubles and keeps the cube; the side that doubled must now take it or drop it. |
boardPoint | function | The point on the board, 1 to 24 counting the way white counts, that is side's own point own. |
canBeaver | function | Whether the side that was doubled may beaver: redouble at once and keep the cube. |
canDouble | function | Whether the side on turn may offer a double now. |
canPlayAll | function | Whether every die of need (highest first) can be played from position, in some order. |
chanceOfWinning | function | The chance, 0 to 1, that side wins from here, by the evaluation, or by the Keith count's rule of thumb in a race (as 0.5 plus a share of the count's lead). |
checkersOf | function | The whole count of each side's checkers: on the board, on the bar, yet to enter, and off. |
choosePlay | function | The play the computer makes for the rest of the turn of the side on turn, from the plays the rules leave it. |
computerAction | function | What the side that has to act in a game would do, if the computer were playing it. |
ComputerAction | type | What the computer does next in a game, for the side it plays. |
ComputerOptions | type | Strength, tie-breaking randomness, lookahead time budget and evaluation weights for computer decisions. |
concede | function | Give up the game: side loses. |
concedeKind | function | What a side gives up if it gives up the game now, which is the worst the position could come to: a single game once it has borne a checker off; a gammon if nothing of the other side's can still hit it; otherwise a backgammon where it may have a checker caught in the other side's home board. |
countAt | function | How many of side's checkers stand on its own point own (1 to 24). |
Cube | type | The doubling cube: what it shows, and who may turn it (null while it stands in the middle, for either). |
CUBE_LIMIT | constant | The most the cube can show. |
cubeInPlay | function | Whether the cube is in play in a game of a match, given whether this is the Crawford game. |
cubeIsDead | function | The cube is dead when turning it could not matter: it already shows enough for either side to win the match with a win. |
DEFAULT_RULES | constant | The rules a variant is played with when nothing else is asked: a single game with no cube and no gammons. |
diceMustPlay | function | WHICH DICE MUST BE PLAYED. |
DiceSource | type | Where dice come from: each call is the number on one die, 1 to 6. |
diceToPlay | function | The dice a roll gives to play, highest first: a double of a game that plays doubles four times is four of them. |
Direction | type | How the sides' tracks lie on the board. |
dropDouble | function | Drop the double that was offered: the side that drops it loses the game, at the cube's value before the double, or for a beaver at its value once the double was taken. |
endTurn | function | End the side on turn's turn, once everything it had to play has been played. |
evaluate | function | The score of a position for side, with the other side to move, as a game where bearing off first wins. |
evaluateFor | function | The score as side plays to win or to lose: a game played to lose is judged the other way up. |
EVALUATION_WEIGHTS | constant | The weights the computer plays with: set by hand and then held against random changes of themselves, none of which won more often over two thousand games. |
EvaluationWeights | type | The numbers the evaluation is made of, each a number of pips. |
finishGame | function | The match after a game's result: the score added up, the Crawford game accounted for, and the match over if it is decided. |
formatMove | function | One move as text: 24/18, bar/22*, 6/off. |
formatOpening | function | One line of a game: the opening throw. |
formatPlay | function | The text of a whole turn: moves of one checker joined, equal moves counted, the farthest-back checker first. |
formatPosition | function | A position as text, for any variant: each side's checkers as point:count in that side's own numbering, highest point first, then the bar, those yet to enter and those borne off, [white, black] each. |
formatRecordHeader | function | The header lines of a record: its version, the variant, the rules and the seed. |
formatResult | function | The line that closes a game, with what it came to. |
formatTurn | function | One line of a game: a turn, with its dice and its play. |
GameRecorder | class | A record written as a game is played. |
GameResult | type | The decided winner, ending, win kind, cube multiplier and points. |
GameState | type | The immutable game phase, board, dice, remaining moves, cube and optional result. |
Goal | type | What it takes to win. |
hashSeed | function | A whole number from a seed given as a number or as text: the same seed is always the same number, in every browser and every Node. |
Hop | type | A step of a written play: one checker, one die's distance (or off), as written. |
HowItEnded | type | How a game came to its end. |
inContact | function | Whether the two sides can still hit one another. |
inPlay | function | Every checker of side that is still in the game: on the board, on the bar or yet to enter. |
isVariantKey | function | Whether key names a variant. |
keithCount | function | The Keith count of a side, a pip count corrected for how badly the checkers are placed for bearing off: plus 2 for each checker beyond the first on the 1-point, 1 for each beyond the first on the 2-point and beyond three on the 3-point, and 1 for each empty point among the 4, 5 and 6, and then the side on roll adds a seventh (rounded down). |
legalMoves | function | The moves the side on turn may make next. |
legalPlays | function | Every different turn a side may make with a roll: one for each position that playing the roll as the rules require can leave, with one way of getting there. |
legalPlaysOf | function | Every different way the side on turn may play out the rest of its turn: for the dice it has yet to play, from where the position stands now. |
Match | type | A MATCH: games played one after another to a number of points, or without end in money play. |
mirrorPoint | function | The other side's own number for the point that is side's own point own. |
Move | type | ONE CHECKER MOVED BY ONE DIE, in the mover's own numbering: from its own point from (or the BAR, 25, for a checker entering from the bar or from off the board at the start of a race) to its own point to (0 for borne off). |
movesOfDie | function | Every move of one die that side may make from position, one for each point a checker can start from. |
multiplierOf | function | What a win of kind is worth, after the rules: a single win when gammons do not count, or when the Jacoby rule holds them back because the cube was never turned. |
newGame | function | A new game, waiting for the opening throw. |
NewGameOptions | type | Options for a new game. |
newMatch | function | A match at 0 to 0. |
nextMoves | function | The moves that may be made next, by a side that still has the dice need (highest first) to play from position: every move that leaves the rest of need playable. |
offerDouble | function | Offer a double: the other side must now take it or drop it. |
onBoard | function | How many checkers side has on the board's points, not counting the bar, the reserve and those borne off. |
Opening | type | How a game is opened. |
openingFrom | function | An opening throw from a source: one die for white and one for black. |
opponentAt | function | How many of the other side's checkers stand on the point that is side's own point own. |
otherSide | function | The other side. |
parseHops | function | The hops a written play names, in the order written: a chain of three points is two hops, and 13/11(2) is two. |
parsePlay | function | The moves a written play makes with a roll, or null if it is not a legal play of that roll. |
parsePosition | function | The position that text of formatPosition's kind stands for, or null if it is not one. |
Phase | type | Where a game has got to. |
pipCount | function | The pip count of a side: the sum of every checker's distance from being borne off. |
Play | type | A WHOLE TURN: the moves a side makes with a roll, in the order it makes them, and the position they leave. |
playMove | function | Make one move for the side on turn, given as the checker's own point it leaves and the one it goes to. |
playMoves | function | The position after a list of moves, made one after another. |
playTurn | function | Make a whole play (the moves of legalPlays) for the side on turn and end the turn. |
POINTS | constant | The points on the board. |
pointsToGo | function | How many points a side still needs to win the match: 0 in money play, where there is no such thing. |
Position | type | WHERE THE CHECKERS ARE. |
positionFromId | function | The position an ID stands for, with onRoll to move, or null if the text is not an ID. |
positionId | function | The ID of a position with onRoll to move, or null if it cannot be written in this form. |
positionKey | function | A position as a short string that is the same for the same position, for keeping a set of them. |
Preset | type | A NAMED WAY OF PLAYING: a variant with its rules. |
presetByKey | function | The preset with this key, or undefined. |
presetByName | function | The preset a site's printed name leads to, or undefined. |
PRESETS | constant | Every named way of playing, in the order of docs/VARIANTS.md. |
Random | type | A source of random numbers from 0 up to but not including 1. |
randomDice | function | Dice that are not seeded: from the device's own random numbers. |
RECORD_VERSION | constant | The record format's version, the number after sugoroku on the first line. |
RecordSeed | type | A seed in a record: all digits means a number, anything else is text. |
ReplayedGame | type | One game of a replayed record, finished. |
ReplayError | type | A refused record with its one-based line number and reason. |
ReplayOk | type | A successfully validated record, its settings, completed games and optional current game. |
replayRecord | function | Replay a record against the rules. |
resolveRules | function | The rules with anything left out filled from DEFAULT_RULES. |
restartTurn | function | Take back every move of the turn. |
rollDice | function | Roll the dice for the side on turn, which must not be waiting on an answer to a double. |
rollFrom | function | A roll of count dice from a source. |
rollOpening | function | The opening throw: one die for white and one for black. |
Rules | type | HOW A GAME IS SCORED AND STAKED, beside the variant's board. |
rulesProblems | function | What goes wrong with a set of rules, as sentences; empty when they are fine. |
seededDice | function | A SEEDED DICE SEQUENCE: the same seed is the same dice, one die after another, in every browser and every Node, so a game can be played again from its seed and a server can tell whether the dice a game says it had are the dice it should have had. |
seededRandom | function | The mulberry32 stream: the same seed makes the same numbers everywhere. |
Settings | type | The settings of a game: the variant's row and the rules. |
settingsFor | function | Settings from a variant key (or a row) and rules, left-out rules filled in. |
Side | type | THE TWO SIDES. |
sideIndex | function | 0 for white and 1 for black: where a side's counts are kept in a position. |
SIDES | constant | Both sides, white first. |
sideToAct | function | Whether a side is the one the computer would act for at this moment of a game: the side on turn, or the side that must answer a double. |
startCounts | function | Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1). |
startGame | function | The first game, or the next game, of a match. |
startPosition | function | The position a variant starts from. |
startReserve | function | How many checkers each side begins off the board, to be entered with the dice. |
stepComputer | function | Carry out one step of what the computer would do, with dice from dice. |
Strength | type | THE COMPUTER PLAYER, in four strengths. |
STRENGTHS | constant | The strengths, weakest first. |
takeDouble | function | Take the double that was offered. |
turnIsPlayed | function | Whether the turn is played out and the side on turn has only to end it. |
undoMove | function | Take back the last move made this turn. |
VARIANT_KEYS | constant | The variants' keys, in the order the demo lists them. |
VariantKey | type | THE VARIANTS, AS ROWS OF SETTINGS. |
VARIANTS | constant | Every variant. |
variantSpec | function | The row for a variant. |
VariantSpec | type | A native variant’s checker counts, starting layout, dice, directions, opening and winning goal. |
VERSION | constant | The package's version. |
wantsToDouble | function | Whether the computer, to move before it rolls, should offer a double. |
wantsToTake | function | Whether the computer, doubled, should take. |
winChance | function | A chance of winning, 0 to 1, that a score in pips stands for: the logistic curve, which a lead of 25 pips in a position of this kind takes to about three in four. |
winKind | function | The kind of win a game that winner has won by bearing off is: single, gammon or backgammon, before the rules say what they count for. |
WinKind | type | What kind of win it was, which is how many times the cube's value it scores. |
withCounts | function | A copy of a position with some counts changed. |