本文整理汇总了TypeScript中chessground/util.pos2key函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pos2key函数的具体用法?TypeScript pos2key怎么用?TypeScript pos2key使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pos2key函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: capture
export function capture(ctrl: RoundController, key: cg.Key) {
const exploding: cg.Key[] = [],
diff: cg.PiecesDiff = {},
orig = util.key2pos(key),
minX = Math.max(1, orig[0] - 1),
maxX = Math.min(8, orig[0] + 1),
minY = Math.max(1, orig[1] - 1),
maxY = Math.min(8, orig[1] + 1);
const pieces = ctrl.chessground.state.pieces;
for (let x = minX; x <= maxX; x++) {
for (let y = minY; y <= maxY; y++) {
const k = util.pos2key([x, y]);
exploding.push(k);
const explodes = pieces[k] && (
k === key || pieces[k]!.role !== 'pawn')
if (explodes) diff[k] = undefined;
}
}
ctrl.chessground.setPieces(diff);
ctrl.chessground.explode(exploding);
}
示例2: enpassant
export function enpassant(ctrl: RoundController, key: cg.Key, color: cg.Color) {
const pos = util.key2pos(key),
pawnPos: cg.Pos = [pos[0], pos[1] + (color === 'white' ? -1 : 1)];
capture(ctrl, util.pos2key(pawnPos));
}