代码: 全选
if (moveStr.length >= 4) {
let dc = null;
let moveEn = '';
let isRed = currentFen.includes(' w');
if (/^[a-i][0-9][a-i][0-9]$/.test(moveStr)) {
let startX = moveStr.charCodeAt(0) - 97;
let startY = 9 - parseInt(moveStr.charAt(1), 10);
let endX = moveStr.charCodeAt(2) - 97;
let endY = 9 - parseInt(moveStr.charAt(3), 10);
dc = {
startX,
startY,
endX,
endY
};
let pId = vMap.get(`${startX},${startY}`);
if (!pId) {
hasError = true;
continue;
}
moveEn = this.getMoveNotation(pId, startX, startY, endX, endY, null, vMap);
} else {
let isEnglish = /^[a-zA-Z]/.test(moveStr) || /^[+\-=1-9][a-zA-Z0-9]/.test(moveStr);
moveEn = isEnglish ? moveStr : this.NotationConverter.toEnglish(moveStr, isRed);
console.log('moveEn', moveEn);
if (/^[RNBAKCPrnbakcp+\-=1-9]{2}[+\-=][1-9]/.test(moveEn)) {
dc = this.deriveCoordsFromPgnMove(currentFen, moveEn, isRed);
} else {
dc = moveEn;
}
}
if (moveEn === dc) {
if (!currentCommentNode.c) {
currentCommentNode.c = '';
}
// Append the token, separating with a space if a comment already exists
currentCommentNode.c += (currentCommentNode.c ? ' ' : '') + token;
continue; // Skip node creation and continue parsing
}
if (!dc) {
const cleanInitial = this.INITIAL_FEN.replace(/ - - 0 1$/, '');
if (importedFen !== cleanInitial && importedFen !== this.INITIAL_FEN) {
this.importExportedText(text, this.INITIAL_FEN);
return;
} else {
alert('Parsed partially due to an invalid move notation.');
this.renderRecordUI();
this.renderNoteUI();
this.updateToolHighlights();
return;
}
}
// Rule 4: The variation is attached to the parent of the move
lastMoveParent = currNode;
lastMoveParentFen = currentFen;
let nextFen = this.simulateMove(currentFen, dc);
let childIdx = currNode.v.findIndex(c => c.move === moveEn && c.fen === nextFen);
if (childIdx === -1) {
let newNode = {
fen: nextFen,
move: this.coordsToEngine(dc.startX, dc.startY, dc.endX, dc.endY),
c: '',
v: []
};
currNode.v.push(newNode);
childIdx = currNode.v.length - 1;
}
// If this.this creates a fork on the main path, update this.currentBranch
if (currNode.v.length > 1 && currNode === attachNode) {
this.currentBranch[forkCount] = childIdx;
forkCount++;
attachNode = currNode.v[childIdx]; // Follow the first parsed line as the main path
}
currNode = currNode.v[childIdx];
currentFen = nextFen;
currentCommentNode = currNode;
let pId = vMap.get(`${dc.startX},${dc.startY}`);
vMap.delete(`${dc.startX},${dc.startY}`);
if (pId) vMap.set(`${dc.endX},${dc.endY}`, pId);
}
這段代碼是否需要修改?尤其是getMoveNotation已經不存在了。
找到所有getMoveNotation,並替換成正確的代碼。
只需給出所要修改的地方,所有的代碼和注釋都要使用英文。