- this.orientation = this.game.mycolor || "w"; //default orientation for observed games
- this.moves = JSON.parse(JSON.stringify(this.game.moves || []));
- // Post-processing: decorate each move with color + current FEN:
- // (to be able to jump to any position quickly)
- let vr_tmp = new V(this.game.fenStart); //vr is already at end of game
- this.firstMoveNumber = Math.floor(
- V.ParseFen(this.game.fenStart).movesCount / 2
- );
- this.moves.forEach(move => {
- // NOTE: this is doing manually what play() function below achieve,
- // but in a lighter "fast-forward" way
- move.color = vr_tmp.turn;
- move.notation = vr_tmp.getNotation(move);
- vr_tmp.play(move);
- move.fen = vr_tmp.getFen();
- });
- if (
- (this.moves.length > 0 && this.moves[0].color == "b") ||
- (this.moves.length == 0 && vr_tmp.turn == "b")
- ) {
- // 'end' is required for Board component to check lastMove for e.p.
+ // "w": default orientation for observed games
+ this.orientation = game.mycolor || "w";
+ this.mode = game.mode || game.type; //TODO: merge...
+ this.moves = JSON.parse(JSON.stringify(game.moves || []));
+ // Post-processing: decorate each move with notation and FEN
+ this.vr = new V(game.fenStart);
+ this.inMultimove = false; //in case of
+ if (!!this.$refs["board"])
+ // Also in case of:
+ this.$refs["board"].resetCurrentAttempt();
+ let analyseBtn = document.getElementById("analyzeBtn");
+ if (!!analyseBtn) analyseBtn.classList.remove("active");
+ const parsedFen = V.ParseFen(game.fenStart);
+ const firstMoveColor = parsedFen.turn;
+ this.firstMoveNumber = Math.floor(parsedFen.movesCount / 2) + 1;
+ let L = this.moves.length;
+ if (L == 0) {
+ // Could be started on a random position in analysis mode:
+ this.incheck = this.vr.getCheckSquares();
+ this.score = this.vr.getCurrentScore();
+ if (this.score != '*') {
+ // Show score on screen
+ const message = getScoreMessage(this.score);
+ this.showEndgameMsg(this.score + " . " + this.st.tr[message]);
+ }
+ }
+ else {
+ this.moves.forEach((move,idx) => {
+ // Strategy working also for multi-moves:
+ if (!Array.isArray(move)) move = [move];
+ const Lm = move.length;
+ move.forEach((m,idxM) => {
+ m.notation = this.vr.getNotation(m);
+ m.unambiguous = V.GetUnambiguousNotation(m);
+ this.vr.play(m);
+ const checkSquares = this.vr.getCheckSquares();
+ if (checkSquares.length > 0) m.notation += "+";
+ if (idxM == Lm - 1) m.fen = this.vr.getFen();
+ if (idx == L - 1 && idxM == Lm - 1) {
+ this.incheck = checkSquares;
+ this.score = this.vr.getCurrentScore();
+ if (["1-0", "0-1"].includes(this.score)) m.notation += "#";
+ }
+ });
+ });
+ }
+ if (firstMoveColor == "b") {
+ // 'start' & 'end' is required for Board component