},
},
})
+ if (this.mode == "analyze")
+ {
+ this.mycolor = V.ParseFen(fen).turn;
+ this.orientation = this.mycolor;
+ }
//////////////////
// 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);
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
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;
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;
},
},
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();