本文整理汇总了TypeScript中shogi.js.Shogi.getMovesTo方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.Shogi.getMovesTo方法的具体用法?TypeScript js.Shogi.getMovesTo怎么用?TypeScript js.Shogi.getMovesTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shogi.js.Shogi
的用法示例。
在下文中一共展示了js.Shogi.getMovesTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
}
示例3: 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;
}
示例4: addRelativeInformation
function addRelativeInformation(shogi: Shogi, move: IMoveMoveFormat) {
const moveVectors = shogi.getMovesTo(move.to.x, move.to.y, move.piece)
.map((mv) => flipVector(shogi.turn, spaceshipVector(mv.to, mv.from)));
if (moveVectors.length >= 2) {
const realVector = flipVector(shogi.turn, spaceshipVector(move.to, move.from));
move.relative = (() => {
// 上下方向唯一
if (moveVectors.filter((mv) => mv.y === realVector.y).length === 1) { return YToUMD(realVector.y); }
// 左右方向唯一
if (moveVectors.filter((mv) => mv.x === realVector.x).length === 1) {
if ((move.piece === "UM" || move.piece === "RY") && realVector.x === 0) {
// 直はだめ
return XToLCR(moveVectors.filter((mv) => mv.x < 0).length === 0 ? -1 : 1);
} else {
return XToLCR(realVector.x);
}
}
// 上下も左右も他の駒がいる
return XToLCR(realVector.x) + YToUMD(realVector.y);
})();
}
}