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 · React hook

NarabeGametype

A React game state and its native move, replay and reset actions.

Import it

import type { NarabeGame } from "@johnmorrisdotca/narabe/react";

Definition

type NarabeGame = {
    state: GameState;
    choices: TurnChoices | null;
    play: (point: Point, kind?: MoveKind, colour?: Stone | null) => void;
    move: (from: Point, to: Point) => void;
    place: (cells: readonly PieceCell[]) => void;
    twist: (quadrant: number, clockwise: boolean) => void;
    pass: () => void;
    undo: () => void;
    canUndo: boolean;
    reset: (settings?: Partial<GameSettings>) => void;
};

Members

NameTypeDescription
stateGameState

The game as it stands. A new object after every move that changed it.

choicesTurnChoices | null

What the player to move may do, or null when there is no set of moves to show. See turnChoices.

play(point: Point, kind?: MoveKind, colour?: Stone | null) => void

Places a stone at point: playMove. colour is for the games where the mover chooses it.

move(from: Point, to: Point) => void

Moves a piece: movePiece.

place(cells: readonly PieceCell[]) => void

Lays a queued piece on these cells: placePiece.

twist(quadrant: number, clockwise: boolean) => void

Turns a quadrant to finish a twist game's move: twistBoard.

pass() => void

Passes the turn where the rules allow it: passTurn.

undo() => void

Takes back the last move, where there is one to take back.

canUndoboolean
reset(settings?: Partial<GameSettings>) => void

Starts again, with these settings or the ones this game began with.

Examples

import { createElement } from "react";
import { useNarabe, type NarabeGame } from "@johnmorrisdotca/narabe/react";
function Board() {
  const game: NarabeGame = useNarabe({variant:"reversi"});
  return createElement("p",null,game.state.toPlay);
}
console.log(createElement(Board));

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