修复AI出牌逻辑:优化目标选择函数,确保AI能正常摸牌后出牌
This commit is contained in:
parent
1e17309168
commit
bce0c3a79b
96
game.js
96
game.js
@ -1497,19 +1497,19 @@ class Game {
|
||||
|
||||
const cardPriority = [
|
||||
{ type: 'peach', condition: () => player.currentHp < player.maxHp, target: null },
|
||||
{ type: 'attack', condition: () => this.attackCount === 0 || canUseMultipleAttacks, target: 'selectTarget', skillCheck: true },
|
||||
{ type: 'duel', condition: () => true, target: 'selectDuelTarget' },
|
||||
{ type: 'attack', condition: () => this.attackCount === 0 || canUseMultipleAttacks, target: 'aiSelectTarget', skillCheck: true },
|
||||
{ type: 'duel', condition: () => true, target: 'aiSelectDuelTarget' },
|
||||
{ type: 'barbarian', condition: () => true, target: null },
|
||||
{ type: 'arrow', condition: () => true, target: null },
|
||||
{ type: 'fireAttack', condition: () => true, target: 'selectFireAttackTarget' },
|
||||
{ type: 'dismantlement', condition: () => true, target: 'selectDismantleTarget' },
|
||||
{ type: 'steal', condition: () => true, target: 'selectStealTarget' },
|
||||
{ type: 'chain', condition: () => true, target: 'selectChainTarget' },
|
||||
{ type: 'happy', condition: () => true, target: 'selectHappyTarget' },
|
||||
{ type: 'starvation', condition: () => true, target: 'selectStarvationTarget' },
|
||||
{ type: 'lightning', condition: () => true, target: 'selectLightningTarget' },
|
||||
{ type: 'fireAttack', condition: () => true, target: 'aiSelectFireAttackTarget' },
|
||||
{ type: 'dismantlement', condition: () => true, target: 'aiSelectDismantleTarget' },
|
||||
{ type: 'steal', condition: () => true, target: 'aiSelectStealTarget' },
|
||||
{ type: 'chain', condition: () => true, target: 'aiSelectChainTarget' },
|
||||
{ type: 'happy', condition: () => true, target: 'aiSelectHappyTarget' },
|
||||
{ type: 'starvation', condition: () => true, target: 'aiSelectStarvationTarget' },
|
||||
{ type: 'lightning', condition: () => true, target: 'aiSelectLightningTarget' },
|
||||
{ type: 'draw', condition: () => true, target: null },
|
||||
{ type: 'equip', condition: () => true, target: 'selectEquipCard', isEquip: true }
|
||||
{ type: 'equip', condition: () => true, target: 'aiSelectEquipCard', isEquip: true }
|
||||
];
|
||||
|
||||
const playNextCard = () => {
|
||||
@ -1578,12 +1578,14 @@ class Game {
|
||||
}
|
||||
|
||||
if (targetIndex !== -1 || !priority.target) {
|
||||
this.playCard(cardIndex, targetIndex);
|
||||
const result = this.playCard(cardIndex, targetIndex);
|
||||
if (result) {
|
||||
cardsUsed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cardsUsed) {
|
||||
updateUI();
|
||||
@ -1607,26 +1609,7 @@ class Game {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (player.identity === 'lord') {
|
||||
const rebel = inRangeTargets.find(t => t.identity === 'rebel');
|
||||
if (rebel) return rebel.index;
|
||||
const spy = inRangeTargets.find(t => t.identity === 'spy');
|
||||
if (spy) return spy.index;
|
||||
} else if (player.identity === 'loyalist') {
|
||||
const rebel = inRangeTargets.find(t => t.identity === 'rebel');
|
||||
if (rebel) return rebel.index;
|
||||
} else if (player.identity === 'rebel') {
|
||||
const lord = inRangeTargets.find(t => t.identity === 'lord');
|
||||
if (lord) return lord.index;
|
||||
const loyalist = inRangeTargets.find(t => t.identity === 'loyalist');
|
||||
if (loyalist) return loyalist.index;
|
||||
} else if (player.identity === 'spy') {
|
||||
const weakTarget = inRangeTargets.reduce((weakest, t) =>
|
||||
t.currentHp < weakest.currentHp ? t : weakest, inRangeTargets[0]);
|
||||
if (weakTarget) return weakTarget.index;
|
||||
}
|
||||
|
||||
return inRangeTargets.length > 0 ? inRangeTargets[0].index : -1;
|
||||
return this.selectTargetByIdentity(player, inRangeTargets);
|
||||
}
|
||||
|
||||
useLiuBeiSkillAI(player, ally, cardIndex) {
|
||||
@ -1676,43 +1659,43 @@ class Game {
|
||||
}
|
||||
|
||||
aiSelectDismantleTarget(player, targets) {
|
||||
const targetWithCards = targets.filter(t => t.hand.length > 0);
|
||||
const targetWithCards = targets.filter(t => t.hand.length > 0 || t.equipment.weapon || t.equipment.armor || t.equipment.horsePlus || t.equipment.horseMinus);
|
||||
if (targetWithCards.length > 0) {
|
||||
return this.aiSelectTarget(player, targetWithCards);
|
||||
return this.selectTargetByIdentity(player, targetWithCards);
|
||||
}
|
||||
return this.aiSelectTarget(player, targets);
|
||||
return this.selectTargetByIdentity(player, targets);
|
||||
}
|
||||
|
||||
aiSelectStealTarget(player, targets) {
|
||||
const targetWithCards = targets.filter(t => t.hand.length > 0);
|
||||
if (targetWithCards.length > 0) {
|
||||
return this.aiSelectTarget(player, targetWithCards);
|
||||
return this.selectTargetByIdentity(player, targetWithCards);
|
||||
}
|
||||
return this.aiSelectTarget(player, targets);
|
||||
return this.selectTargetByIdentity(player, targets);
|
||||
}
|
||||
|
||||
aiSelectChainTarget(player, targets) {
|
||||
const unchainedTargets = targets.filter(t => !t.statusEffects.chain);
|
||||
if (unchainedTargets.length > 0) {
|
||||
return this.aiSelectTarget(player, unchainedTargets);
|
||||
return this.selectTargetByIdentity(player, unchainedTargets);
|
||||
}
|
||||
return this.aiSelectTarget(player, targets);
|
||||
return this.selectTargetByIdentity(player, targets);
|
||||
}
|
||||
|
||||
aiSelectHappyTarget(player, targets) {
|
||||
const dangerousTargets = targets.filter(t => t.hand.length >= 3);
|
||||
if (dangerousTargets.length > 0) {
|
||||
return this.aiSelectTarget(player, dangerousTargets);
|
||||
return this.selectTargetByIdentity(player, dangerousTargets);
|
||||
}
|
||||
return this.aiSelectTarget(player, targets);
|
||||
return this.selectTargetByIdentity(player, targets);
|
||||
}
|
||||
|
||||
aiSelectStarvationTarget(player, targets) {
|
||||
const inRangeTargets = targets.filter(t => this.isInRange(t.index));
|
||||
if (inRangeTargets.length > 0) {
|
||||
return this.aiSelectTarget(player, inRangeTargets);
|
||||
return this.selectTargetByIdentity(player, inRangeTargets);
|
||||
}
|
||||
return -1;
|
||||
return this.selectTargetByIdentity(player, targets);
|
||||
}
|
||||
|
||||
aiSelectLightningTarget(player, targets) {
|
||||
@ -1727,9 +1710,34 @@ class Game {
|
||||
});
|
||||
|
||||
if (enemyTargets.length > 0) {
|
||||
return this.aiSelectTarget(player, enemyTargets);
|
||||
return this.selectTargetByIdentity(player, enemyTargets);
|
||||
}
|
||||
return this.aiSelectTarget(player, targets);
|
||||
return this.selectTargetByIdentity(player, targets);
|
||||
}
|
||||
|
||||
selectTargetByIdentity(player, targets) {
|
||||
if (targets.length === 0) return -1;
|
||||
|
||||
if (player.identity === 'lord') {
|
||||
const rebel = targets.find(t => t.identity === 'rebel');
|
||||
if (rebel) return rebel.index;
|
||||
const spy = targets.find(t => t.identity === 'spy');
|
||||
if (spy) return spy.index;
|
||||
} else if (player.identity === 'loyalist') {
|
||||
const rebel = targets.find(t => t.identity === 'rebel');
|
||||
if (rebel) return rebel.index;
|
||||
} else if (player.identity === 'rebel') {
|
||||
const lord = targets.find(t => t.identity === 'lord');
|
||||
if (lord) return lord.index;
|
||||
const loyalist = targets.find(t => t.identity === 'loyalist');
|
||||
if (loyalist) return loyalist.index;
|
||||
} else if (player.identity === 'spy') {
|
||||
const weakTarget = targets.reduce((weakest, t) =>
|
||||
t.currentHp < weakest.currentHp ? t : weakest, targets[0]);
|
||||
if (weakTarget) return weakTarget.index;
|
||||
}
|
||||
|
||||
return targets.length > 0 ? targets[0].index : -1;
|
||||
}
|
||||
|
||||
aiSelectEquipCard(player) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user