fix: fix onitama black orientation

This commit is contained in:
hypercross 2026-04-08 09:00:25 +08:00
parent 98a12b9266
commit 5b310f400d
1 changed files with 36 additions and 18 deletions

View File

@ -34,6 +34,22 @@ function playerHasCard(state: OnitamaState, player: PlayerType, cardName: string
return cardList.includes(cardName); return cardList.includes(cardName);
} }
/**
*
* 180
*/
function getCardMoveCandidates(state: OnitamaState, cardName: string, player: PlayerType) {
const card = state.cards[cardName];
const candidates = card.moveCandidates;
// 黑方需要将卡牌旋转180度
if (player === 'black') {
return candidates.map(m => ({ dx: -m.dx, dy: -m.dy }));
}
return candidates;
}
/** /**
* *
*/ */
@ -62,8 +78,9 @@ function isValidMove(state: OnitamaState, cardName: string, fromX: number, fromY
const dx = toX - fromX; const dx = toX - fromX;
const dy = toY - fromY; const dy = toY - fromY;
// 检查移动是否在卡牌的移动候选项中 // 检查移动是否在卡牌的移动候选项中黑方需要旋转180度
const isValid = card.moveCandidates.some(m => m.dx === dx && m.dy === dy); const candidates = getCardMoveCandidates(state, cardName, player);
const isValid = candidates.some(m => m.dx === dx && m.dy === dy);
if (!isValid) { if (!isValid) {
return `卡牌 ${cardName} 不支持移动 (${dx}, ${dy})`; return `卡牌 ${cardName} 不支持移动 (${dx}, ${dy})`;
} }
@ -245,14 +262,15 @@ function getAvailableMoves(state: OnitamaState, player: PlayerType): Array<{card
// 对于每张卡牌 // 对于每张卡牌
for (const cardName of cardNames) { for (const cardName of cardNames) {
const card = state.cards[cardName]; // 获取旋转后的移动候选项黑方需要旋转180度
const candidates = getCardMoveCandidates(state, cardName, player);
// 对于每个棋子 // 对于每个棋子
for (const pawn of playerPawns) { for (const pawn of playerPawns) {
const [fromX, fromY] = pawn.position; const [fromX, fromY] = pawn.position;
// 对于卡牌的每个移动 // 对于卡牌的每个移动
for (const move of card.moveCandidates) { for (const move of candidates) {
const toX = fromX + move.dx; const toX = fromX + move.dx;
const toY = fromY + move.dy; const toY = fromY + move.dy;