+ const sendMove = Object.assign({}, filtered_move, {
+ addTime: addTime,
+ cancelDrawOffer: this.drawOffer == ""
+ });
+ this.send("newmove", { data: sendMove });
+ // (Add)Time indication: useful in case of lastate infos requested
+ move.addTime = addTime;
+ } else addTime = move.addTime; //supposed transmitted
+ // Update current game object:
+ if (nextIdx != colorIdx)
+ this.game.movesCount++;
+ this.game.moves.push(move);
+ this.game.fen = move.fen;
+ this.game.clocks[colorIdx] += addTime;
+ // move.initime is set only when I receive a "lastate" move from opponent
+ this.game.initime[nextIdx] = move.initime || Date.now();
+ this.re_setClocks();
+ // If repetition detected, consider that a draw offer was received:
+ const fenObj = V.ParseFen(move.fen);
+ let repIdx = fenObj.position + "_" + fenObj.turn;
+ if (fenObj.flags) repIdx += "_" + fenObj.flags;
+ this.repeat[repIdx] = this.repeat[repIdx] ? this.repeat[repIdx] + 1 : 1;
+ if (this.repeat[repIdx] >= 3) this.drawOffer = "threerep";
+ else if (this.drawOffer == "threerep") this.drawOffer = "";