X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FAtomic.js;h=87c980979cc8d0cbf870477dfaa3c1196a31b60b;hb=ab4f4bf258ed68d8292b64d81babde03cddbae3c;hp=666c50b214406656bc04a258e6f75c448e5a2b75;hpb=388e4c401f05b1f6a4c54e33c9da9114969a53c0;p=vchess.git diff --git a/public/javascripts/variants/Atomic.js b/public/javascripts/variants/Atomic.js index 666c50b2..87c98097 100644 --- a/public/javascripts/variants/Atomic.js +++ b/public/javascripts/variants/Atomic.js @@ -90,7 +90,7 @@ class AtomicRules extends ChessRules { super.unupdateVariables(move); const c = move.vanish[0].c; - const oppCol = this.getOppCol(c); + const oppCol = V.GetOppCol(c); if ([this.kingPos[c][0],this.kingPos[oppCol][0]].some(e => { return e < 0; })) { // There is a chance that last move blowed some king away.. @@ -102,37 +102,30 @@ class AtomicRules extends ChessRules } } - underCheck(move) + underCheck(color) { - const c = this.turn; - const oppCol = this.getOppCol(c); - this.play(move); + const oppCol = V.GetOppCol(color); let res = undefined; // If our king disappeared, move is not valid - if (this.kingPos[c][0] < 0) + if (this.kingPos[color][0] < 0) res = true; // If opponent king disappeared, move is valid else if (this.kingPos[oppCol][0] < 0) res = false; // Otherwise, if we remain under check, move is not valid else - res = this.isAttacked(this.kingPos[c], [oppCol]); - this.undo(move); + res = this.isAttacked(this.kingPos[color], [oppCol]); return res; } - getCheckSquares(move) + getCheckSquares(color) { - const c = this.getOppCol(this.turn); - // King might explode: - const saveKingPos = JSON.parse(JSON.stringify(this.kingPos[c])); - this.play(move); let res = [ ]; - if (this.kingPos[c][0] < 0) - res = [saveKingPos]; - else if (this.isAttacked(this.kingPos[c], [this.getOppCol(c)])) - res = [ JSON.parse(JSON.stringify(this.kingPos[c])) ] - this.undo(move); + if (this.kingPos[color][0] >= 0 //king might have exploded + && this.isAttacked(this.kingPos[color], [V.GetOppCol(color)])) + { + res = [ JSON.parse(JSON.stringify(this.kingPos[color])) ] + } return res; } @@ -142,10 +135,8 @@ class AtomicRules extends ChessRules const kp = this.kingPos[color]; if (kp[0] < 0) //king disappeared return color == "w" ? "0-1" : "1-0"; - if (!this.isAttacked(kp, [this.getOppCol(color)])) + if (!this.isAttacked(kp, [V.GetOppCol(color)])) return "1/2"; return color == "w" ? "0-1" : "1-0"; //checkmate } } - -const VariantRules = AtomicRules;