From: Benjamin Auder Date: Wed, 10 Apr 2019 15:49:21 +0000 (+0200) Subject: Still some issues with moves navigation after computer game ends X-Git-Url: https://git.auder.net/%7B%7B%20asset%28%27mixstore/css/static/policy.css%27%29%20%7D%7D?a=commitdiff_plain;h=37cdcbf303d3c2e57b388a1abc9f853ba68a55cd;p=vchess.git Still some issues with moves navigation after computer game ends --- diff --git a/client/next_src/components/problemSummary.js b/client/next_src/components/problemSummary.js index 54602e05..7321c234 100644 --- a/client/next_src/components/problemSummary.js +++ b/client/next_src/components/problemSummary.js @@ -32,3 +32,8 @@ Vue.component('my-problem-summary', { }, }, }) + if (this.mode == "analyze") + { + this.mycolor = V.ParseFen(fen).turn; + this.orientation = this.mycolor; + } diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 087b4f5b..eefd04d9 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -409,8 +409,13 @@ export const ChessRules = class ChessRules ////////////////// // INITIALIZATION - // Fen string fully describes the game state constructor(fen) + { + this.re_init(fen); + } + + // Fen string fully describes the game state + re_init(fen) { const fenParsed = V.ParseFen(fen); this.board = V.GetBoard(fenParsed.position); diff --git a/client/src/components/BaseGame.vue b/client/src/components/BaseGame.vue index 8285c0ce..28752181 100644 --- a/client/src/components/BaseGame.vue +++ b/client/src/components/BaseGame.vue @@ -9,8 +9,8 @@ Board(:vr="vr" :last-move="lastMove" :analyze="analyze" :user-color="mycolor" :orientation="orientation" :vname="vname" @play-move="play") .button-group - button(@click="play") Play - button(@click="undo") Undo + button(@click="() => play()") Play + button(@click="() => undo()") Undo button(@click="flip") Flip button(@click="gotoBegin") GotoBegin button(@click="gotoEnd") GotoEnd @@ -51,6 +51,18 @@ export default { lastMove: null, }; }, + watch: { + // fenStart changes when a new game starts + fenStart: function() { + // Reset all variables + this.endgameMessage = ""; + this.orientation = this.mycolor; + this.score = "*"; + this.moves = []; + this.cursor = -1; + this.lastMove = null; + }, + }, computed: { showMoves: function() { return true; @@ -223,12 +235,12 @@ export default { this.moves.pop(); }, gotoMove: function(index) { - this.vr = new V(this.moves[index].fen); + this.vr.re_init(this.moves[index].fen); this.cursor = index; this.lastMove = this.moves[index]; }, gotoBegin: function() { - this.vr = new V(this.fenStart); + this.vr.re_init(this.fenStart); this.cursor = -1; this.lastMove = null; }, diff --git a/client/src/components/ComputerGame.vue b/client/src/components/ComputerGame.vue index 2070cd09..8c0ac382 100644 --- a/client/src/components/ComputerGame.vue +++ b/client/src/components/ComputerGame.vue @@ -80,23 +80,15 @@ export default { }, newGameFromFen: function(fen) { this.vr = new V(fen); - this.moves = []; - this.cursor = -1; this.fenStart = fen; - this.score = "*"; - if (this.mode == "analyze") - { - this.mycolor = V.ParseFen(fen).turn; - this.orientation = this.mycolor; - } - else if (this.mode == "computer") //only other alternative (HH with gameId) - { - this.mycolor = (Math.random() < 0.5 ? "w" : "b"); - this.orientation = this.mycolor; - this.compWorker.postMessage(["init",fen]); - if (this.mycolor != "w" || this.mode == "auto") - this.playComputerMove(); - } + 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") + this.playComputerMove(); }, playComputerMove: function() { this.timeStart = Date.now();