X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FMagnetic.js;h=8adb1babd4cbcc5b75f3ba27674c5bd9ab4b2ad3;hb=26b8e4f7c71030d49e44fe1d89632ef91b886d67;hp=6682b2709682d419b6c474f1131e94374ef1cc53;hpb=fb6ceeff17b53ab049e14d2bee7a61de92ca4762;p=vchess.git diff --git a/public/javascripts/variants/Magnetic.js b/public/javascripts/variants/Magnetic.js index 6682b270..8adb1bab 100644 --- a/public/javascripts/variants/Magnetic.js +++ b/public/javascripts/variants/Magnetic.js @@ -2,14 +2,6 @@ class MagneticRules extends ChessRules { static get HasEnpassant() { return false; } - setOtherVariables(fen) - { - // No en-passant: - const parsedFen = V.ParseFen(fen); - this.setFlags(fenParsed.flags); - this.scanKingsRooks(fen); - } - getPotentialMovesFrom([x,y]) { let standardMoves = super.getPotentialMovesFrom([x,y]); @@ -24,67 +16,6 @@ class MagneticRules extends ChessRules return moves; } - getPotentialPawnMoves([x,y]) - { - const color = this.turn; - let moves = []; - const [sizeX,sizeY] = [V.size.x,V.size.y]; - const shift = (color == "w" ? -1 : 1); - const firstRank = (color == 'w' ? sizeX-1 : 0); - const startRank = (color == "w" ? sizeX-2 : 1); - const lastRank = (color == "w" ? 0 : sizeX-1); - - if (x+shift >= 0 && x+shift < sizeX && x+shift != lastRank) - { - // Normal moves - if (this.board[x+shift][y] == V.EMPTY) - { - moves.push(this.getBasicMove([x,y], [x+shift,y])); - // Next condition because variants with pawns on 1st rank allow them to jump - if ([startRank,firstRank].includes(x) && this.board[x+2*shift][y] == V.EMPTY) - { - // Two squares jump - moves.push(this.getBasicMove([x,y], [x+2*shift,y])); - } - } - // Captures - if (y>0 && this.board[x+shift][y-1] != V.EMPTY - && this.canTake([x,y], [x+shift,y-1])) - { - moves.push(this.getBasicMove([x,y], [x+shift,y-1])); - } - if (y { - // Normal move - if (this.board[x+shift][y] == V.EMPTY) - moves.push(this.getBasicMove([x,y], [x+shift,y], {c:pawnColor,p:p})); - // Captures - if (y>0 && this.board[x+shift][y-1] != V.EMPTY - && this.canTake([x,y], [x+shift,y-1])) - { - moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:pawnColor,p:p})); - } - if (y= 2 && move.vanish[1].p == V.KING) { // We took opponent king ! - const oppCol = this.getOppCol(c); + const oppCol = V.GetOppCol(c); this.kingPos[oppCol] = [-1,-1]; this.castleFlags[oppCol] = [false,false]; } // Did we magnetically move our (init) rooks or opponents' ones ? const firstRank = (c == "w" ? 7 : 0); const oppFirstRank = 7 - firstRank; - const oppCol = this.getOppCol(c); + const oppCol = V.GetOppCol(c); move.vanish.forEach(psq => { if (psq.x == firstRank && this.INIT_COL_ROOK[c].includes(psq.y)) this.castleFlags[c][psq.y==this.INIT_COL_ROOK[c][0] ? 0 : 1] = false; @@ -254,8 +175,8 @@ class MagneticRules extends ChessRules unupdateVariables(move) { super.unupdateVariables(move); - const c = this.getColor(move.start.x,move.start.y); - const oppCol = this.getOppCol(c); + const c = move.vanish[0].c; + const oppCol = V.GetOppCol(c); if (this.kingPos[oppCol][0] < 0) { // Last move took opponent's king