Merge branch 'master' into 'master'

Fix AI cheating with ChooseTypeEffect

Closes #1410

See merge request core-developers/forge!2811
This commit is contained in:
Michael Kamensky
2020-05-14 05:31:04 +00:00
2 changed files with 6 additions and 3 deletions

View File

@@ -2201,10 +2201,13 @@ public class ComputerUtil {
return getCardsToDiscardFromOpponent(aiChooser, p, sa, validCards, min, max); return getCardsToDiscardFromOpponent(aiChooser, p, sa, validCards, min, max);
} }
public static String chooseSomeType(Player ai, String kindOfType, String logic, List<String> invalidTypes) { public static String chooseSomeType(Player ai, String kindOfType, String logic, Collection<String> validTypes, List<String> invalidTypes) {
if (invalidTypes == null) { if (invalidTypes == null) {
invalidTypes = ImmutableList.of(); invalidTypes = ImmutableList.of();
} }
if (validTypes == null) {
validTypes = ImmutableList.of();
}
final Game game = ai.getGame(); final Game game = ai.getGame();
String chosen = ""; String chosen = "";
@@ -2228,7 +2231,7 @@ public class ComputerUtil {
} }
} }
if (StringUtils.isEmpty(chosen)) { if (StringUtils.isEmpty(chosen)) {
chosen = "Creature"; chosen = validTypes.isEmpty() ? "Creature" : Aggregates.random(validTypes);
} }
} else if (kindOfType.equals("Creature")) { } else if (kindOfType.equals("Creature")) {
if (logic != null) { if (logic != null) {

View File

@@ -503,7 +503,7 @@ public class PlayerControllerAi extends PlayerController {
@Override @Override
public String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes, boolean isOptional) { public String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes, boolean isOptional) {
String chosen = ComputerUtil.chooseSomeType(player, kindOfType, sa.getParam("AILogic"), invalidTypes); String chosen = ComputerUtil.chooseSomeType(player, kindOfType, sa.getParam("AILogic"), validTypes, invalidTypes);
if (StringUtils.isBlank(chosen) && !validTypes.isEmpty()) { if (StringUtils.isBlank(chosen) && !validTypes.isEmpty()) {
chosen = validTypes.iterator().next(); chosen = validTypes.iterator().next();
System.err.println("AI has no idea how to choose " + kindOfType +", defaulting to arbitrary element: chosen"); System.err.println("AI has no idea how to choose " + kindOfType +", defaulting to arbitrary element: chosen");