From: Benjamin Auder Date: Tue, 26 May 2020 12:24:24 +0000 (+0200) Subject: Fix Koopa promotions with captures, and Balakhlava: pawns move forward X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/images/assets/current/doc/%7B%7B%20targetUrl%20%7D%7D?a=commitdiff_plain;h=f9f6716634c2faf722b174a9bab7f704a0e65f24;p=vchess.git Fix Koopa promotions with captures, and Balakhlava: pawns move forward --- diff --git a/client/src/variants/Balaklava.js b/client/src/variants/Balaklava.js index 3a04e1d0..4a720f04 100644 --- a/client/src/variants/Balaklava.js +++ b/client/src/variants/Balaklava.js @@ -61,8 +61,19 @@ export class BalaklavaRules extends ChessRules { : super.getPotentialMovesFrom([x, y]); if (piece != V.KING) { // Add non-capturing knight movements - const lastRank = (this.turn == 'w' ? 0 : 7); + const color = this.turn; + const lastRank = (color == 'w' ? 0 : 7); V.steps[V.KNIGHT].forEach(step => { + // Pawns cannot go backward: + if ( + piece == V.PAWN && + ( + (color == 'w' && step[0] > 0) || + (color == 'b' && step[0] < 0) + ) + ) { + return; + } const [i, j] = [x + step[0], y + step[1]]; if ( V.OnBoard(i, j) && diff --git a/client/src/variants/Koopa.js b/client/src/variants/Koopa.js index 8d4f0e97..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;