X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FCheckered1.js;h=71f9b920f28e6a5dea0073db3206fcd834b4c689;hb=7e8a7ea1cb66adb4a987badfb0a3c2f99a21bd0a;hp=47e7375e19126758077997fca0f6110dfc9e33e0;hpb=e50a802531b99829c533f22ecd21e359e7e1e049;p=vchess.git diff --git a/client/src/variants/Checkered1.js b/client/src/variants/Checkered1.js index 47e7375e..71f9b920 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; @@ -487,31 +491,6 @@ export class Checkered1Rules extends ChessRules { this.postPlay(move); } - updateCastleFlags(move, piece) { - const c = V.GetOppCol(this.turn); - const firstRank = (c == "w" ? V.size.x - 1 : 0); - // Update castling flags if rooks are moved - const oppCol = this.turn; - const oppFirstRank = V.size.x - 1 - firstRank; - if (piece == V.KING && move.appear.length > 0) - this.castleFlags[c] = [V.size.y, V.size.y]; - else if ( - move.start.x == firstRank && //our rook moves? - this.castleFlags[c].includes(move.start.y) - ) { - const flagIdx = (move.start.y == this.castleFlags[c][0] ? 0 : 1); - this.castleFlags[c][flagIdx] = V.size.y; - } - // NOTE: not "else if" because a rook could take an opposing rook - if ( - move.end.x == oppFirstRank && //we took opponent rook? - this.castleFlags[oppCol].includes(move.end.y) - ) { - const flagIdx = (move.end.y == this.castleFlags[oppCol][0] ? 0 : 1); - this.castleFlags[oppCol][flagIdx] = V.size.y; - } - } - postPlay(move) { if (move.appear.length == 0 && move.vanish.length == 0) { this.stage = 2; @@ -524,7 +503,7 @@ export class Checkered1Rules extends ChessRules { this.kingPos[c][0] = move.appear[0].x; this.kingPos[c][1] = move.appear[0].y; } - this.updateCastleFlags(move, piece); + 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) this.pawnFlags[move.start.x == 6 ? "w" : "b"][move.start.y] = false; @@ -609,7 +588,7 @@ export class Checkered1Rules extends ChessRules { } static GenRandInitFen(randomness) { - // Add 16 pawns flags + empty cmovei + stage == 1: + // Add 16 pawns flags + empty cmove + stage == 1: return ChessRules.GenRandInitFen(randomness) .slice(0, -2) + "1111111111111111 - - 1"; } @@ -700,4 +679,5 @@ export class Checkered1Rules extends ChessRules { notation += "=" + move.appear[0].p.toUpperCase(); return notation; } + };