- this.compWorker.postMessage(["scripts",this.variant.name]);
- this.newGameFromFen(this.fen);
- },
- newGameFromFen: function(fen) {
- this.vr = new V(fen);
- this.moves = [];
- this.cursor = -1;
- this.fenStart = fen;
- this.score = "*";
- if (this.mode == "analyze")
- {
- this.mycolor = V.ParseFen(fen).turn;
- this.orientation = this.mycolor;
- }
- else if (this.mode == "computer") //only other alternative (HH with gameId)
- {
- this.mycolor = (Math.random() < 0.5 ? "w" : "b");
- this.orientation = this.mycolor;
- this.compWorker.postMessage(["init",fen]);
- if (this.mycolor != "w" || this.subMode == "auto")
- this.playComputerMove();
- }
+ this.compWorker.postMessage(["scripts",this.gameInfo.vname]);
+ this.compWorker.postMessage(["init",this.gameInfo.fen]);
+ this.vr = new V(this.gameInfo.fen);
+ const mycolor = (Math.random() < 0.5 ? "w" : "b");
+ let players = ["Myself","Computer"];
+ if (mycolor == "b")
+ players = players.reverse();
+ // NOTE: (TODO?) fen and fenStart are redundant in game object
+ this.game = Object.assign({},
+ this.gameInfo,
+ {
+ fenStart: this.gameInfo.fen,
+ players: players,
+ mycolor: mycolor,
+ });
+ this.compWorker.postMessage(["init",this.gameInfo.fen]);
+ if (mycolor != "w" || this.gameInfo.mode == "auto")
+ this.playComputerMove();