X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKnightrelay1.js;h=0afa9aa21793342f2d23aeb93cafa2e065471d99;hb=ded43c88fad60fd8f9bb46aabd67f3f2092f65f3;hp=1e7bfabb8fd0d09d77eb05c388835a8f6c1726ca;hpb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;p=vchess.git diff --git a/client/src/variants/Knightrelay1.js b/client/src/variants/Knightrelay1.js index 1e7bfabb..0afa9aa2 100644 --- a/client/src/variants/Knightrelay1.js +++ b/client/src/variants/Knightrelay1.js @@ -6,7 +6,19 @@ export class Knightrelay1Rules extends ChessRules { return false; } - // TODO: IsGoodPosition to check that 2 knights are on the board... + static IsGoodPosition(position) { + if (!ChessRules.IsGoodPosition(position)) return false; + // Check that (at least) 2 knights per side are on the board + const rows = position.split("/"); + let knights = { 'N': 0, 'n': 0 }; + for (let row of rows) { + for (let i = 0; i < row.length; i++) { + if (['N','n'].includes(row[i])) knights[row[i]]++; + } + } + if (Object.values(knights).some(v => v < 2)) return false; + return true; + } getPotentialMovesFrom([x, y]) { let moves = super.getPotentialMovesFrom([x, y]); @@ -61,7 +73,7 @@ export class Knightrelay1Rules extends ChessRules { // Check if a (non-knight) piece at knight distance // is guarded by a knight (and thus attacking) - // --> Except for pawns targetting last rank. + // --> Except for kings, and pawns targetting last rank. const x = sq[0], y = sq[1]; // Last rank for me, that is to say oppCol of color: @@ -72,7 +84,10 @@ export class Knightrelay1Rules extends ChessRules { this.getColor(x+step[0],y+step[1]) == color ) { const piece = this.getPiece(x+step[0],y+step[1]); - if (piece != V.KNIGHT && (piece != V.PAWN || x != lastRank)) { + if ( + ![V.KNIGHT, V.KING].includes(piece) && + (piece != V.PAWN || x != lastRank) + ) { for (const step2 of V.steps[V.KNIGHT]) { const xx = x+step[0]+step2[0], yy = y+step[1]+step2[1];