UNPKG

shogiops

Version:
61 lines 1.86 kB
import { Hands } from '../hands.js'; import { opposite } from '../util.js'; import { Position } from './position.js'; import { standardBoard, standardDropDests, standardMoveDests, standardSquareAttacks, standardSquareSnipers, } from './shogi.js'; export class Checkshogi extends Position { constructor() { super('checkshogi'); } static default() { const pos = new this(); pos.board = standardBoard(); pos.hands = Hands.empty(); pos.turn = 'sente'; pos.moveNumber = 1; return pos; } static from(setup, strict) { const pos = new this(); pos.fromSetup(setup); return pos.validate(strict).map((_) => pos); } squareAttackers(square, attacker, occupied) { return standardSquareAttacks(square, attacker, this.board, occupied); } squareSnipers(square, attacker) { return standardSquareSnipers(square, attacker, this.board); } moveDests(square, ctx) { return standardMoveDests(this, square, ctx); } dropDests(piece, ctx) { return standardDropDests(this, piece, ctx); } isSpecialVariantEnd(ctx) { ctx = ctx || this.ctx(); return ctx.checkers.nonEmpty(); } outcome(ctx) { ctx = ctx || this.ctx(); if (this.isSpecialVariantEnd(ctx)) return { result: 'specialVariantEnd', winner: opposite(ctx.color), }; else if (this.isStalemate(ctx)) { return { result: 'stalemate', winner: opposite(ctx.color), }; } else if (this.isDraw(ctx)) { return { result: 'draw', winner: undefined, }; } else return; } } //# sourceMappingURL=checkshogi.js.map