將製作ejcees(中國象棋打譜程式)
Re: 將製作ejcees(中國象棋打譜程式)
https://ejsoon.vip/wp-content/uploads/2 ... 99771.html
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
代码: 全选
改進以下代碼:
一,當path的根節點存在path.c且不為空時,在「fen + '\n'」的後面加上「path.c + \n」。
二,當任何節點存在path.c且不為空時,在它下方加「\n + path.c + \n」。如果輪到紅方,則加完後,接下來黑方會加入 「...」省略號。
例如之前是「1. 炮二平五 馬8進7」,現在就變為「
1. 炮二平五
對於炮二平五的評論。
1. ... 馬8進7
」
給出完整的generateCnTextWidthComment函式,所有代碼和注釋都要使用英文。
function generateCnTextWidthComment() {
let path = getGamePath();
let fen = path.fen;
let text = fen + '\n';
let isRedTurn = fen.split(' ')[1] === 'w';
let moveIdx = 0;
let moveNum = 1;
while (path.v.length) {
let line = `${moveNum}. `;
if (!isRedTurn && moveIdx === 0) {
path = path.v[0];
let blkMove = isEnglish ? path.move : NotationConverter.toChinese(path.move);
line += `... ${blkMove}`;
moveIdx++;
} else {
path = path.v[0];
let redMove = isEnglish ? path.move : NotationConverter.toChinese(path.move);
line += `${redMove}`;
moveIdx++;
if (path.v.length) {
path = path.v[0];
let blkMove = isEnglish ? path.move : NotationConverter.toChinese(path.move);
line += ` ${blkMove}`;
moveIdx++;
}
}
text += line + '\n';
moveNum++;
}
return text.trim();
}
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
代码: 全选
/**
* Generates game notation text including FEN, moves, and comments.
* Handles automatic ellipsis (...) insertion when a comment interrupts a turn.
*/
function generateCnTextWidthComment() {
const pathRoot = getGamePath();
const fen = pathRoot.fen;
let text = fen + '\n';
// Requirement 1: Add root comment if it exists and is not empty
if (pathRoot.c && pathRoot.c.trim() !== '') {
text += pathRoot.c.trim() + '\n';
}
let isRedTurn = fen.split(' ')[1] === 'w';
let moveNum = 1; // Standard starting move number
let currentNode = pathRoot;
// Tracks if the previous move was interrupted by a comment
// or if the game started on a Black move.
let needsEllipsis = !isRedTurn;
while (currentNode.v && currentNode.v.length > 0) {
// Move to the next node in the main variation
currentNode = currentNode.v[0];
// Convert move notation based on language setting
const moveStr = typeof isEnglish !== 'undefined' && isEnglish
? currentNode.move
: NotationConverter.toChinese(currentNode.move);
if (isRedTurn) {
// RED TURN PROCESSING
text += `${moveNum}. ${moveStr}`;
// Requirement 2: Check for comment after Red move
if (currentNode.c && currentNode.c.trim() !== '') {
text += `\n${currentNode.c.trim()}\n`;
needsEllipsis = true; // Black will need "..." on the next line
} else {
text += " "; // Add space to separate from potential Black move
needsEllipsis = false;
}
isRedTurn = false; // Toggle turn to Black
} else {
// BLACK TURN PROCESSING
if (needsEllipsis) {
// If interrupted by Red's comment or starting mid-turn
text += `${moveNum}. ... ${moveStr}\n`;
} else {
// Standard flow: Black follows Red on the same line
text += `${moveStr}\n`;
}
// Requirement 2: Check for comment after Black move
if (currentNode.c && currentNode.c.trim() !== '') {
text += `${currentNode.c.trim()}\n`;
}
moveNum++; // Increment move number after Black finishes
isRedTurn = true; // Toggle turn to Red
needsEllipsis = false; // Reset ellipsis flag
}
}
return text.trim();
}https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
這下帶序號的帶評論了:
https://ejsoon.vip/wp-content/uploads/2 ... 99774.html
- 附件
-
ejcees20260329withComment999774.7z- (42.75 KiB) 已下载 3 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
Re: 將製作ejcees(中國象棋打譜程式)
改對評論的單雙次按出結果:
https://ejsoon.vip/wp-content/uploads/2 ... 99775.html
- 附件
-
ejcees20260329withComm999775.7z- (42.75 KiB) 已下载 4 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
弈趣極光:享受思維樂趣
在线用户
正浏览此版面之用户: 没有注册用户 和 2 访客
