X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKoopa.js;h=dbce84217e674fd077364880f95e4a63c6d91a70;hb=6d596afc7305916de4c7f9b6f29e3f0fcfe009cf;hp=3f2e855ad2ddf5965067498f996074907afcbd7d;hpb=e50a802531b99829c533f22ecd21e359e7e1e049;p=vchess.git diff --git a/client/src/variants/Koopa.js b/client/src/variants/Koopa.js index 3f2e855a..dbce8421 100644 --- a/client/src/variants/Koopa.js +++ b/client/src/variants/Koopa.js @@ -184,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)); @@ -232,10 +235,16 @@ 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"); - if (kIdx >= 0) - // A stunned king vanish (game over) - this.kingPos[move.vanish[kIdx].c] = [-1, -1]; + const color = this.turn; + const kp = this.kingPos[color]; + if ( + this.board[kp[0], kp[1]] == V.EMPTY || + !['k', 'l'].includes(this.getPiece(kp[0], kp[1])) || + this.getColor(kp[0], kp[1]) != color + ) { + // King didn't move by itself, and vanished => game over + this.kingPos[color] = [-1, -1]; + } move.stunned = JSON.stringify(this.stunned); // Array of stunned stage 1 pieces (just back to normal then) Object.keys(this.stunned).forEach(square => { @@ -265,11 +274,12 @@ export class KoopaRules extends ChessRules { postUndo(move) { super.postUndo(move); - const kIdx = move.vanish.findIndex(v => v.p == "l"); - if (kIdx >= 0) { - // A stunned king vanished - this.kingPos[move.vanish[kIdx].c] = - [move.vanish[kIdx].x, move.vanish[kIdx].y]; + const oppCol = V.GetOppCol(this.turn); + if (this.kingPos[oppCol][0] < 0) { + // Opponent's king vanished + const psq = + move.vanish.find((v,i) => i >= 1 && ['k', 'l'].includes(v.p)); + this.kingPos[oppCol] = [psq.x, psq.y]; } this.stunned = JSON.parse(move.stunned); for (let i=0; i<8; i++) {