movePiecefunction
Slides a piece one step, or in checkers a step or a capture. Illegal moves return the state unchanged.
Import it
import { movePiece } from "@johnmorrisdotca/narabe";
Definition
function movePiece(state: GameState, from: Point, to: Point): GameState
Parameters
| Name | Type | Description |
|---|---|---|
state | GameState | The current immutable game position. |
from | Point | The source point of the group or moving piece. |
to | Point | The destination point of the moving piece. |
Returns
GameState
The resulting position; a refused or inapplicable action leaves the input position unchanged.
Examples
import { createGame, movePiece } from "@johnmorrisdotca/narabe";
const checkers = createGame({variant:"checkers"});
console.log(movePiece(checkers,{row:5,col:0},{row:4,col:1}).moves.length);0What it prints (run when this page was built)