X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKoopa.js;h=57d19b929f92e4decffa8aceee8a4667829f66f0;hp=c7b0859f1c389061695955d6bc3fddbada972570;hb=f9f6716634c2faf722b174a9bab7f704a0e65f24;hpb=78a75d54a18dec6dcedeeba98e5f67645d2edd51 diff --git a/client/src/variants/Koopa.js b/client/src/variants/Koopa.js index c7b0859f..57d19b92 100644 --- a/client/src/variants/Koopa.js +++ b/client/src/variants/Koopa.js @@ -118,7 +118,17 @@ export class KoopaRules extends ChessRules { } getPotentialMovesFrom([x, y]) { - let moves = super.getPotentialMovesFrom([x, y]); + let moves = super.getPotentialMovesFrom([x, y]).filter(m => { + if ( + m.vanish[0].p != V.PAWN || + m.appear[0].p == V.PAWN || + m.vanish.length == 1 + ) { + return true; + } + // Pawn promotion, "capturing": remove duplicates + return m.appear[0].p == V.QUEEN; + }); // Complete moves: stuns & kicks let promoteAfterStun = []; const color = this.turn; @@ -205,18 +215,28 @@ export class KoopaRules extends ChessRules { return moves.concat(promoteAfterStun); } + getPotentialKingMoves(sq) { + return ( + this.getSlideNJumpMoves( + sq, + V.steps[V.ROOK].concat(V.steps[V.BISHOP]), + "oneStep" + ).concat(super.getCastleMoves(sq, true, ['r'])) + ); + } + filterValid(moves) { // Forbid kicking own king out const color = this.turn; return moves.filter(m => { - const kingAppear = m.appear.some(a => a.c == color && a.p == V.KING); - return m.vanish.every(v => { - return ( - v.c != color || - !["k", "l"].includes(v.p) || - (v.p == "k" && kingAppear) - ); - }); + const kingVanish = + m.vanish.some(v => v.c == color && ['k', 'l'].includes(v.p)); + if (kingVanish) { + const kingAppear = + m.appear.some(a => a.c == color && ['k', 'l'].includes(a.p)); + return kingAppear; + } + return true; }); } @@ -235,10 +255,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 => { @@ -268,11 +294,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++) {