当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript js.Shogi.get方法代码示例

本文整理汇总了TypeScript中shogi.js.Shogi.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.Shogi.get方法的具体用法?TypeScript js.Shogi.get怎么用?TypeScript js.Shogi.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shogi.js.Shogi的用法示例。


在下文中一共展示了js.Shogi.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: normalizeCSA

export function normalizeCSA(obj: IJSONKifuFormat): IJSONKifuFormat {
    restorePreset(obj);
    const shogi = new Shogi(obj.initial || undefined);
    for (let i = 0; i < obj.moves.length; i++) {
        restoreTotalTime(obj.moves[i].time, i >= 2 ? obj.moves[i - 2].time : void 0);
        const move = obj.moves[i].move;
        if (!move) { continue; }
        // 手番
        move.color = shogi.turn;
        if (move.from) {
            // move

            // same復元
            if (i > 0 && obj.moves[i - 1].move && obj.moves[i - 1].move.to.x === move.to.x
                    && obj.moves[i - 1].move.to.y === move.to.y) {
                move.same = true;
            }

            // capture復元
            addCaptureInformation(shogi, move);
            if (Piece.isPromoted(move.piece)) {
                // 成かも
                const from = shogi.get(move.from.x, move.from.y);
                if (from.kind !== move.piece) {
                    move.piece = from.kind;
                    move.promote = true;
                }
            } else if (Piece.canPromote(move.piece)) {
                // 不成かも
                if (canPromote(move.to, shogi.turn) || canPromote(move.from, shogi.turn)) {
                    move.promote = false;
                }
            }
            // relative復元
            addRelativeInformation(shogi, move);

            try {
                shogi.move(move.from.x, move.from.y, move.to.x, move.to.y, move.promote);
            } catch (e) {
                throw new Error(i + "手目で失敗しました: " + e);
            }
        } else {
            // drop
            if (shogi.getMovesTo(move.to.x, move.to.y, move.piece).length > 0) {
                move.relative = "H";
            }
            shogi.drop(move.to.x, move.to.y, move.piece);
        }
    }
    return obj;
}
开发者ID:na2hiro,项目名称:json-kifu-format,代码行数:51,代码来源:normalizer.ts

示例2: addCaptureInformation

function addCaptureInformation(shogi: Shogi, move: IMoveMoveFormat) {
    const to = shogi.get(move.to.x, move.to.y);
    if (to) { move.capture = to.kind; }
}
开发者ID:na2hiro,项目名称:json-kifu-format,代码行数:4,代码来源:normalizer.ts

示例3: normalizeMinimalMoves

function normalizeMinimalMoves(shogi: Shogi, moves: IMoveFormat[], lastMove?: IMoveFormat) {
    for (let i = 0; i < moves.length; i++) {
        const last = i === 0 ? lastMove : moves[i - 1];
        const move = moves[i].move;
        if (!move) { continue; }
        // 手番
        move.color = shogi.turn;
        if (move.from) {
            // move

            // toからsame復元
            if (last && last.move && move.to.x === last.move.to.x && move.to.y === last.move.to.y) {
                move.same = true;
            }

            // capture復元
            addCaptureInformation(shogi, move);

            // piece復元
            if (!move.piece) {
                move.piece = shogi.get(move.from.x, move.from.y).kind;
            }

            // 不成復元
            if (!move.promote && !Piece.isPromoted(move.piece) && Piece.canPromote(move.piece)) {
                // 成ってない
                if (canPromote(move.to, shogi.turn) || canPromote(move.from, shogi.turn)) {
                    move.promote = false;
                }
            }
            // relative復元
            addRelativeInformation(shogi, move);

            try {
                shogi.move(move.from.x, move.from.y, move.to.x, move.to.y, move.promote);
            } catch (e) {
                throw new Error(i + "手目で失敗しました: " + e);
            }
        } else {
            // drop
            if (shogi.getMovesTo(move.to.x, move.to.y, move.piece).length > 0) {
                move.relative = "H";
            }
            shogi.drop(move.to.x, move.to.y, move.piece);
        }
    }
    restoreColorOfIllegalAction(moves, shogi);
    for (let i = moves.length - 1; i >= 0; i--) {
        const move = moves[i].move;
        if (move) {
            if (move.from) {
                shogi.unmove(move.from.x, move.from.y, move.to.x, move.to.y, move.promote, move.capture);
            } else {
                shogi.undrop(move.to.x, move.to.y);
            }
        }
        const last = i <= 1 ? lastMove : moves[i - 1];
        if (moves[i].forks) {
            for (const fork of moves[i].forks) {
                normalizeMinimalMoves(shogi, fork, last);
            }
        }
    }
}
开发者ID:na2hiro,项目名称:json-kifu-format,代码行数:64,代码来源:normalizer.ts


注:本文中的shogi.js.Shogi.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。