fix: fix onitama black orientation
This commit is contained in:
parent
98a12b9266
commit
5b310f400d
|
|
@ -34,6 +34,22 @@ function playerHasCard(state: OnitamaState, player: PlayerType, cardName: string
|
|||
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 dy = toY - fromY;
|
||||
|
||||
// 检查移动是否在卡牌的移动候选项中
|
||||
const isValid = card.moveCandidates.some(m => m.dx === dx && m.dy === dy);
|
||||
// 检查移动是否在卡牌的移动候选项中(黑方需要旋转180度)
|
||||
const candidates = getCardMoveCandidates(state, cardName, player);
|
||||
const isValid = candidates.some(m => m.dx === dx && m.dy === dy);
|
||||
if (!isValid) {
|
||||
return `卡牌 ${cardName} 不支持移动 (${dx}, ${dy})`;
|
||||
}
|
||||
|
|
@ -245,14 +262,15 @@ function getAvailableMoves(state: OnitamaState, player: PlayerType): Array<{card
|
|||
|
||||
// 对于每张卡牌
|
||||
for (const cardName of cardNames) {
|
||||
const card = state.cards[cardName];
|
||||
// 获取旋转后的移动候选项(黑方需要旋转180度)
|
||||
const candidates = getCardMoveCandidates(state, cardName, player);
|
||||
|
||||
// 对于每个棋子
|
||||
for (const pawn of playerPawns) {
|
||||
const [fromX, fromY] = pawn.position;
|
||||
|
||||
// 对于卡牌的每个移动
|
||||
for (const move of card.moveCandidates) {
|
||||
for (const move of candidates) {
|
||||
const toX = fromX + move.dx;
|
||||
const toY = fromY + move.dy;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue