Merge pull request #1786 from asvitkine/fix_lands

Fix simulation AI logic related to playing lands.
This commit is contained in:
Anthony Calosa
2022-11-03 20:52:28 +08:00
committed by GitHub
4 changed files with 44 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
package forge.ai.simulation;
import forge.game.spellability.LandAbility;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -154,7 +155,7 @@ public class GameSimulator {
}
public Score simulateSpellAbility(SpellAbility origSa, GameStateEvaluator eval) {
SpellAbility sa;
if (origSa instanceof SpellAbilityPicker.PlayLandAbility) {
if (origSa instanceof LandAbility) {
Card hostCard = (Card) copier.find(origSa.getHostCard());
if (!aiPlayer.playLand(hostCard, false)) {
System.err.println("Simulation: Couldn't play land! " + origSa);
@@ -164,7 +165,7 @@ public class GameSimulator {
// TODO: optimize: prune identical SA (e.g. two of the same card in hand)
sa = findSaInSimGame(origSa);
if (sa == null) {
System.err.println("Simulation: SA not found! " + origSa);
System.err.println("Simulation: SA not found! " + origSa + " / " + origSa.getClass());
return new Score(Integer.MIN_VALUE);
}

View File

@@ -74,7 +74,7 @@ public class SpellAbilityPicker {
continue;
}
landsDeDupe.put(land.getName(), land);
all.add(new PlayLandAbility(land));
all.add(new LandAbility(land));
}
}
List<SpellAbility> candidateSAs = ComputerUtilAbility.getOriginalAndAltCostAbilities(all, player);
@@ -147,8 +147,8 @@ public class SpellAbilityPicker {
private static boolean isSorcerySpeed(SpellAbility sa, Player player) {
// TODO: Can we use the actual rules engine for this instead of trying to do the logic ourselves?
if (sa instanceof PlayLandAbility) {
return false;
if (sa instanceof LandAbility) {
return true;
}
if (sa.isSpell()) {
return !sa.withFlash(sa.getHostCard(), player);
@@ -334,7 +334,7 @@ public class SpellAbilityPicker {
}
private AiPlayDecision canPlayAndPayForSim(final SpellAbility sa) {
if (sa instanceof PlayLandAbility) {
if (sa instanceof LandAbility) {
return AiPlayDecision.WillPlay;
}
if (!sa.canPlay()) {
@@ -452,13 +452,4 @@ public class SpellAbilityPicker {
}
return ComputerUtil.chooseSacrificeType(player, type, ability, ability.getTargetCard(), effect, amount, exclude);
}
public static class PlayLandAbility extends LandAbility {
public PlayLandAbility(Card land) {
super(land);
}
@Override
public String toUnsuppressedString() { return "Play land " + (getHostCard() != null ? getHostCard().getName() : ""); }
}
}