Still some issues with moves navigation after computer game ends
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 10 Apr 2019 15:49:21 +0000 (17:49 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 10 Apr 2019 15:49:21 +0000 (17:49 +0200)
client/next_src/components/problemSummary.js
client/src/base_rules.js
client/src/components/BaseGame.vue
client/src/components/ComputerGame.vue

index 54602e0..7321c23 100644 (file)
@@ -32,3 +32,8 @@ Vue.component('my-problem-summary', {
                },
        },
 })
+      if (this.mode == "analyze")
+      {
+        this.mycolor = V.ParseFen(fen).turn;
+        this.orientation = this.mycolor;
+      }
index 087b4f5..eefd04d 100644 (file)
@@ -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);
index 8285c0c..2875218 100644 (file)
@@ -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;
     },
index 2070cd0..8c0ac38 100644 (file)
@@ -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();