X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCheckered.js;h=eee21b82af84b6bcdad9f611a68ce0ab5957856b;hb=f6dbe8e31a3260487664f1e0b50710b3f3efaf5f;hp=d73cef41431f55c3fe1c011d4d8219a0925e205a;hpb=388e4c401f05b1f6a4c54e33c9da9114969a53c0;p=vchess.git diff --git a/public/javascripts/variants/Checkered.js b/public/javascripts/variants/Checkered.js index d73cef41..eee21b82 100644 --- a/public/javascripts/variants/Checkered.js +++ b/public/javascripts/variants/Checkered.js @@ -151,7 +151,10 @@ class CheckeredRules extends ChessRules const L = this.moves.length; if (L > 0 && this.oppositeMoves(this.moves[L-1], m)) return false; - return !this.underCheck(m); + this.play(m); + const res = !this.underCheck(color); + this.undo(m); + return res; }); } @@ -176,19 +179,13 @@ class CheckeredRules extends ChessRules return false; } - underCheck(move) + underCheck(color) { - const color = this.turn; - this.play(move); - let res = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']); - this.undo(move); - return res; + return this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']); } - getCheckSquares(move) + getCheckSquares(color) { - this.play(move); - const color = this.turn; // Artifically change turn, for checkered pawns this.turn = this.getOppCol(color); const kingAttacked = this.isAttacked( @@ -197,7 +194,6 @@ class CheckeredRules extends ChessRules ? [JSON.parse(JSON.stringify(this.kingPos[color]))] //need to duplicate! : []; this.turn = color; - this.undo(move); return res; }