- launchGame: function() {
- 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 = [{name:"Myself"},{name:"Computer"}];
- if (mycolor == "b")
- players = players.reverse();
+ launchGame: function(game) {
+ this.compWorker.postMessage(["scripts", this.gameInfo.vname]);
+ if (!game) {
+ game = {
+ vname: this.gameInfo.vname,
+ fenStart: V.GenRandInitFen(this.st.settings.randomness),
+ moves: []
+ };
+ game.fen = game.fenStart;
+ if (this.gameInfo.mode == "versus")
+ CompgameStorage.add(game);
+ }
+ if (this.gameInfo.mode == "versus" && !game.mycolor)
+ game.mycolor = Math.random() < 0.5 ? "w" : "b";
+ this.compWorker.postMessage(["init", game.fen]);
+ this.vr = new V(game.fen);
+ game.players = [{ name: "Myself" }, { name: "Computer" }];
+ if (game.myColor == "b") game.players = game.players.reverse();
+ game.score = "*"; //finished games are removed