X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKnightrelay.js;h=daa7bbb8cca1e974dd5043b985068dab828c0635;hp=8ccd0e2188a97d1a55bc35d8a5b6841b7ea3490e;hb=8055eabd23feaabe878b25522929c7273dcb0f24;hpb=d1be804633f9632b35662c0b10743ca50e10030f diff --git a/client/src/variants/Knightrelay.js b/client/src/variants/Knightrelay.js index 8ccd0e21..daa7bbb8 100644 --- a/client/src/variants/Knightrelay.js +++ b/client/src/variants/Knightrelay.js @@ -5,7 +5,8 @@ export const VariantRules = class KnightrelayRules extends ChessRules { let moves = super.getPotentialMovesFrom([x, y]); // Expand possible moves if guarded by a knight: - if (this.getPiece(x,y) != V.KNIGHT) { + const piece = this.getPiece(x,y); + if (piece != V.KNIGHT) { const color = this.turn; let guardedByKnight = false; for (const step of V.steps[V.KNIGHT]) { @@ -19,12 +20,24 @@ export const VariantRules = class KnightrelayRules extends ChessRules { } } if (guardedByKnight) { + const lastRank = color == "w" ? 0 : V.size.x - 1; for (const step of V.steps[V.KNIGHT]) { if ( V.OnBoard(x+step[0],y+step[1]) && this.getColor(x+step[0],y+step[1]) != color ) { - moves.push(this.getBasicMove([x,y], [x+step[0],y+step[1]])); + // Potential promotions: + const finalPieces = piece == V.PAWN && x + step[0] == lastRank + ? [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN] + : [V.PAWN]; + for (let p of finalPieces) { + moves.push( + this.getBasicMove([x,y], [x+step[0],y+step[1]], { + c: color, + p: p + }) + ); + } } } }