X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKoopa.js;h=57d19b929f92e4decffa8aceee8a4667829f66f0;hb=c3ff3a0c807d97c0311a06491318fe02440266db;hp=dbce84217e674fd077364880f95e4a63c6d91a70;hpb=6d596afc7305916de4c7f9b6f29e3f0fcfe009cf;p=vchess.git diff --git a/client/src/variants/Koopa.js b/client/src/variants/Koopa.js index dbce8421..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; }); }