Some code cleaning + clarifying (TODO: work on variables names)
[vchess.git] / public / javascripts / variants / Checkered.js
index 441cd3c..019e1e2 100644 (file)
@@ -88,7 +88,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
@@ -103,7 +103,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 +167,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,12 +261,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;
                }