X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=15609eb16dd29e2bfcbaa263c9df93b19c9c5a87;hb=9d54ab8900b69876c3249b4ed1bfa355dccb7f97;hp=087b4f5b39622aa5cb4b8ae89eefcfb8359ae931;hpb=1c9f093dad69e4c7b6d2b42cb5e0bd3bc7224ec9;p=vchess.git diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 087b4f5b..15609eb1 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -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++;