+ // "w": default orientation for observed games
+ this.orientation = game.mycolor || "w";
+ this.moves = JSON.parse(JSON.stringify(game.moves || []));
+ // Post-processing: decorate each move with notation and FEN
+ this.vr = new V(game.fenStart);
+ const parsedFen = V.ParseFen(game.fenStart);
+ const firstMoveColor = parsedFen.turn;
+ this.firstMoveNumber = Math.floor(parsedFen.movesCount / 2);
+ let L = this.moves.length;
+ this.moves.forEach(move => {
+ // Strategy working also for multi-moves:
+ if (!Array.isArray(move)) move = [move];
+ move.forEach((m,idx) => {
+ m.notation = this.vr.getNotation(m);
+ m.unambiguous = V.GetUnambiguousNotation(m);
+ this.vr.play(m);
+ if (idx < L - 1 && this.vr.getCheckSquares(this.vr.turn).length > 0)
+ m.notation += "+";
+ });
+ });
+ if (firstMoveColor == "b") {
+ // 'start' & 'end' is required for Board component
+ this.moves.unshift({
+ notation: "...",
+ unambiguous: "...",
+ start: { x: -1, y: -1 },
+ end: { x: -1, y: -1 },
+ fen: game.fenStart
+ });
+ L++;
+ }
+ this.positionCursorTo(this.moves.length - 1);
+ this.incheck = this.vr.getCheckSquares(this.vr.turn);
+ const score = this.vr.getCurrentScore();
+ if (L > 0 && this.moves[L - 1].notation != "...") {
+ if (["1-0","0-1"].includes(score)) this.moves[L - 1].notation += "#";
+ else if (this.incheck.length > 0) this.moves[L - 1].notation += "+";
+ }
+ },
+ positionCursorTo: function(index) {
+ this.cursor = index;
+ // Caution: last move in moves array might be a multi-move
+ if (index >= 0) {
+ if (Array.isArray(this.moves[index])) {
+ const L = this.moves[index].length;
+ this.lastMove = this.moves[index][L - 1];
+ } else {
+ this.lastMove = this.moves[index];
+ }
+ } else this.lastMove = null;
+ },
+ analyzePosition: function() {
+ let newUrl =
+ "/analyse/" +
+ this.game.vname +
+ "/?fen=" +
+ this.vr.getFen().replace(/ /g, "_");
+ if (this.game.mycolor)
+ newUrl += "&side=" + this.game.mycolor;
+ // Open in same tab in live games (against cheating)
+ if (this.game.type == "live") this.$router.push(newUrl);
+ else window.open("#" + newUrl);