Show best moves and the optimal line in review

Closes #19
This commit is contained in:
2026-11-02 21:45:06 +01:00
parent 36548ece8d
commit fa71783e55
3 changed files with 320 additions and 54 deletions
+28
View File
@@ -18,6 +18,10 @@ export const ChessBoard = {
this.showReviewPosition(fen);
});
this.handleEvent("best_line_move", ({ from, to, promotion, san }) => {
this.applyBestLineMove({ from, to, promotion, san });
});
this.handleKeyDown = (event) => {
if (!this.reviewing) return;
@@ -97,6 +101,30 @@ export const ChessBoard = {
});
},
applyBestLineMove({ from, to, promotion, san }) {
const move = promotion
? this.chess.move({ from, to, promotion })
: this.chess.move({ from, to });
if (!move) {
console.error("Best-line move rejected by chess.js", { from, to, promotion, san });
return;
}
const turnColor = this.chess.turn() === "w" ? "white" : "black";
this.ground.set({
fen: this.chess.fen(),
turnColor,
movable: { color: null, dests: new Map() },
});
this.pushEvent("best_line_move_applied", {
fen: this.chess.fen(),
san: move.san,
});
},
initBoard({ fen, orientation, player_color, blocked }) {
try {
this.chess.load(fen);