X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=public%2Fjavascripts%2Fvariants%2FCheckered.js;h=2d62d4b8af2bdaf53f64aa6414ea390a42fa3fe1;hb=0b7d99ecbb5dedc02cd96c457b5fc2962db9b297;hp=f1cf771f948e585ce9a4ce7342058c154b7d69e0;hpb=5bfb09560aa346d132e829a7c63558407bcc8091;p=vchess.git diff --git a/public/javascripts/variants/Checkered.js b/public/javascripts/variants/Checkered.js index f1cf771f..2d62d4b8 100644 --- a/public/javascripts/variants/Checkered.js +++ b/public/javascripts/variants/Checkered.js @@ -72,14 +72,19 @@ class CheckeredRules extends ChessRules { let standardMoves = super.getPotentialMovesFrom([x,y]); const lastRank = this.turn == "w" ? 0 : 7; - if (this.getPiece(x,y) == VariantRules.KING) + if (this.getPiece(x,y) == V.KING) 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 == V.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] == V.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 @@ -88,8 +93,8 @@ 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: - && (m.vanish[0].p != VariantRules.PAWN || m.end.x != lastRank)) + if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated): + && (m.vanish[0].p != V.PAWN || m.end.x != lastRank)) { // Add transformation into captured piece let m2 = JSON.parse(JSON.stringify(m)); @@ -103,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)); } @@ -141,7 +147,7 @@ class CheckeredRules extends ChessRules { for (let i of [-1,1]) { - if (y+i>=0 && y+i<8 && this.getPiece(x+pawnShift,y+i)==VariantRules.PAWN + if (y+i>=0 && y+i<8 && this.getPiece(x+pawnShift,y+i)==V.PAWN && this.getColor(x+pawnShift,y+i)==c) { return true; @@ -166,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! : [ ]; @@ -177,42 +184,37 @@ class CheckeredRules extends ChessRules updateVariables(move) { - const c = this.getColor(move.start.x,move.start.y); - if (c != 'c') //checkered not concerned by castle flags - super.updateVariables(move); - - // Does it turn off a 2-squares pawn flag? + super.updateVariables(move); + // Does this move turn off a 2-squares pawn flag? const secondRank = [1,6]; - if (secondRank.includes(move.start.x) && move.vanish[0].p == VariantRules.PAWN) + if (secondRank.includes(move.start.x) && move.vanish[0].p == V.PAWN) this.pawnFlags[move.start.x==6 ? "w" : "b"][move.start.y] = false; } 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() { - const [sizeX,sizeY] = VariantRules.size; let evaluation = 0; //Just count material for now, considering checkered neutral (...) - for (let i=0; i 0 && piece != move.appear[0].p) //promotion + notation += "=" + move.appear[0].p.toUpperCase(); + } return notation; }