X-Git-Url: https://git.auder.net/assets/current/gitweb.css?a=blobdiff_plain;f=base_rules.js;h=4627eb78e34aef0a152fc7009ae67fc644cb0cdf;hb=0e466aac11288f35b34d744b2652c7b4e9df2e24;hp=11b8b30fbaffc43958bcab57d2bfd8fa23123e28;hpb=b9877ed29697640d72b8f3d89848863fc87bd7e8;p=xogo.git diff --git a/base_rules.js b/base_rules.js index 11b8b30..4627eb7 100644 --- a/base_rules.js +++ b/base_rules.js @@ -779,8 +779,8 @@ export default class ChessRules { piece = "k"; //capturing cannibal king: back to king form const oldCount = this.reserve[color][piece]; this.reserve[color][piece] = count; - // Redrawing is much easier if count==0 - if ([oldCount, count].includes(0)) + // Redrawing is much easier if count==0 (or undefined) + if ([oldCount, count].some(item => !item)) this.re_drawReserve([color]); else { const numId = this.getReserveNumId(color, piece); @@ -1341,7 +1341,13 @@ export default class ChessRules { } getStepSpec(color, x, y, piece) { - return this.pieces(color, x, y)[piece || this.getPieceType(x, y)]; + let pieceType = piece; + const allSpecs = this.pieces(color, x, y); + if (!piece) + pieceType = this.getPieceType(x, y); + else if (allSpecs[piece].moveas) + pieceType = allSpecs[piece].moveas; + return allSpecs[pieceType]; } // Can thing on square1 capture thing on square2? @@ -2340,14 +2346,13 @@ export default class ChessRules { } postPlay(move) { - const color = this.turn; if (this.options["dark"]) this.updateEnlightened(); if (this.options["teleport"]) { if ( this.subTurnTeleport == 1 && move.vanish.length > move.appear.length && - move.vanish[1].c == color + move.vanish[1].c == this.turn ) { const v = move.vanish[move.vanish.length - 1]; this.captured = {x: v.x, y: v.y, c: v.c, p: v.p}; @@ -2357,8 +2362,12 @@ export default class ChessRules { this.subTurnTeleport = 1; this.captured = null; } + this.tryChangeTurn(move); + } + + tryChangeTurn(move) { if (this.isLastMove(move)) { - this.turn = C.GetOppCol(color); + this.turn = C.GetOppCol(this.turn); this.movesCount++; this.subTurn = 1; }