X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKnightrelay1.js;h=aba952905069a08367310accc078c9a4da5139f9;hb=9a1e3abe33fff07218b17c7c799eb622a730b7c7;hp=626519cd9a38784c0048c5ed9f95e70bf9428fe4;hpb=2c5d7b20742b802d9c47916915c1114bcfc9a9c3;p=vchess.git diff --git a/client/src/variants/Knightrelay1.js b/client/src/variants/Knightrelay1.js index 626519cd..aba95290 100644 --- a/client/src/variants/Knightrelay1.js +++ b/client/src/variants/Knightrelay1.js @@ -1,11 +1,24 @@ import { ChessRules } from "@/base_rules"; export class Knightrelay1Rules extends ChessRules { + static get HasEnpassant() { 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]); @@ -139,4 +152,5 @@ export class Knightrelay1Rules extends ChessRules { return notation; } + };