- launchGame: async function() {
- const vModule = await import("@/variants/" + this.vname + ".js");
- window.V = vModule.VariantRules;
- this.compWorker.postMessage(["scripts",this.vname]);
- this.compWorker.postMessage(["init",this.fen]);
- this.newGameFromFen(this.fen);
- },
- newGameFromFen: function(fen) {
- this.vr = new V(fen);
- this.fenStart = fen;
- this.mycolor = (Math.random() < 0.5 ? "w" : "b");
- console.log(this.mycolor);
- this.players = ["Myself","Computer"];
- if (this.mycolor == "b")
- this.players = this.players.reverse();
- this.compWorker.postMessage(["init",fen]);
- if (this.mycolor != "w" || this.mode == "auto")
+ 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 (!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: "Computer" }, { name: "Computer" }];
+ if (this.gameInfo.mode == "versus")
+ game.players[game.mycolor == 'w' ? 0 : 1] = { name: "Myself" };
+ game.score = "*"; //finished games are removed
+ game.mode = this.gameInfo.mode;
+ this.currentUrl = document.location.href; //to avoid playing outside page
+ this.game = game;
+ this.$refs["basegame"].re_setVariables(game);
+ this.compWorker.postMessage(["init", game.fen]);
+ if (this.gameInfo.mode == "auto" || game.mycolor != this.vr.turn)