| import { Chess } from "../../../libs/chess.js"; |
| import { Classification } from "../../classification/MoveClassifier.js"; |
|
|
| export const IgnoredSuggestionTypes = [ |
| Classification.BRILLIANT.type, |
| Classification.GREAT.type, |
| Classification.PERFECT.type, |
| Classification.THEORY.type, |
| Classification.FORCED.type |
| ]; |
|
|
| export class MoveInformation { |
| constructor() {} |
|
|
| |
| |
| |
| |
| |
| |
| static convertUCIToSAN(uci, fen) { |
| const tempChess = new Chess(fen); |
| const from = uci.substring(0, 2); |
| const to = uci.substring(2, 4); |
| const promotion = uci.length > 4 ? uci.substring(4, 5) : undefined; |
| const moveObj = tempChess.move({ from, to, promotion }); |
| return moveObj.san; |
| } |
|
|
| |
| |
| |
| |
| |
| static updateMoveInfo(node, prevNode) { |
| const $moveInfo = $(".move-info").empty(); |
|
|
| |
| if (!node || node.id === 'root' || !node.move) { |
| $("<div>").addClass("move-info-placeholder") |
| .text("Select a move to see its classification.") |
| .appendTo($moveInfo); |
| return; |
| } |
|
|
| |
| const $moveInfoContainer = $("<div>").addClass("move-classification-info"); |
|
|
| |
| if (node.classification) { |
| const $moveInfoLine = $("<div>").addClass("classification-line"); |
|
|
| |
| const $moveLeftSide = $("<div>").addClass("move-left-side"); |
|
|
| |
| const trueClassification = Classification[node.classification.toUpperCase()]; |
| if (trueClassification?.cachedImg) { |
| const originalImg = trueClassification.cachedImg; |
| const clone = originalImg.cloneNode(true); |
| $moveLeftSide.append(clone); |
| } else { |
| $("<img>").addClass("move-icon") |
| .attr("src", trueClassification.src) |
| .attr("alt", node.classification) |
| .appendTo($moveLeftSide); |
| } |
|
|
| $("<span>").addClass("move") |
| .addClass(trueClassification.class) |
| .text(node.move.san + " " + trueClassification.comment) |
| .appendTo($moveLeftSide); |
|
|
| $moveInfoLine.append($moveLeftSide); |
|
|
| |
| if (node.evaluatedMove?.lines?.length > 0 && !IgnoredSuggestionTypes.includes(node.classification)) { |
|
|
| |
| if (prevNode?.evaluatedMove?.lines) { |
| const bestLine = prevNode.evaluatedMove.lines.find(line => line.id === 1); |
| if (bestLine) { |
| |
| const bestMoveUci = bestLine.uciMove || (bestLine.pv && bestLine.pv.length > 0 ? bestLine.pv[0] : null); |
|
|
| if (bestMoveUci) { |
| const san = MoveInformation.convertUCIToSAN(bestMoveUci, prevNode.fen); |
| $("<div>").addClass("perfect-move-alternative") |
| .text("Best was " + san) |
| .appendTo($moveInfoLine); |
| } |
| } |
| } |
| } |
|
|
| $moveInfoContainer.append($moveInfoLine); |
| } |
|
|
| |
| $moveInfo.append($moveInfoContainer); |
| } |
| } |