+ re_setClocks: function() {
+ if (this.game.movesCount < 2 || this.game.score != "*") {
+ // 1st move not completed yet, or game over: freeze time
+ this.virtualClocks = this.game.clocks.map(s => ppt(s));
+ return;
+ }
+ const currentTurn = this.vr.turn;
+ const currentMovesCount = this.game.moves.length;
+ const colorIdx = ["w", "b"].indexOf(currentTurn);
+ let countdown =
+ this.game.clocks[colorIdx] -
+ (Date.now() - this.game.initime[colorIdx]) / 1000;
+ this.virtualClocks = [0, 1].map(i => {
+ const removeTime =
+ i == colorIdx ? (Date.now() - this.game.initime[colorIdx]) / 1000 : 0;
+ return ppt(this.game.clocks[i] - removeTime);
+ });
+ let clockUpdate = setInterval(() => {
+ if (
+ countdown < 0 ||
+ this.game.moves.length > currentMovesCount ||
+ this.game.score != "*"
+ ) {
+ clearInterval(clockUpdate);
+ if (countdown < 0)
+ this.gameOver(
+ currentTurn == "w" ? "0-1" : "1-0",
+ this.st.tr["Time"]
+ );
+ } else
+ this.$set(
+ this.virtualClocks,
+ colorIdx,
+ ppt(Math.max(0, --countdown))
+ );
+ }, 1000);
+ },
+ // Post-process a (potentially partial) move (which was just played in BaseGame)