X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCheckered.js;h=814d91b8ce10ee30e73c7cd7bd59173deb7db9ca;hb=2316f8b8248589effc756d5c09c73a1acb431574;hp=56fa15a382639c2b9361d390dc1aa99096b9a829;hpb=aea1443ebf56afb2c507c2830ac6b67b509778bc;p=vchess.git diff --git a/public/javascripts/variants/Checkered.js b/public/javascripts/variants/Checkered.js index 56fa15a3..814d91b8 100644 --- a/public/javascripts/variants/Checkered.js +++ b/public/javascripts/variants/Checkered.js @@ -1,6 +1,5 @@ class CheckeredRules extends ChessRules { - // Path to pieces static getPpath(b) { return b[0]=='c' ? "Checkered/"+b : b; @@ -77,10 +76,15 @@ class CheckeredRules extends ChessRules return standardMoves; //king has to be treated differently (for castles) let moves = []; standardMoves.forEach(m => { - if (m.vanish[0].p == VariantRules.PAWN && Math.abs(m.end.x-m.start.x)==2 - && !this.pawnFlags[this.turn][m.start.y]) + if (m.vanish[0].p == VariantRules.PAWN) { - return; //skip forbidden 2-squares jumps + if (Math.abs(m.end.x-m.start.x)==2 && !this.pawnFlags[this.turn][m.start.y]) + return; //skip forbidden 2-squares jumps + if (this.board[m.end.x][m.end.y] == VariantRules.EMPTY + && m.vanish.length==2 && this.getColor(m.start.x,m.start.y) == 'c') + { + return; //checkered pawns cannot take en-passant + } } if (m.vanish.length == 1) moves.push(m); //no capture @@ -89,7 +93,7 @@ class CheckeredRules extends ChessRules // A capture occured (m.vanish.length == 2) m.appear[0].c = "c"; moves.push(m); - if (m.appear[0].p != m.vanish[1].p //avoid promotions: + if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated): && (m.vanish[0].p != VariantRules.PAWN || m.end.x != lastRank)) { // Add transformation into captured piece @@ -104,7 +108,8 @@ class CheckeredRules extends ChessRules canIplay(side, [x,y]) { - return ((side=='w' && this.moves.length%2==0) || (side=='b' && this.moves.length%2==1)) + return ((side=='w' && this.moves.length%2==0) + || (side=='b' && this.moves.length%2==1)) && [side,'c'].includes(this.getColor(x,y)); } @@ -167,7 +172,8 @@ class CheckeredRules extends ChessRules this.play(move); const color = this.turn; this.moves.push(move); //artifically change turn, for checkered pawns (TODO) - const kingAttacked = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']); + const kingAttacked = this.isAttacked( + this.kingPos[color], [this.getOppCol(color),'c']); let res = kingAttacked ? [ JSON.parse(JSON.stringify(this.kingPos[color])) ] //need to duplicate! : [ ]; @@ -191,13 +197,12 @@ class CheckeredRules extends ChessRules checkGameEnd() { const color = this.turn; - if (!this.isAttacked(this.kingPos[color], this.getOppCol(color)) - && !this.isAttacked(this.kingPos[color], 'c')) - { - return "1/2"; - } - // OK, checkmate - return color == "w" ? "0-1" : "1-0"; + this.moves.length++; //artifically change turn, for checkered pawns (TODO) + const res = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']) + ? (color == "w" ? "0-1" : "1-0") + : "1/2"; + this.moves.length--; + return res; } evalPosition() @@ -261,12 +266,15 @@ class CheckeredRules extends ChessRules { // Capture let startColumn = String.fromCharCode(97 + move.start.y); - notation = startColumn + "x" + finalSquare + "=" + move.appear[0].p.toUpperCase(); + notation = startColumn + "x" + finalSquare + + "=" + move.appear[0].p.toUpperCase(); } else //no capture + { notation = finalSquare; - if (move.appear.length > 0 && piece != move.appear[0].p) //promotion - notation += "=" + move.appear[0].p.toUpperCase(); + if (move.appear.length > 0 && piece != move.appear[0].p) //promotion + notation += "=" + move.appear[0].p.toUpperCase(); + } return notation; }