- if (navigate)
- {
- if (this.cursor == this.moves.length-1)
- return; //no more moves
- move = this.moves[this.cursor+1];
- }
- if (!!programmatic) //computer or (remote) human opponent
- {
- if (this.cursor < this.moves.length-1)
- this.gotoEnd(); //required to play the move
- return this.animateMove(move);
- }
- // Not programmatic, or animation is over
- if (!move.notation)
- move.notation = this.vr.getNotation(move);
- if (!move.color)
- move.color = this.vr.turn;
- this.vr.play(move);
- this.cursor++;
- this.lastMove = move;
- if (!move.fen)
- move.fen = this.vr.getFen();
- if (this.st.settings.sound == 2)
- new Audio("/sounds/move.mp3").play().catch(err => {});
- // Send the move to web worker (including his own moves)
- this.compWorker.postMessage(["newmove",move]);
- if (!navigate && (this.score == "*" || this.analyze))
- {
- // Stack move on movesList at current cursor
- if (this.cursor == this.moves.length)
- this.moves.push(move);
- else
- this.moves = this.moves.slice(0,this.cursor).concat([move]);
- }
- // Is opponent in check?
- this.incheck = this.vr.getCheckSquares(this.vr.turn);
- const score = this.vr.getCurrentScore();
- if (score != "*")
- {
- if (!this.analyze)
- this.endGame(score);
- else //just show score on screen (allow undo)
- this.showScoreMsg(score);
- }
- // subTurn condition for Marseille (and Avalanche) rules
- else if ((this.mode == "computer" && (!this.vr.subTurn || this.vr.subTurn <= 1))
- && (this.subMode == "auto" || this.vr.turn != this.mycolor))
- {
- this.playComputerMove();
- }
- // https://vuejs.org/v2/guide/list.html#Caveats (also for undo)
- //if (navigate)
- // this.$children[0].$forceUpdate(); //TODO!?
+ const doPlayMove = () => {
+ if (!!receive && this.cursor < this.moves.length - 1) this.gotoEnd(); //required to play the move
+ if (navigate) {
+ if (this.cursor == this.moves.length - 1) return; //no more moves
+ move = this.moves[this.cursor + 1];
+ } else {
+ move.color = this.vr.turn;
+ move.notation = this.vr.getNotation(move);
+ }
+ this.vr.play(move);
+ this.cursor++;
+ this.lastMove = move;
+ if (this.st.settings.sound == 2)
+ new Audio("/sounds/move.mp3").play().catch(() => {});
+ if (!navigate) {
+ move.fen = this.vr.getFen();
+ // Stack move on movesList at current cursor
+ if (this.cursor == this.moves.length) this.moves.push(move);
+ else this.moves = this.moves.slice(0, this.cursor).concat([move]);
+ }
+ // Is opponent in check?
+ this.incheck = this.vr.getCheckSquares(this.vr.turn);
+ const score = this.vr.getCurrentScore();
+ if (score != "*") {
+ const message = getScoreMessage(score);
+ if (this.game.mode != "analyze")
+ this.$emit("gameover", score, message);
+ //just show score on screen (allow undo)
+ else this.showEndgameMsg(score + " . " + message);
+ }
+ if (!navigate && this.game.mode != "analyze")
+ this.$emit("newmove", move); //post-processing (e.g. computer play)
+ };
+ if (!!receive && this.game.vname != "Dark")
+ this.animateMove(move, doPlayMove);
+ else doPlayMove();