Miracle is optional

This commit is contained in:
Bug Hunter
2022-02-10 12:58:47 +00:00
committed by Michael Kamensky
parent a25a2e548b
commit 4569439385
9 changed files with 35 additions and 20 deletions

View File

@@ -153,10 +153,15 @@ public class AiAttackController {
}
}
/** Choose opponent for AI to attack here. Expand as necessary. */
/**
* Choose opponent for AI to attack here. Expand as necessary.
* No strategy to secure a second place instead, since Forge has no variant for that
*/
public static Player choosePreferredDefenderPlayer(Player ai) {
Player defender = ai.getWeakestOpponent(); //Concentrate on opponent within easy kill range
// TODO connect with evaluateBoardPosition and only fall back to random when no player is the biggest threat by a fair margin
if (defender.getLife() > 8) { //Otherwise choose a random opponent to ensure no ganging up on players
// TODO should we cache the random for each turn? some functions like shouldPumpCard base their decisions on the assumption who will be attacked
return ai.getOpponents().get(MyRandom.getRandom().nextInt(ai.getOpponents().size()));
@@ -720,7 +725,7 @@ public class AiAttackController {
continue;
}
boolean mustAttack = false;
// TODO for nextTurn check if it was temporary
// TODO this might result into attacking the wrong player
if (attacker.isGoaded()) {
mustAttack = true;
} else if (attacker.getSVar("MustAttack").equals("True")) {
@@ -737,7 +742,7 @@ public class AiAttackController {
mustAttack = true;
}
}
if (mustAttack || (attacker.getController().getMustAttackEntity() != null && nextTurn) || (attacker.getController().getMustAttackEntityThisTurn() != null && !nextTurn)) {
if (mustAttack ||attacker.getController().getMustAttackEntityThisTurn() != null) {
combat.addAttacker(attacker, defender);
attackersLeft.remove(attacker);
numForcedAttackers++;

View File

@@ -426,7 +426,6 @@ public class AiBlockController {
}
attackersLeft = new ArrayList<>(currentAttackers);
currentAttackers = new ArrayList<>(attackersLeft);
boolean considerTripleBlock = true;
@@ -437,6 +436,11 @@ public class AiBlockController {
continue;
}
// AI can't handle good blocks with more than three creatures yet
if (CombatUtil.getMinNumBlockersForAttacker(attacker, ai) > (considerTripleBlock ? 3 : 2)) {
continue;
}
int evalAttackerValue = ComputerUtilCard.evaluateCreature(attacker);
blockers = getPossibleBlockers(combat, attacker, blockersLeft, false);
@@ -446,11 +450,6 @@ public class AiBlockController {
int currentValue; // The value of the creatures in the blockgang
boolean foundDoubleBlock = false; // if true, a good double block is found
// AI can't handle good blocks with more than three creatures yet
if (CombatUtil.getMinNumBlockersForAttacker(attacker, ai) > (considerTripleBlock ? 3 : 2)) {
continue;
}
// Try to add blockers that could be destroyed, but are worth less than the attacker
// Don't use blockers without First Strike or Double Strike if attacker has it
usableBlockers = CardLists.filter(blockers, new Predicate<Card>() {
@@ -460,8 +459,7 @@ public class AiBlockController {
&& !ComputerUtilCombat.dealsFirstStrikeDamage(c, false, combat)) {
return false;
}
final boolean randomTrade = wouldLikeToRandomlyTrade(attacker, c, combat);
return lifeInDanger || randomTrade || ComputerUtilCard.evaluateCreature(c) + diff < ComputerUtilCard.evaluateCreature(attacker);
return lifeInDanger || wouldLikeToRandomlyTrade(attacker, c, combat) || ComputerUtilCard.evaluateCreature(c) + diff < ComputerUtilCard.evaluateCreature(attacker);
}
});
if (usableBlockers.size() < 2) {

View File

@@ -2822,8 +2822,6 @@ public class ComputerUtil {
pRating /= 5;
}
System.out.println("Board position evaluation for " + p + ": " + pRating);
if (pRating > bestBoardRating) {
bestBoardRating = pRating;
bestBoardPosition = p;

View File

@@ -830,7 +830,7 @@ public class ComputerUtilCombat {
}
// defender == null means unblocked
if ((defender == null) && mode == TriggerType.AttackerUnblocked) {
if (defender == null && mode == TriggerType.AttackerUnblocked) {
willTrigger = true;
if (!trigger.matchesValidParam("ValidCard", attacker)) {
return false;