+ // The board may show some possible moves: (TODO: bad solution)
+ this.$refs["board"].resetCurrentAttempt();
+ const playSubmove = (smove) => {
+ smove.notation = this.vr.getNotation(smove);
+ smove.unambiguous = V.GetUnambiguousNotation(smove);
+ this.vr.play(smove);
+ if (this.inMultimove && !!this.lastMove) {
+ if (!Array.isArray(this.lastMove))
+ this.lastMove = [this.lastMove, smove];
+ else this.lastMove.push(smove);
+ }
+ if (!this.inMultimove) {
+ // First sub-move:
+ this.lastMove = smove;
+ // Condition is "!navigate" but we mean "!this.autoplay"
+ if (!navigate) {
+ if (this.cursor < this.moves.length - 1)
+ this.moves = this.moves.slice(0, this.cursor + 1);
+ this.moves.push(smove);
+ }
+ this.inMultimove = true; //potentially
+ this.cursor++;
+ }
+ else if (!navigate) {
+ // Already in the middle of a multi-move
+ const L = this.moves.length;
+ if (!Array.isArray(this.moves[L-1]))
+ this.$set(this.moves, L-1, [this.moves[L-1], smove]);
+ else this.moves[L-1].push(smove);
+ }
+ };
+ const playMove = () => {
+ const animate = (
+ ["all", "highlight"].includes(V.ShowMoves) &&
+ (this.autoplay || !!received)
+ );
+ if (!Array.isArray(move)) move = [move];
+ let moveIdx = 0;
+ let self = this;
+ const initurn = this.vr.turn;
+ (function executeMove() {
+ const smove = move[moveIdx++];
+ // NOTE: condition "smove.start.x >= 0" required for Dynamo,
+ // because second move may be empty. noHighlight condition
+ // is used at least for Chakart.
+ if (animate && smove.start.x >= 0 && !smove.end.noHighlight) {
+ self.animateMove(smove, () => {
+ playSubmove(smove);
+ if (moveIdx < move.length) setTimeout(executeMove, 500);
+ else afterMove(smove, initurn);
+ });
+ }
+ else {
+ playSubmove(smove);
+ if (moveIdx < move.length) executeMove();
+ else afterMove(smove, initurn);
+ }
+ })();
+ };
+ const computeScore = () => {
+ const score = this.vr.getCurrentScore();
+ if (!navigate) {
+ if (["1-0", "0-1"].includes(score)) {
+ if (Array.isArray(this.lastMove)) {
+ const L = this.lastMove.length;
+ this.lastMove[L - 1].notation += "#";
+ }
+ else this.lastMove.notation += "#";
+ }
+ }
+ if (score != "*" && ["analyze", "versus"].includes(this.mode)) {
+ const message = getScoreMessage(score);
+ // Show score on screen
+ this.showEndgameMsg(score + " . " + this.st.tr[message]);
+ }
+ return score;
+ };
+ const afterMove = (smove, initurn) => {
+ if (this.vr.turn != initurn) {
+ // Turn has changed: move is complete
+ if (!smove.fen)
+ // NOTE: only FEN of last sub-move is required (=> setting it here)
+ smove.fen = this.vr.getFen();
+ this.emitFenIfAnalyze();
+ this.inMultimove = false;
+ this.incheck = this.vr.getCheckSquares();
+ if (this.incheck.length > 0) smove.notation += "+";
+ this.score = computeScore();
+ if (this.autoplay) {
+ if (this.cursor < this.moves.length - 1)
+ setTimeout(() => this.play(null, null, null, "autoplay"), 1000);
+ else {
+ this.autoplay = false;
+ if (this.stackToPlay.length > 0)
+ // Move(s) arrived in-between
+ this.play(this.stackToPlay.pop(), "received");
+ }
+ }
+ if (this.mode != "analyze" && !navigate) {
+ if (!received) {
+ // Post-processing (e.g. computer play).
+ const L = this.moves.length;
+ // NOTE: always emit the score, even in unfinished
+ this.$emit("newmove", this.moves[L-1], { score: this.score });
+ }
+ else {
+ this.inPlay = false;
+ if (this.stackToPlay.length > 0)
+ // Move(s) arrived in-between
+ this.play(this.stackToPlay.pop(), "received");
+ }
+ }
+ }
+ };
+ // NOTE: navigate and received are mutually exclusive
+ if (navigate) {
+ // The move to navigate to is necessarily full:
+ if (this.cursor == this.moves.length - 1) return; //no more moves
+ move = this.moves[this.cursor + 1];
+ if (!this.autoplay) {
+ // Just play the move:
+ if (!Array.isArray(move)) move = [move];
+ for (let i=0; i < move.length; i++) this.vr.play(move[i]);
+ if (!light) {
+ this.lastMove = move;
+ this.incheck = this.vr.getCheckSquares();
+ this.score = computeScore();
+ this.emitFenIfAnalyze();
+ }
+ this.cursor++;
+ return;