X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FMagnetic.js;h=8adb1babd4cbcc5b75f3ba27674c5bd9ab4b2ad3;hb=26b8e4f7c71030d49e44fe1d89632ef91b886d67;hp=d6cf918cf51d7cdcea1665c0c112033363bdf50c;hpb=aea1443ebf56afb2c507c2830ac6b67b509778bc;p=vchess.git diff --git a/public/javascripts/variants/Magnetic.js b/public/javascripts/variants/Magnetic.js index d6cf918c..8adb1bab 100644 --- a/public/javascripts/variants/Magnetic.js +++ b/public/javascripts/variants/Magnetic.js @@ -1,9 +1,6 @@ class MagneticRules extends ChessRules { - getEpSquare(move) - { - return undefined; //no en-passant - } + static get HasEnpassant() { return false; } getPotentialMovesFrom([x,y]) { @@ -14,15 +11,15 @@ class MagneticRules extends ChessRules if (newMove_s.length == 1) moves.push(newMove_s[0]); else //promotion - moves = moves.concat(moves, newMove_s); + moves = moves.concat(newMove_s); }); return moves; } // Complete a move with magnetic actions + // TODO: job is done multiple times for (normal) promotions. applyMagneticLaws(move) { - const V = VariantRules; if (move.appear[0].p == V.KING && move.appear.length==1) return [move]; //kings are not charged const aIdx = (move.appear[0].p != V.KING ? 0 : 1); //if castling, rook is charged @@ -31,11 +28,10 @@ class MagneticRules extends ChessRules const lastRank = (color=="w" ? 0 : 7); const standardMove = JSON.parse(JSON.stringify(move)); this.play(standardMove); - const [sizeX,sizeY] = V.size; for (let step of [[-1,0],[1,0],[0,-1],[0,1]]) { let [i,j] = [x+step[0],y+step[1]]; - while (i>=0 && i=0 && j=2 || Math.abs(j-y)>=2) - && this.getPiece(i,j) != V.KING) + if ((Math.abs(i-x)>=2 || Math.abs(j-y)>=2) && this.getPiece(i,j) != V.KING) { move.vanish.push( new PiPo({ @@ -71,7 +66,7 @@ class MagneticRules extends ChessRules { // Push it until we meet an obstacle or edge of the board let [ii,jj] = [i+step[0],j+step[1]]; - while (ii>=0 && ii=0 && jj= 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 = 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; + else if (psq.x == oppFirstRank && this.INIT_COL_ROOK[oppCol].includes(psq.y)) + this.castleFlags[oppCol][psq.y==this.INIT_COL_ROOK[oppCol][0] ? 0 : 1] = false; + }); } 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 @@ -194,22 +191,16 @@ class MagneticRules extends ChessRules } } - checkGameOver() - { - if (this.checkRepetition()) - return "1/2"; - - const color = this.turn; - // TODO: do we need "atLeastOneMove()"? - if (this.atLeastOneMove() && this.kingPos[color][0] >= 0) - return "*"; - - return this.checkGameEnd(); - } - checkGameEnd() { // No valid move: our king disappeared return this.turn == "w" ? "0-1" : "1-0"; } + + static get THRESHOLD_MATE() + { + return 500; //checkmates evals may be slightly below 1000 + } } + +const VariantRules = MagneticRules;