+ this.compWorker.postMessage(["init",this.vr.getFen()]);
+ this.mycolor = (Math.random() < 0.5 ? 'w' : 'b');
+ if (this.mycolor != this.vr.turn)
+ this.playComputerMove();
+ }
+ else if (mode == "friend")
+ this.mycolor = "w"; //convention...
+ //else: problem solving: nothing more to do
+ },
+ continueGame: function(mode) {
+ this.mode = mode;
+ this.oppid = (mode=="human" ? localStorage.getItem("oppid") : undefined);
+ const prefix = this.getStoragePrefix(mode);
+ this.mycolor = localStorage.getItem(prefix+"mycolor");
+ const moves = JSON.parse(localStorage.getItem(prefix+"moves"));
+ const fen = localStorage.getItem(prefix+"fen");
+ const score = localStorage.getItem(prefix+"score"); //set in "endGame()"
+ this.fenStart = localStorage.getItem(prefix+"fenStart");
+ this.vr = new VariantRules(fen, moves);
+ this.incheck = this.vr.getCheckSquares(this.vr.turn);
+ if (mode == "human")
+ {
+ this.gameId = localStorage.getItem("gameId");
+ // Send ping to server (answer pong if opponent is connected)
+ this.conn.send(JSON.stringify({
+ code:"ping",oppid:this.oppid,gameId:this.gameId}));
+ }
+ else if (mode == "computer")
+ {
+ this.compWorker.postMessage(["init",fen]);
+ if (score == "*" && this.mycolor != this.vr.turn)
+ this.playComputerMove();
+ }
+ //else: nothing special to do in friend mode
+ if (score != "*")
+ {
+ // Small delay required when continuation run faster than drawing page
+ setTimeout(() => this.endGame(score), 100);