+ processMove: function(move, data) {
+ if (!data) data = {};
+ const moveCol = this.vr.turn;
+ const doProcessMove = () => {
+ const colorIdx = ["w", "b"].indexOf(moveCol);
+ const nextIdx = 1 - colorIdx;
+ const origMovescount = this.game.moves.length;
+ let addTime =
+ this.game.type == "live"
+ ? (data.addTime || 0)
+ : undefined;
+ if (moveCol == this.game.mycolor && !data.receiveMyMove) {
+ if (this.drawOffer == "received")
+ // I refuse draw
+ this.drawOffer = "";
+ if (this.game.type == "live" && origMovescount >= 2) {
+ const elapsed = Date.now() - this.game.initime[colorIdx];
+ // elapsed time is measured in milliseconds
+ addTime = this.game.increment - elapsed / 1000;
+ }
+ }
+ // Update current game object:
+ playMove(move, this.vr);
+// TODO: notifyTurn: "changeturn" message
+ this.game.moves.push(move);
+ // (add)Time indication: useful in case of lastate infos requested
+ if (this.game.type == "live")
+ this.game.addTimes.push(addTime);
+ this.game.fen = this.vr.getFen();
+ if (this.game.type == "live") this.game.clocks[colorIdx] += addTime;
+ // In corr games, just reset clock to mainTime:
+ else this.game.clocks[colorIdx] = extractTime(this.game.cadence).mainTime;
+ // data.initime is set only when I receive a "lastate" move from opponent
+ this.game.initime[nextIdx] = data.initime || Date.now();
+ this.re_setClocks();
+ // If repetition detected, consider that a draw offer was received:
+ const fenObj = this.vr.getFenForRepeat();
+ this.repeat[fenObj] = this.repeat[fenObj] ? this.repeat[fenObj] + 1 : 1;
+ if (this.repeat[fenObj] >= 3) this.drawOffer = "threerep";
+ else if (this.drawOffer == "threerep") this.drawOffer = "";
+ // Since corr games are stored at only one location, update should be
+ // done only by one player for each move:
+ if (!!this.game.mycolor && !data.receiveMyMove) {
+ // NOTE: 'var' to see that variable outside this block
+ var filtered_move = getFilteredMove(move);
+ }