]
);
}
- if (this.mode == "friend")
+ if (["friend","problem"].includes(this.mode))
{
actionArray = actionArray.concat(
[
h('h3',
{
domProps: { innerHTML: "Show solution" },
- on: { click: "toggleShowSolution" }
+ on: { click: this.toggleShowSolution },
}
),
h('p',
methods: {
toggleShowSolution: function() {
let problemSolution = document.getElementById("problem-solution");
- problemSolution.style.display = problemSolution.style.display == "none"
- ? "block"
- : "none";
+ problemSolution.style.display =
+ !problemSolution.style.display || problemSolution.style.display == "none"
+ ? "block"
+ : "none";
},
download: function() {
let content = document.getElementById("pgn-game").innerHTML;
this.fenStart = localStorage.getItem(prefix+"fenStart");
}
else
- this.fenStart = fen;
+ this.fenStart = V.ParseFen(fen).position; //this is enough
if (mode=="human")
{
// Opponent found!
{
this.mycolor = Math.random() < 0.5 ? 'w' : 'b';
if (this.mycolor == 'b')
- this.playComputerMove();
+ setTimeout(this.playComputerMove, 100); //small delay for drawing board
}
//else: against a (IRL) friend or problem solving: nothing more to do
},
playComputerMove: function() {
const timeStart = Date.now();
+ // TODO: next call asynchronous (avoid freezing interface while computer "think").
+ // This would also allow to remove some artificial setTimeouts
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);
+ const delay = Math.max(250-(Date.now()-timeStart), 0);
setTimeout(() => {
if (this.mode == "computer") //Warning: mode could have changed!
this.play(compMove, "animate")
}
}
if (this.mode == "computer" && this.vr.turn != this.mycolor)
- this.playComputerMove;
+ setTimeout(this.playComputerMove, 250); //small delay for animation
},
undo: function() {
// Navigate after game is over
undoInGame: function() {
const lm = this.vr.lastMove;
if (!!lm)
+ {
this.vr.undo(lm);
+ const lmBefore = this.vr.lastMove;
+ if (!!lmBefore)
+ {
+ this.vr.undo(lmBefore);
+ this.incheck = this.vr.getCheckSquares(lmBefore);
+ this.vr.play(lmBefore, "ingame");
+ }
+ else
+ this.incheck = [];
+ }
},
},
})