X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCheckered.js;h=6864673c0cc6a5bf1f6d021104675a465fd9ceb7;hb=26b8e4f7c71030d49e44fe1d89632ef91b886d67;hp=d73cef41431f55c3fe1c011d4d8219a0925e205a;hpb=643479f8d7c3622b57fc49c4f10d9950793ebf4f;p=vchess.git diff --git a/public/javascripts/variants/Checkered.js b/public/javascripts/variants/Checkered.js index d73cef41..6864673c 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,28 +179,21 @@ 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], [V.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); + this.turn = V.GetOppCol(color); const kingAttacked = this.isAttacked( - this.kingPos[color], [this.getOppCol(color),'c']); + this.kingPos[color], [V.GetOppCol(color),'c']); let res = kingAttacked ? [JSON.parse(JSON.stringify(this.kingPos[color]))] //need to duplicate! : []; this.turn = color; - this.undo(move); return res; } @@ -214,11 +210,11 @@ class CheckeredRules extends ChessRules { const color = this.turn; // Artifically change turn, for checkered pawns - this.turn = this.getOppCol(this.turn); - const res = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']) + this.turn = V.GetOppCol(this.turn); + const res = this.isAttacked(this.kingPos[color], [V.GetOppCol(color),'c']) ? (color == "w" ? "0-1" : "1-0") : "1/2"; - this.turn = this.getOppCol(this.turn); + this.turn = V.GetOppCol(this.turn); return res; } @@ -282,7 +278,7 @@ class CheckeredRules extends ChessRules if (move.vanish.length > 1) { // Capture - const startColumn = V.GetColumn(move.start.y); + const startColumn = V.CoordToColumn(move.start.y); notation = startColumn + "x" + finalSquare + "=" + move.appear[0].p.toUpperCase(); }