Reference · Boards, rules and challenges
undofunction
Returns the previous position, or the same game when history is empty.
Import it
import { undo } from "@johnmorrisdotca/tobiishi";
Definition
function undo(game: Game): Game
Parameters
| Name | Type | Description |
|---|---|---|
game | Readonly<{ board: Board; start: readonly boolean[]; pegs: readonly boolean[]; target: number | null; history: readonly Jump[]; helped: boolean; }> | The immutable native peg position, board, target, history and assistance marker. |
Returns
Readonly<{ board: Board; start: readonly boolean[]; pegs: readonly boolean[]; target: number | null; history: readonly Jump[]; helped: boolean; }>
Returns the previous position, or the same game when history is empty. The game’s target is null when any final hole is permitted.
Examples
import { jumpAt, makeBoard, newGame, pegCount, undo } from "@johnmorrisdotca/tobiishi";
const board = makeBoard("Three holes",[{x:0,y:0},{x:1,y:0},{x:2,y:0}]);
const game = newGame(board,[true,true,false],2);
console.log(pegCount(undo(jumpAt(game,0,2))));2What it prints (run when this page was built)