Some code cleaning + clarifying (TODO: work on variables names)
[vchess.git] / public / javascripts / variants / Loser.js
index b4d8b4f..9ae2e7f 100644 (file)
@@ -9,7 +9,7 @@ class LoserRules extends ChessRules
        setFlags(fen)
        {
                // No castling, hence no flags; but flags defined for compatibility
-               this.castleFlags = "0000";
+               this.castleFlags = { "w":[false,false], "b":[false,false] };
        }
 
        getPotentialPawnMoves([x,y])
@@ -24,15 +24,20 @@ class LoserRules extends ChessRules
                const lastRank = (color == "w" ? 0 : sizeX-1);
                if (x+shift == lastRank)
                {
-                       let p = V.KING;
                        // Normal move
                        if (this.board[x+shift][y] == V.EMPTY)
-                               moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:p}));
+                               moves.push(this.getBasicMove([x,y], [x+shift,y], {c:color,p:V.KING}));
                        // Captures
-                       if (y>0 && this.canTake([x,y], [x+shift,y-1]) && this.board[x+shift][y-1] != V.EMPTY)
-                               moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:p}));
-                       if (y<sizeY-1 && this.canTake([x,y], [x+shift,y+1]) && this.board[x+shift][y+1] != V.EMPTY)
-                               moves.push(this.getBasicMove([x,y], [x+shift,y+1], {c:color,p:p}));
+                       if (y>0 && this.canTake([x,y], [x+shift,y-1])
+                               && this.board[x+shift][y-1] != V.EMPTY)
+                       {
+                               moves.push(this.getBasicMove([x,y], [x+shift,y-1], {c:color,p:V.KING}));
+                       }
+                       if (y<sizeY-1 && this.canTake([x,y], [x+shift,y+1])
+                               && this.board[x+shift][y+1] != V.EMPTY)
+                       {
+                               moves.push(this.getBasicMove([x,y], [x+shift,y+1], {c:color,p:V.KING}));
+                       }
                }
 
                return moves;
@@ -110,6 +115,11 @@ class LoserRules extends ChessRules
        unupdateVariables(move) { }
        parseFlags(flags) { }
 
+       getFlagsFen()
+       {
+               return "-";
+       }
+
        checkGameEnd()
        {
                // No valid move: you win!