Complete GameStorage.update. TODO: move transmission
[vchess.git] / client / src / base_rules.js
index 087b4f5..15609eb 100644 (file)
@@ -50,13 +50,13 @@ export const ChessRules = class ChessRules
   // Turn "wb" into "B" (for FEN)
   static board2fen(b)
   {
-    return b[0]=='w' ? b[1].toUpperCase() : b[1];
+    return (b[0]=='w' ? b[1].toUpperCase() : b[1]);
   }
 
   // Turn "p" into "bp" (for board)
   static fen2board(f)
   {
-    return f.charCodeAt()<=90 ? "w"+f.toLowerCase() : "b"+f;
+    return (f.charCodeAt()<=90 ? "w"+f.toLowerCase() : "b"+f);
   }
 
   // Check if FEN describe a position
@@ -409,8 +409,13 @@ export const ChessRules = class ChessRules
   //////////////////
   // INITIALIZATION
 
-  // Fen string fully describes the game state
   constructor(fen)
+  {
+    this.re_init(fen);
+  }
+
+  // Fen string fully describes the game state
+  re_init(fen)
   {
     const fenParsed = V.ParseFen(fen);
     this.board = V.GetBoard(fenParsed.position);
@@ -1057,8 +1062,6 @@ export const ChessRules = class ChessRules
       move.flags = JSON.stringify(this.aggregateFlags()); //save flags (for undo)
     if (V.HasEnpassant)
       this.epSquares.push( this.getEpSquare(move) );
-    if (!move.color)
-      move.color = this.turn; //for interface
     V.PlayOnBoard(this.board, move);
     this.turn = V.GetOppCol(this.turn);
     this.movesCount++;