X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKoopa.js;h=bc72d6df8ad11692dbf67ee910c6d3d5c74b9250;hb=13227d6124e1cf465d329373e32c407d6fd351d3;hp=f24e5b2f995f74855bb2471074dcd7a1fdbfade9;hpb=6e0f28425075e6d2d79cab6d30bca6ce6d55f19d;p=vchess.git diff --git a/client/src/variants/Koopa.js b/client/src/variants/Koopa.js index f24e5b2f..bc72d6df 100644 --- a/client/src/variants/Koopa.js +++ b/client/src/variants/Koopa.js @@ -49,11 +49,9 @@ export class KoopaRules extends ChessRules { } getStunnedFen() { - return ( - Object.keys(this.stunned) - .map(square => square + this.stunned[square]) - .join(",") - ); + const squares = Object.keys(this.stunned); + if (squares.length == 0) return "-"; + return squares.map(square => square + this.stunned[square]).join(","); } // Base GenRandInitFen() is fine because en-passant indicator will @@ -80,7 +78,7 @@ export class KoopaRules extends ChessRules { this.INIT_COL_KING["w"] = k; break; default: { - const num = parseInt(fenRows[i].charAt(j)); + const num = parseInt(fenRows[i].charAt(j), 10); if (!isNaN(num)) k += num - 1; } } @@ -100,7 +98,7 @@ export class KoopaRules extends ChessRules { .map(s => { return { square: s.substr(0, 2), - state: parseInt(s[2]) + state: parseInt(s[2], 10) }; }); } @@ -186,7 +184,10 @@ export class KoopaRules extends ChessRules { m.appear[0].x = i; m.appear[0].y = j; // Is it a pawn on last rank? - if ((color == 'w' && i == 0) || (color == 'b' && i == 7)) { + if ( + m.appear[0].p == V.PAWN && + ((color == 'w' && i == 0) || (color == 'b' && i == 7)) + ) { m.appear[0].p = V.ROOK; for (let ppiece of [V.KNIGHT, V.BISHOP, V.QUEEN]) { let mp = JSON.parse(JSON.stringify(m)); @@ -234,9 +235,10 @@ export class KoopaRules extends ChessRules { // Base method is fine because a stunned king (which won't be detected) // can still castle after going back to normal. super.postPlay(move); - const kIdx = move.vanish.findIndex(v => v.p == "l"); + const kIdx = move.vanish.findIndex( + (v,i) => v.p == 'l' || (i >= 1 && v.p == 'k')); if (kIdx >= 0) - // A stunned king vanish (game over) + // A (stunned or not) king vanish: game over this.kingPos[move.vanish[kIdx].c] = [-1, -1]; move.stunned = JSON.stringify(this.stunned); // Array of stunned stage 1 pieces (just back to normal then) @@ -267,9 +269,10 @@ export class KoopaRules extends ChessRules { postUndo(move) { super.postUndo(move); - const kIdx = move.vanish.findIndex(v => v.p == "l"); + const kIdx = move.vanish.findIndex( + (v,i) => v.p == 'l' || (i >= 1 && v.p == 'k')); if (kIdx >= 0) { - // A stunned king vanished + // A king vanished this.kingPos[move.vanish[kIdx].c] = [move.vanish[kIdx].x, move.vanish[kIdx].y]; }