本文整理汇总了TypeScript中shogi.js.Shogi.undrop方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.Shogi.undrop方法的具体用法?TypeScript js.Shogi.undrop怎么用?TypeScript js.Shogi.undrop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shogi.js.Shogi
的用法示例。
在下文中一共展示了js.Shogi.undrop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: normalizeKIFMoves
function normalizeKIFMoves(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
// sameからto復元
if (move.same) { move.to = last.move.to; }
// capture復元
addCaptureInformation(shogi, move);
// 不成復元
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 === 0 ? lastMove : moves[i - 1]; // When first fork has fork, use lastMove of this fork
if (moves[i].forks) {
for (const fork of moves[i].forks) {
normalizeKIFMoves(shogi, fork, last);
}
}
}
}
示例2: normalizeKI2Moves
function normalizeKI2Moves(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;
// 同からto復元
if (move.same) { move.to = last.move.to; }
// from復元
const candMoves = shogi.getMovesTo(move.to.x, move.to.y, move.piece);
if (move.relative === "H" || candMoves.length === 0) {
// ok
} else if (candMoves.length === 1) {
move.from = candMoves[0].from;
} else {
// 相対逆算
const moveAns = filterMovesByRelatives(move.relative, shogi.turn, candMoves);
if (moveAns.length !== 1) { throw new Error("相対情報が不完全で複数の候補があります"); }
move.from = moveAns[0].from;
}
if (move.from) {
// move
// capture復元
addCaptureInformation(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
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) { continue; }
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) {
normalizeKI2Moves(shogi, fork, last);
}
}
}
}