+ // Update current game object (no need for moves stack):
+ playMove(move, this.vr);
+ this.game.movesCount++;
+ // (add)Time indication: useful in case of lastate infos requested
+ this.game.moves.push({move:move, addTime:addTime});
+ this.game.fen = this.vr.getFen();
+ this.game.clocks[colorIdx] += addTime;
+ // data.initime is set only when I receive a "lastate" move from opponent
+ this.game.initime[nextIdx] = (data && data.initime) ? data.initime : Date.now();
+ this.re_setClocks();
+ // If repetition detected, consider that a draw offer was received:
+ const fenObj = V.ParseFen(this.game.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 = "";
+ // Since corr games are stored at only one location, update should be
+ // done only by one player for each move:
+ if (
+ this.game.mycolor &&
+ (this.game.type == "live" || moveCol == this.game.mycolor)
+ ) {
+ let drawCode = "";
+ switch (this.drawOffer) {
+ case "threerep":
+ drawCode = "t";
+ break;
+ case "sent":
+ drawCode = this.game.mycolor;
+ break;
+ case "received":
+ drawCode = V.GetOppCol(this.game.mycolor);
+ break;
+ }
+ if (this.game.type == "corr") {
+ GameStorage.update(this.gameRef.id, {
+ fen: this.game.fen,
+ move: {
+ squares: filtered_move,
+ played: Date.now(),
+ idx: this.game.moves.length - 1
+ },
+ // Code "n" for "None" to force reset (otherwise it's ignored)
+ drawOffer: drawCode || "n"
+ });
+ }
+ else {
+ // Live game:
+ GameStorage.update(this.gameRef.id, {
+ fen: this.game.fen,
+ move: filtered_move,
+ clocks: this.game.clocks,
+ initime: this.game.initime,
+ drawOffer: drawCode
+ });
+ }
+ }
+ };
+ if (this.game.type == "corr" && moveCol == this.game.mycolor) {
+ setTimeout(() => {
+ if (
+ !confirm(
+ this.st.tr["Move played:"] +
+ " " +
+ getFullNotation(move) +
+ "\n" +
+ this.st.tr["Are you sure?"]
+ )
+ ) {
+ this.$refs["basegame"].cancelLastMove();
+ return;
+ }
+ doProcessMove();
+ // Let small time to finish drawing current move attempt:
+ }, 500);