Fix Checkered and Ultima rules. Write Chess960 rules and complete others
[vchess.git] / public / javascripts / variants / Checkered.js
index b9e7223..814d91b 100644 (file)
@@ -76,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
@@ -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));
        }
 
@@ -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!
                        : [ ];
@@ -259,7 +266,8 @@ 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
                        {