X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered1.js;h=2451f9b50c5e7bed349c43ea8361c545ea5f72a1;hb=d807470f965d4d60a7fe6e1320ac7dfd3f0ea03f;hp=4556f07b3f6cf2fe0c0c7aee91598a4971eee5e8;hpb=a9e1202b681d9d2f814767180183a0b04c58f8ab;p=vchess.git diff --git a/client/src/variants/Checkered1.js b/client/src/variants/Checkered1.js index 4556f07b..2451f9b5 100644 --- a/client/src/variants/Checkered1.js +++ b/client/src/variants/Checkered1.js @@ -1,6 +1,7 @@ import { ChessRules, Move, PiPo } from "@/base_rules"; export class Checkered1Rules extends ChessRules { + static board2fen(b) { const checkered_codes = { p: "s", @@ -131,7 +132,7 @@ export class Checkered1Rules extends ChessRules { ); } - getPotentialMovesFrom([x, y]) { + getPotentialMovesFrom([x, y], noswitch) { let standardMoves = super.getPotentialMovesFrom([x, y]); if (this.stage == 1) { const color = this.turn; @@ -141,7 +142,10 @@ export class Checkered1Rules extends ChessRules { // King is treated differently: it never turn checkered if (this.getPiece(x, y) == V.KING) { // If at least one checkered piece, allow switching: - if (this.board.some(b => b.some(cell => cell[0] == 'c'))) { + if ( + !noswitch && + this.board.some(b => b.some(cell => cell[0] == 'c')) + ) { const oppCol = V.GetOppCol(color); moves.push( new Move({ @@ -328,7 +332,7 @@ export class Checkered1Rules extends ChessRules { ) ) ) { - const moves = this.getPotentialMovesFrom([i, j]); + const moves = this.getPotentialMovesFrom([i, j], "noswitch"); if (moves.length > 0) { for (let k = 0; k < moves.length; k++) if (this.filterValid([moves[k]]).length > 0) return true; @@ -500,9 +504,14 @@ export class Checkered1Rules extends ChessRules { this.kingPos[c][1] = move.appear[0].y; } super.updateCastleFlags(move, piece); - // Does this move turn off a 2-squares pawn flag? - if ([1, 6].includes(move.start.x) && move.vanish[0].p == V.PAWN) + if ( + [1, 6].includes(move.start.x) && + move.vanish[0].p == V.PAWN && + Math.abs(move.end.x - move.start.x) == 2 + ) { + // This move turns off a 2-squares pawn flag this.pawnFlags[move.start.x == 6 ? "w" : "b"][move.start.y] = false; + } } this.cmoves.push(this.getCmove(move)); } @@ -675,4 +684,5 @@ export class Checkered1Rules extends ChessRules { notation += "=" + move.appear[0].p.toUpperCase(); return notation; } + };