From: Benjamin Auder Date: Wed, 22 Jan 2020 14:04:09 +0000 (+0100) Subject: Fix games vs comp + auto X-Git-Url: https://git.auder.net/variants/Cwda/vendor/scripts/current/git-logo.png?a=commitdiff_plain;h=af32cf62c4e117a49a76aef24146555a724dd463;p=vchess.git Fix games vs comp + auto --- diff --git a/client/src/components/ComputerGame.vue b/client/src/components/ComputerGame.vue index 5b04cd8c..2745e4c1 100644 --- a/client/src/components/ComputerGame.vue +++ b/client/src/components/ComputerGame.vue @@ -54,31 +54,24 @@ export default { if (!Array.isArray(compMove)) compMove = [compMove]; //to deal with MarseilleRules // Small delay for the bot to appear "more human" -// TODO: debug delay, 2000 --> 0 - const delay = 2000 + Math.max(500-(Date.now()-this.timeStart), 0); -console.log("GOT MOVE: " + this.compThink); + const delay = Math.max(500-(Date.now()-this.timeStart), 0); setTimeout(() => { // NOTE: Dark and 2-moves are incompatible const animate = (this.gameInfo.vname != "Dark"); - this.$refs.basegame.play(compMove[0], animate); - const waitEndOfAnimation = () => { - // 250ms = length of animation (TODO: some constant somewhere) - setTimeout( () => { -console.log("RESET: " + this.compThink); - this.compThink = false; - if (this.game.score != "*") //user action - this.$emit("game-stopped"); - }, animate ? 250 : 0); - }; - if (compMove.length == 2) - { - setTimeout( () => { - this.$refs.basegame.play(compMove[1], animate); - waitEndOfAnimation(); - }, 750); - } - else - waitEndOfAnimation(); + const animDelay = (animate ? 250 : 0); + let moveIdx = 0; + let self = this; + (function executeMove() { + self.$refs.basegame.play(compMove[moveIdx++], animate); + if (moveIdx >= compMove.length) + { + self.compThink = false; + if (self.game.score != "*") //user action + self.$emit("game-stopped"); + } + else + setTimeout(executeMove, 500 + animDelay); + })(); }, delay); } if (!!this.gameInfo.fen) @@ -113,7 +106,6 @@ console.log("RESET: " + this.compThink); playComputerMove: function() { this.timeStart = Date.now(); this.compThink = true; -console.log("ASK MOVE (SET TRUE): " + this.compThink); this.compWorker.postMessage(["askmove"]); }, processMove: function(move) { diff --git a/client/src/views/Rules.vue b/client/src/views/Rules.vue index c77294ff..e709e50a 100644 --- a/client/src/views/Rules.vue +++ b/client/src/views/Rules.vue @@ -11,8 +11,7 @@ | Stop game .section-content(v-show="display=='rules'" v-html="content") ComputerGame(v-show="display=='computer'" :game-info="gameInfo" - @computer-think="gameInProgress=false" @game-over="stopGame" - @game-stopped="gameStopped") + @game-over="stopGame" @game-stopped="gameStopped")