X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=public%2Fjavascripts%2Fcomponents%2Fgame.js;h=1a3d2379c11a49fb6d7074d051934c8d6eb31a47;hp=085dafa3a61671a329104cc6e1370a5325144052;hb=6e62b1c7d177585003e923d423025dff280a7525;hpb=4f7723a1a0d1554f16c699017ae308079aa43a69 diff --git a/public/javascripts/components/game.js b/public/javascripts/components/game.js index 085dafa3..1a3d2379 100644 --- a/public/javascripts/components/game.js +++ b/public/javascripts/components/game.js @@ -1120,13 +1120,21 @@ Vue.component('my-game', { const self = this; this.compWorker.onmessage = function(e) { let compMove = e.data; - compMove.computer = true; //TODO: imperfect attempt to avoid ghost move + if (!Array.isArray(compMove)) + compMove = [compMove]; //to deal with MarseilleRules + // TODO: imperfect attempt to avoid ghost move: + compMove.forEach(m => { m.computer = true; }); // (first move) HACK: small delay to avoid selecting elements // before they appear on page: const delay = Math.max(500-(Date.now()-self.timeStart), 0); setTimeout(() => { if (self.mode == "computer") //warning: mode could have changed! - self.play(compMove, "animate") + self.play(compMove[0], "animate"); + if (compMove.length == 2) + setTimeout( () => { + if (self.mode == "computer") + self.play(compMove[1]); + }, 2000); }, delay); } }, @@ -1297,7 +1305,7 @@ Vue.component('my-game', { this.endGame(this.mycolor=="w"?"0-1":"1-0"); }, newGame: function(mode, fenInit, color, oppId) { - const fen = fenInit || VariantRules.GenRandInitFen(); + const fen = "rnbbqkrn/1ppppp1p/p5p1/8/8/3P4/PPP1PPPP/BNQBRKRN w1 1111 -"; //fenInit || VariantRules.GenRandInitFen(); console.log(fen); //DEBUG if (mode=="human" && !oppId) { @@ -1378,7 +1386,7 @@ Vue.component('my-game', { else if (mode == "computer") { this.compWorker.postMessage(["init",this.vr.getFen()]); - this.mycolor = (Math.random() < 0.5 ? 'w' : 'b'); + this.mycolor = "w";//(Math.random() < 0.5 ? 'w' : 'b'); if (this.mycolor != this.vr.turn) this.playComputerMove(); }