Fix '3 knights' bug + tiny advance on problems tab
[vchess.git] / public / javascripts / components / game.js
index 202f542..533bc0e 100644 (file)
@@ -24,7 +24,7 @@ Vue.component('my-game', {
                };
        },
        render(h) {
-               const [sizeX,sizeY] = VariantRules.size;
+               const [sizeX,sizeY] = [V.size.x,V.size.y];
                const smallScreen = (window.innerWidth <= 420);
                // Precompute hints squares to facilitate rendering
                let hintSquares = doubleArray(sizeX, sizeY, false);
@@ -1014,7 +1014,7 @@ Vue.component('my-game', {
                        this.endGame(this.mycolor=="w"?"0-1":"1-0");
                },
                newGame: function(mode, fenInit, color, oppId, moves, continuation) {
-                       const fen = "3N1K2/2n2q2/P1R1kPnN/p3b1p1/b7/5Q2/4r3/8 0000";//fenInit || VariantRules.GenRandInitFen();
+                       const fen = fenInit || VariantRules.GenRandInitFen();
                        console.log(fen); //DEBUG
                        if (mode=="human" && !oppId)
                        {
@@ -1072,7 +1072,7 @@ Vue.component('my-game', {
                        }
                        else if (mode == "computer")
                        {
-                               this.mycolor = "w";//Math.random() < 0.5 ? 'w' : 'b';
+                               this.mycolor = Math.random() < 0.5 ? 'w' : 'b';
                                if (this.mycolor == 'b')
                                        setTimeout(this.playComputerMove, 500);
                        }
@@ -1083,7 +1083,10 @@ Vue.component('my-game', {
                        const compMove = this.vr.getComputerMove();
                        // (first move) HACK: avoid selecting elements before they appear on page:
                        const delay = Math.max(500-(Date.now()-timeStart), 0);
-                       setTimeout(() => this.play(compMove, "animate"), delay);
+                       setTimeout(() => {
+                               if (this.mode == "computer") //Warning: mode could have changed!
+                                       this.play(compMove, "animate")
+                       }, delay);
                },
                // Get the identifier of a HTML table cell from its numeric coordinates o.x,o.y.
                getSquareId: function(o) {