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=be3fb7b5de79dc2295d41b593faf18c6ed895e0d;hp=1d1ab5277c41267b1cce201f5223f0d1275e886c;hpb=32f6285ee325a14286562a53baefc647201df2af;p=vchess.git diff --git a/client/src/variants/Knightrelay1.js b/client/src/variants/Knightrelay1.js index 1d1ab527..aba95290 100644 --- a/client/src/variants/Knightrelay1.js +++ b/client/src/variants/Knightrelay1.js @@ -1,10 +1,25 @@ import { ChessRules } from "@/base_rules"; export class Knightrelay1Rules extends ChessRules { + static get HasEnpassant() { return false; } + 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]); @@ -97,7 +112,7 @@ export class Knightrelay1Rules extends ChessRules { return { p: 1, r: 5, - n: 7, //the knight is valuable + n: 0, //the knight isn't captured - value doesn't matter b: 3, q: 9, k: 1000 @@ -118,7 +133,8 @@ export class Knightrelay1Rules extends ChessRules { const finalSquare = V.CoordsToSquare(move.end); const piece = this.getPiece(move.start.x, move.start.y); - // Since pieces and pawns could move like knight, indicate start and end squares + // Since pieces and pawns could move like knight, + // indicate start and end squares let notation = piece.toUpperCase() + initSquare + @@ -136,4 +152,5 @@ export class Knightrelay1Rules extends ChessRules { return notation; } + };