Skip to the content

Narabe並べ

Play forty-eight abstract board games through immutable moves, legal choices and replayable records.

Narabe means arranging in Japanese, as in gomoku-narabe: five in a row. About the name

Contents

Reference

Rules and records

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

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

Narabe 並べ: one rules engine for forty-eight abstract board games.

Every game is a row of data (VARIANT_SPECS), and every function takes a GameState and returns a new one. Start with createGame, play with playMove, movePiece, placePiece, twistBoard or passTurn, and ask turnChoices what the player to move may do. Records are plain move lists: replayMoves and replayGame read them back, undoMove steps one back.

Deeper pieces (each rule module on its own) are reachable by path as well, for example @johnmorrisdotca/narabe/rules/go.

Exports

NameKindWhat it is
ALL_BOARD_SIZESconstantEvery size any game here is played on, for the schemas at the API edge.
availableOpeningsfunctionThe openings these settings may use: what the variant offers, less the colour-swapping ones when a handicap is bound to a colour — and only the free opening under a head start.
BlockedtypeAn intersection the rules have taken out of play.
BLOCKEDconstantThe unavailable-cell marker.
BOARD_GRIDSconstantWhere a game's stones sit when it is drawn its own way: on the crossings, or in the squares.
BOARD_SIZESconstantBoard is size × size.
BoardGridtypeWhere a game's stones sit when it is drawn the way it is traditionally played: on the crossings of the lines, as in go and gomoku, or inside the squares, as in tic-tac-toe, Othello and checkers.
boardSizesForfunctionThe board sizes a variant plays on, smallest first — the order they are drawn in.
BRAZILIAN_DRAUGHTS_RULESconstantBrazilian draughts: the international rules of capture and crowning on 8×8, with twelve men, and the draws of the Brazilian confederation's own rules (CBJD, Regras Oficiais) rather than the FMJD's 8×8 set, which differs.
campOffunctionWhose home camp point lies in, or null for the open board.
campSizefunctionPieces a side has on size: the squares of its camp.
campSquaresfunctionThe squares of a colour's home camp.
CANADIAN_CHECKERS_RULESconstantCanadian checkers: the international rules on 12×12, thirty men a side in five rows.
canBeDrawnfunctionWhether this game can be drawn at all.
canChooseColourfunctionWhether the game is waiting on a seat to pick a colour.
canExtendOpeningfunctionSwap2 only: the first chooser may add two stones and pass the choice back.
canForfeitfunctionWhether a recorded forfeit could have been written here: only where the clock had no pass to write instead.
canGrowBoardfunctionWhether resizing is enabled and a larger native board is available.
canPassfunctionWhether passing is on offer: forced in a piece game with nothing to lay, free at any point in Go.
canShrinkBoardfunctionWhether resizing is enabled and a smaller native board is available.
canSkipfunctionWhether skipping is enabled and a legal corner stone can burn the turn.
canSwapSeatsfunctionWhether the seat to play may trade seats right now.
canTwistfunctionWhether the colour to move owes a quarter turn before the move is complete.
canUndofunctionWhether undo is enabled and a recorded move can be removed.
CAPTURE_CHOICESconstantThe free-choice and maximum-capture draughts modes.
CaptureChoicetypeWhich capture a checkers-family player may choose, when more than one is on offer.
capturePathsfunctionThe squares each capture has passed through so far, move by move, or null for a move that took nothing.
CelltypeOne intersection of the board: a stone, an obstacle, a hotspot, a wormhole, or nothing.
cellAtfunctionRead a cell from a valid zero-based board point; null means empty.
centreSquaresfunctionThe four centre squares, top-left first.
checkersHasCapturefunctionWhether any of stone's pieces on the board has a capture available right now.
CheckersRulestypeHow one game of the checkers family is played, as data: the rows of men each side sets out, which way a man may take, how far a king may travel, which capture must be chosen, and what crowning does to a capture under way.
chooseColourfunctionThe deciding seat takes stone.
ColourRulestypeThe rules one colour actually plays under: the variant's spec for that colour with the handicap laid over it.
COLUMN_LETTERSconstantColumn letters used in coordinate labels, left to right.
columnLetterfunctionColumn letter, left to right: A, B, C ...
createGamefunctionCreate an initial immutable position from native settings and an opening roll.
CROWN_MID_CAPTUREconstantThe supported promotion behavior during a capture chain.
CrownMidCapturetypeWhat becomes of a man that reaches the far row in the middle of a capture.
DEFAULT_BOARD_SIZEconstantThe default side length for an unconstrained board.
DEFAULT_CAPTURES_TO_WINconstantEnemy stones to capture for a win in the capture game: five pairs.
DEFAULT_SETTINGSconstantThe defaults used when creating a game without overrides.
DEFAULT_SWAPS_PER_SEATconstantThe default seat-swap allowance for each player.
defaultBoardForfunctionThe board a game OPENS on, where nothing else has said: its own defaultBoard if it has one, else the first of its boards.
DIRECTIONSconstantThe four line orientations through a point.
discCountfunctionCount black and white discs currently on a board.
DRAW_LIMIT_LISTconstantThe selectable configured game-length limits.
DRAW_LIMIT_MIN_POINTSconstantThe smallest board a length means anything on, in points.
DRAW_LIMIT_SHAREconstantThe board fractions used by configured draw limits.
DRAW_LIMITSconstantThe shares of the board a game may be called a draw at.
DrawLimittypeWhen a game nobody has won is called a draw.
drawnByLengthfunctionWhether a finished game was drawn because it ran to its length, rather than because the board filled or both sides made a line at once.
dropTargetfunctionWhere a stone dropped into col lands, or null when the column is full.
emptyPointsfunctionEvery intersection still open: no stone, no obstacle.
endedWithNoMovesfunctionWhether the game ended because neither side had a move: two forced passes, the last two moves on the record.
ENDGAME_COUNT_KINDSconstantThe specific-ending and material-balance draw count modes.
EndgameCounttypeAn ending that must be won within so many moves or it is a draw, once each player has made movesEach more moves inside it.
EndgameCountKindtypeThe two shapes an endgame count is written in — see EndgameCount.
endsOnItsOwnfunctionWhether the rules alone guarantee this game ends.
ENGLISH_CHECKERS_RULESconstantEnglish draughts, American checkers: three rows of men, a man takes forward only, a king moves one square, any capture may be chosen, and a man crowned by a capture ends the move there.
extendOpeningfunctionThe chooser declines to choose and lays two more stones instead.
findWinningLinefunctionThe winning line through point, if the stone there completes one under the rule that applies to its colour.
FIRST_PLAYERSconstantThe supported opening colours and random opener choice.
FIRST_STONEconstantBlack opens unless the settings say otherwise.
FirstPlayertypeWho opens.
flipsAtfunctionThe discs a stone of stone at point would turn.
footprintAtfunctionThe absolute cells of an orientation anchored with its origin at anchor.
footprintFitsfunctionWhether every cell of a footprint is on the board and empty.
FORBIDDEN_PATTERNSconstantThe named forbidden shapes checked by line games.
forbiddenAtfunctionWhy stone may not play point, or null when it may.
ForbiddenPatterntypeShapes a colour may be forbidden from making.
forbiddenPointsfunctionEvery empty point the colour to move is forbidden from playing right now.
forbiddenReasonfunctionWhy the colour to move may not play point, when a forbidden shape is why.
forfeitOnRecordfunctionA missed turn, as the position the record will replay it to.
forfeitTurnfunctionTakes the turn away from the colour to move without a stone: the graceful penalty for a missed deadline.
GAME_STATUSconstantThe playing, won and drawn outcome labels.
GameSettingstypeNative rule, layout, opening, handicap and optional action settings.
GameStatetypeThe complete immutable position and its move history, seats and outcome.
GameStatustypeWhether the game is playing, won or drawn.
groupAtfunctionThe connected group of stones sharing the colour at from, and the empty points touching any of them — its liberties.
growBoardfunctionReturns the game on a larger board, or the state unchanged when it cannot grow.
HandicaptypeExtra restrictions one colour plays under, so a stronger player can give a weaker one a fair game.
HANDICAP_RULESconstantThe handicap toggles, in the order the settings list them.
HandicapRuletypeThe toggles of a handicap, without the colour that carries them.
HandicapTermstypeEVERYTHING THAT MAKES A GAME UNEVEN ON PURPOSE, as hasHandicap reads it: the per-colour handicap and the head start.
hasFlipMovefunctionWhether the colour has a legal disc-flipping move.
hasHandicapfunctionWhether any handicap is in force for anyone: harder rules for one colour, or a head start for one.
HEAD_START_FREE_TURNSconstantThe free turns a head start may give, none included.
HeadStarttypeA start given to one colour — the weaker player's — before the game is even.
HeadStartTurnstypeThe most free turns a game offers as a head start: 0 where it offers none.
HEX_LINE_DIRECTIONSconstantThe three line orientations on the hexagon lattice — see rules/hexagon.ts for the embedding.
HottypeA hotspot: an intersection that counts as either colour's stone in a line.
HOTconstantThe cell marker that counts as either colour in a line.
indexOffunctionConvert a board point into its row-major array index.
inLayingPhasefunctionClassic reversi: the first four discs are laid by the players, in the centre, with no flipping.
inMovePhasefunctionWhether the colour to move has all its pieces down and must now slide one.
INTERNATIONAL_DRAUGHTS_RULESconstantInternational draughts, from the FMJD's official rules (Annex 1, 2018, and the 2024 Annexes).
isDarkSquarefunctionCheckers is played on one colour of square only: the board's own dark squares.
isKingAtfunctionWhether the piece at at, if any, is a king.
isLegalMovefunctionWhether the colour to move may play point: on the board, empty, allowed by the opening, not a shape the variant forbids that colour, the landing cell of its column in a drop game, and not while a twist or a slide is owed.
isOnBoardfunctionWhether both coordinates are within the square board.
isStonefunctionNarrows a cell to a played stone, excluding empties and obstacles.
KOMIconstantGo: stones never move once played, and nothing about a line ever decides anything.
landingPointsfunctionThe one landing cell per column with room: the only cells a drop can fill.
lastMovefunctionThe point of the latest stone or piece move; null when no point was played.
leavesNoStonefunctionWhether a recorded move put nothing on the board: a pass, or a turn the clock took away.
legalPointsfunctionEvery intersection the colour to move may play right now.
LINE_RULESconstantThe at-least, exact and open-exact winning line modes.
lineDirectionsForfunctionThe directions a winning line may run: the hexagon's three axes on a hexagon board, the square's four otherwise.
LineRuletypeWhat a completed line has to look like to win.
longestPossibleGamefunctionThe most moves a game of these settings can contain, or null when nothing in the rules bounds it.
MovetypeA move rebuilt by the engine, including captures and other replay effects.
MOVE_KINDSconstantThe stable labels used in move records.
MOVE_NARROWINGSconstantThe reasons a move list is restricted to captures.
MoveInputtypeThe shape of a move as a record or a request carries it, without the colour.
MoveKindtypeplace: an ordinary stone.
MoveNarrowingtypeA rule that has narrowed the moves on offer below what the pieces could make: a capture that must be made, or carried on, instead of a step; or — where the game takes the most — the capture taking the most pieces, over shorter ones the pieces also have.
movePiecefunctionSlides a piece one step, or in checkers a step or a capture.
movesBeforeDrawfunctionHow many moves may be played before a game nobody has won is a draw, or null when it is to be played out.
mustPassfunctionWhether the colour to move has nothing it may play.
nextBoardSizefunctionThe next size up, or null when the board is already the largest.
NO_HANDICAPconstantThe default terms with no colour-bound rule restrictions.
NO_HEAD_STARTconstantNobody given a start: the even game, which is most games.
NO_POINTconstantA pass has no point on the board.
noBoundReasonfunctionWhat stops this game being bounded by its board, or null when nothing does.
NoBoundReasontypeWhy a game has no bound, or null when the board is its bound.
normaliseSettingsfunctionSettings that agree with their variant: a pinned line length wins over the player's choice, an opening the variant does not offer falls back to free, and a handicap rules out the openings that swap colours.
OBSTACLE_LAYOUTSconstantThe native empty and star-point obstacle layouts.
ObstacleLayouttypenone: every intersection is playable.
OPENING_CHOICE_EXTENDconstantThe one opening choice that is not a colour.
OPENING_RULE_LISTconstantAll supported opening identifiers in display order.
OPENING_RULESconstantThe stable identifiers for supported opening protocols.
OPENING_STAGESconstantThe stages of the opening protocol.
OpeningChoicetypeA decision taken during the opening: a colour, or two more stones.
OpeningRuletypeHow the first stones go down.
OpeningStagetypeWhere a swap-style opening stands.
OpeningStatetypeThe opening protocol stage, acting seat and recorded colour choices.
orientationsfunctionEvery distinct way the piece can lie: four rotations, each also mirrored.
orientCellsfunctionThe piece turned turns quarter turns and, if asked, mirrored — the shape a player has in hand.
otherStonefunctionThe other stone colour.
passesOwedfunctionThe position after every pass the rules force: none when the colour to move has something to play, one when only it is stuck, and two — ending the game — when neither side can move.
passTurnfunctionTakes a turn without a stone.
PiecetypeA piece from the queue: its cells relative to the top-left of its bounding box.
PIECE_PREVIEWconstantHow many queued pieces a player is shown ahead of the one in hand.
PIECE_QUEUESconstantThe domino and tetromino queue identifiers.
PieceCelltypeOne cell of a multi-cell piece, with the colour it carries.
pieceMovesfunctionWhere a piece of the colour to move may step from from; empty if it may not move.
piecePlacementsfunctionEvery legal footprint of the piece in hand.
PieceQueuetypeWhich queue of pieces a game draws from.
piecesHomefunctionHow many of stone's pieces stand in the far camp.
PieceTallytypeA side's pieces, as an endgame count names them.
PlacementtypeWhere a stone goes when played.
PLACEMENTSconstantThe free, dropped and supported-edge placement modes.
placePiecefunctionLays the piece in hand on cells.
playMovefunctionPlays the stone to move at point.
PointtypeZero-based board coordinates.
pointNamefunctionRenju-style name for an intersection, e.g.
pointOffunctionConvert a row-major array index into board coordinates.
POOL_CHECKERS_RULESconstantPool checkers, from the American Pool Checker Association's Tournament Rules of Play (2016): men take both ways (rule 14), kings fly (15, 18), any capture may be chosen — "not compelled to take the greater or lesser number" (20) — and a capture once begun is completed (21).
previousBoardSizefunctionThe next size down, or null when the board is already the smallest.
quadrantCountfunctionHow many quadrants a board of this size holds.
quadrantOriginfunctionThe top-left corner of quadrant quadrant.
queuedPiecefunctionThe piece the colour to move must lay next, or null outside the piece games.
ReplayFactstypeWhat a replay needs to know about a record that its moves cannot say.
replayGamefunctionThe position as it stands now.
replayMovesfunctionReplays a record through the engine: every position it passed through, including the ones a swap-opening decision produced.
replayTimelinefunctionRebuilds every position a game passed through by replaying its moves.
resignfunctionGives the game up.
resolveOpenerfunctionThe colour that opens.
resolvePlacementfunctionWhere a stone played at point actually goes: the same point, or in a drop game the bottom of its column.
rowNumberfunctionRow number counted from the bottom edge, so the bottom row is 1.
RULE_VARIANT_LISTconstantThe variants in the order the browser and the filters list them.
RULE_VARIANTSconstantThe stable identifiers for all forty-eight rule variants.
rulesForfunctionThe rules a colour plays under: the variant's spec for that colour, with the handicap laid over it when the handicap belongs to that colour.
RuleVarianttypeThe named rule sets.
RUSSIAN_DRAUGHTS_RULESconstantRussian draughts (shashki), from the Russian Draughts Federation's rules (ФШР, shashki.ru) and the FMJD/IDF rules for 8×8 draughts: men take both ways, kings fly, any capture may be chosen whatever it takes (FMJD-64 4.13), and a man that reaches the far row in the middle of a capture is crowned there and carries on capturing as a king (4.14).
scoreAreafunctionThe area score: every stone on the board, plus every empty region whose only neighbours are one colour.
SeattypeThe two people at the board.
seatOffunctionThe seat holding stone right now.
SEATSconstantThe first and second player seat labels.
seatToPlayfunctionThe seat whose turn it is.
SECOND_STONE_EXCLUSIONSconstantHalf-widths of the central square a handicapped second stone must leave.
SEED_RANGEconstantSeeds are 31-bit integers, small enough for every store and reproducible everywhere.
seededRandomfunctionA small seeded random number generator, so anything a game decides by chance — where the dead squares fall, which pieces come next — is fixed by the seed stored with the game and comes out the same on every replay.
shrinkBoardfunctionReturns the game on a smaller board, or the state unchanged when the ring that would be removed is in use.
singlesLeftfunctionSingle stones the colour to move may still lay instead of a piece.
sizeForVariantfunctionThe board this variant will actually be played on, given a size somebody asked for.
skipMovefunctionBurns the turn on a corner stone.
skipTargetfunctionWhere a skipped turn puts its stone: the open intersection furthest from the action, picked from the corner chosen by roll.
SlideMovetypeWhat a record needs of a move to say whether it slid, jumped, or went on jumping.
slideWordfunctionA slide as the draughts records write it: square to square with an arrow, a capture with a colon (g5:e3), and a multi-jump as every square it landed on (g5:e3:c1).
STAR_POINTSconstantHoshi (star point) positions drawn on the board, by board size: the four corner points, plus tengen at the centre, and for 19×19 the side points too.
STAR_RADIUSconstantHow many rows deep each of the star's six points is.
starCampOffunctionWhose home point point lies in, or null outside both.
starCampSizefunctionPieces a side has: the cells of one point, ten on the standard board.
starPiecesHomefunctionHow many of stone's pieces stand in the far point.
starSizefunctionThe side of the square array a star of this radius is embedded in.
STARTING_DISCSconstantThe fixed, laid or absent starting-disc layouts.
StartingDiscstypeHow a flipping game begins: nothing, the fixed four, or four the players lay themselves.
StonetypeOne of the two stone colours.
STONELESS_WORDSconstantHow a written move list says the two moves that have no point.
stonelessWordfunctionHow a written record says a move with no point, or null for a move that has one.
STONESconstantThe black and white stone labels.
stonesLeftfunctionStones the colour to move still has to place before the turn passes.
StoredGametypeThe stored shape of a game, as both the API and the pages see it.
swapSeatsfunctionTrades seats: the player to move hands over their colour and takes the opponent's stones instead.
TRADITIONAL_HEAD_STARTSconstantThe traditional head starts, see TraditionalHeadStart.
TraditionalHeadStarttypeThe head start a game's own tradition gives a weaker player, where it has one: Go's handicap stones on the star points, Othello's corners, and draughts' piece odds, the men taken off the stronger side before the start.
TURN_CHOICE_KINDSconstantThe piece-moving and stone-placement choice modes.
TurnChoiceKindtypeWhether a turn moves a piece already on the board, or places on a point.
turnChoicesfunctionWhat the colour to move may do this turn — every piece that has a move, or every point that may be played — and whether a rule narrowed it.
TurnChoicestypeWhat the colour to move may do this turn, as the engine answers it — see turnChoices.
turnPassedByfunctionThe colour whose turn passed because it had no move, as the latest turn left the board — or null when nobody's did.
TwisttypeA quarter turn of one quadrant, which ends a move in the twist games.
twistBoardfunctionTurns one quadrant to finish the move.
undoMovefunctionRemoves the last move, putting back anything it captured, a piece where it came from, and a twisted quadrant the way it was.
upcomingPiecesfunctionThe pieces after the one in hand, for the preview.
VARIANT_SPECSconstantEvery rule set, as data.
VariantSpectypeOne rule set, as data.
WIN_LENGTHconstantStones in a line needed to win, unless a variant pins it.
WIN_LENGTHSconstantLine lengths a player may pick in the variants that leave it open.
WIN_REASONSconstantThe recorded reasons a game is won.
winOnTimefunctionEnds the game against a player who has run out of time.
WinReasontypeHow a won game was won.
WormtypeA wormhole: a line entering it comes out of its partner and carries on.
WORMconstantThe linked wormhole-cell marker.
WRAP_MODESconstantThe supported board edge-wrapping modes.
WrapModetypeWhich edges of the board join up: a plane, a cylinder, or a torus.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/narabe 1.3.0.