- if (!!receive && this.game.vname != "Dark")
- this.animateMove(move, doPlayMove);
- else
- doPlayMove();
- },
- undo: function(move) {
- const navigate = !move;
- if (navigate)
- {
- if (this.cursor < 0)
- return; //no more moves
- move = this.moves[this.cursor];
+ 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();
+ // Is opponent in check?
+ this.incheck = this.vr.getCheckSquares(this.vr.turn);
+ this.emitFenIfAnalyze();
+ this.inMultimove = false;
+ this.score = computeScore();
+ if (this.game.mode != "analyze" && !navigate) {
+ if (!noemit) {
+ // Post-processing (e.g. computer play).
+ const L = this.moves.length;
+ // NOTE: always emit the score, even in unfinished,
+ // to tell Game::processMove() that it's not a received move.
+ 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, light, noemit);
+ }
+ }
+ }
+ };
+ // 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[move.length-1];
+ this.incheck = this.vr.getCheckSquares(this.vr.turn);
+ this.score = computeScore();
+ this.emitFenIfAnalyze();
+ }
+ this.cursor++;
+ return;
+ }