Reference · Redacted player and observer views
legalMovesForCurrentPlayerfunction
Legal move coordinates for the player whose turn it is; roles are never returned.
Import it
import { legalMovesForCurrentPlayer } from "@johnmorrisdotca/gunjin/views";
Also exported from: @johnmorrisdotca/gunjin
Definition
function legalMovesForCurrentPlayer(match: AuthoritativeMatch, player: Player): { from: Coordinate; to: Coordinate; }[]
Parameters
| Name | Type | Description |
|---|---|---|
match | AuthoritativeMatch | The full authoritative match, held by a trusted host or the local hotseat owner. |
player | Player | The acting player, 0 or 1; the lifecycle checks that this is the expected player. |
Returns
{ from: Coordinate; to: Coordinate; }[]
Legal move coordinates for the player whose turn it is; roles are never returned.
Examples
import type { Player } from "@johnmorrisdotca/gunjin";
import { createHasamiMatch, hasamiRoster, submitHasamiSetup } from "@johnmorrisdotca/gunjin/hasami";
import { acknowledgePass } from "@johnmorrisdotca/gunjin/stratego-lite";
import { legalMovesForCurrentPlayer } from "@johnmorrisdotca/gunjin/views";
const home=(player: Player)=>hasamiRoster(7).map((kind,x)=>({kind,x,y:player===0?6:0}));
const base=createHasamiMatch({width:7,height:7});
const firstSetup=submitHasamiSetup(base,0,home(0),base.setupStep);
let ready=acknowledgePass(firstSetup,1,firstSetup.turn);
ready=submitHasamiSetup(ready,1,home(1),ready.setupStep);
ready=acknowledgePass(ready,0,ready.turn);
console.log(legalMovesForCurrentPlayer(ready,0).length);35What it prints (run when this page was built)