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
| Name | Type | Description |
|---|---|---|
state | GameState | The game as it stands. A new object after every move that changed it. |
choices | TurnChoices | null | What the player to move may do, or null when there is no set of moves to show. See |
play | (point: Point, kind?: MoveKind, colour?: Stone | null) => void | Places a stone at |
move | (from: Point, to: Point) => void | Moves a piece: |
place | (cells: readonly PieceCell[]) => void | Lays a queued piece on these cells: |
twist | (quadrant: number, clockwise: boolean) => void | Turns a quadrant to finish a twist game's move: |
pass | () => void | Passes the turn where the rules allow it: |
undo | () => void | Takes back the last move, where there is one to take back. |
canUndo | boolean | |
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));