- if (!!moves && moves.length > 0) //imply continuation
- {
- const lastMove = moves[moves.length-1];
- this.vr.undo(lastMove);
- this.incheck = this.vr.getCheckSquares(lastMove);
- this.vr.play(lastMove, "ingame");
- }
- delete localStorage["newgame"];
- this.setStorage(); //in case of interruptions
+ if (this.sound >= 1)
+ new Audio("/sounds/newgame.mp3").play().catch(err => {});
+ document.getElementById("modal-newgame").checked = false;
+ }
+ else if (mode == "computer")
+ {
+ 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
+ if (mode != "problem")
+ this.setStorage(); //store game state in case of interruptions
+ },
+ 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}));