將製作ejcees(中國象棋打譜程式)

分享和讨论Javascript相关的话题
回复
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

static樣式需要調整
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

如果第一步導入都會發生錯誤,則改為新建並往INITIAL_FEN導入,如果仍發生錯誤,則這次導入中止。
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

代码: 全选

改進以下代碼:

一,當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/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

gemini thinking:

代码: 全选

/**
 * 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/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

附件
ejcees20260329withComment999774.7z
(42.75 KiB) 已下载 3 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
头像
ejsoon
圈圈精英
圈圈精英
帖子: 4885
注册时间: 2022年 11月 18日 17:36
为圈友点赞: 173 次
被圈友点赞: 202 次
联系:

Re: 將製作ejcees(中國象棋打譜程式)

帖子 ejsoon »

附件
ejcees20260329withComm999775.7z
(42.75 KiB) 已下载 4 次
https://ejsoon.vip/
弈趣極光:享受思維樂趣
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 2 访客