Merge pull request #5004 from magefree/rystan-marath

Fix AI overuse of Marath X ability with 0 value #4906
This commit is contained in:
LevelX2 2018-06-04 07:28:07 +02:00 committed by GitHub
commit 347fa8aff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 30 deletions

View file

@ -132,8 +132,8 @@ public class SimulatedPlayer2 extends ComputerPlayer {
if (variableManaCost != null) {
int multiplier = variableManaCost.getMultiplier();
for (int mana = 0; mana <= numAvailable; mana++) {
if (mana % multiplier == 0) { // use only values dependant from muliplier
for (int mana = variableManaCost.getMinX(); mana <= numAvailable; mana++) {
if (mana % multiplier == 0) { // use only values dependant from multiplier
int xAmount = mana / multiplier;
Ability newAbility = ability.copy();
VariableManaCost varCost = null;

View file

@ -70,7 +70,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
private static final Logger log = Logger.getLogger(ComputerPlayer.class);
protected int PASSIVITY_PENALTY = 5; // Penalty value for doing nothing if some actions are availble
protected int PASSIVITY_PENALTY = 5; // Penalty value for doing nothing if some actions are available
protected boolean ALLOW_INTERRUPT = true; // change this for test to false / debugging purposes to false to switch off interrupts while debugging
private transient Map<Mana, Card> unplayable = new TreeMap<>();
@ -279,9 +279,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = threats(randomOpponentId, sourceId, ((FilterCreatureOrPlayer) t.getFilter()).getCreatureFilter(), game, target.getTargets());
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(abilityControllerId, permanent.getId(), null, game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.add(permanent.getId(), game);
return true;
}
@ -312,9 +312,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = opponentTargets;
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(permanent.getId(), game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.add(permanent.getId(), game);
return true;
}
@ -346,9 +346,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = ownedTargets;
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(permanent.getId(), game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.add(permanent.getId(), game);
return true;
}
@ -376,11 +376,11 @@ public class ComputerPlayer extends PlayerImpl implements Player {
if (target.getOriginalTarget() instanceof TargetCardInYourGraveyard
|| target.getOriginalTarget() instanceof TargetCardInASingleGraveyard) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
List<Card> cards = new ArrayList<>(game.getPlayer(abilityControllerId).getGraveyard().getCards((FilterCard) target.getFilter(), game));
while (!cards.isEmpty()) {
Card card = pickTarget(cards, outcome, target, null, game);
if (card != null && alreadyTargetted != null && !alreadyTargetted.contains(card.getId())) {
if (card != null && alreadyTargeted != null && !alreadyTargeted.contains(card.getId())) {
target.add(card.getId(), game);
if (target.isChosen()) {
return true;
@ -396,9 +396,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
for (UUID targetId : targets) {
MageObject targetObject = game.getObject(targetId);
if (targetObject != null) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(targetObject.getId(), game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(targetObject.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(targetObject.getId())) {
target.add(targetObject.getId(), game);
return true;
}
@ -547,9 +547,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = game.getBattlefield().getActivePermanents(((FilterCreatureOrPlayer) t.getFilter()).getCreatureFilter(), playerId, game);
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(abilityControllerId, permanent.getId(), source, game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.addTarget(permanent.getId(), source, game);
return true;
}
@ -594,9 +594,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = game.getBattlefield().getActivePermanents(((FilterCreaturePlayerOrPlaneswalker) t.getFilter()).getCreatureFilter(), playerId, game);
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(abilityControllerId, permanent.getId(), source, game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.addTarget(permanent.getId(), source, game);
return true;
}
@ -641,9 +641,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = game.getBattlefield().getActivePermanents(((FilterPermanentOrPlayer) t.getFilter()).getPermanentFilter(), playerId, game);
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(abilityControllerId, permanent.getId(), source, game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.addTarget(permanent.getId(), source, game);
return true;
}
@ -676,9 +676,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
targets = game.getBattlefield().getActivePermanents(((TargetPlayerOrPlaneswalker) t.getFilter()).getFilterPermanent(), playerId, game);
}
for (Permanent permanent : targets) {
List<UUID> alreadyTargetted = target.getTargets();
List<UUID> alreadyTargeted = target.getTargets();
if (t.canTarget(abilityControllerId, permanent.getId(), source, game)) {
if (alreadyTargetted != null && !alreadyTargetted.contains(permanent.getId())) {
if (alreadyTargeted != null && !alreadyTargeted.contains(permanent.getId())) {
target.addTarget(permanent.getId(), source, game);
return true;
}
@ -1382,7 +1382,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
private Abilities<ActivatedManaAbilityImpl> getManaAbilitiesSortedByManaCount(MageObject mageObject, final Game game) {
Abilities<ActivatedManaAbilityImpl> manaAbilities = mageObject.getAbilities().getAvailableActivatedManaAbilities(Zone.BATTLEFIELD, game);
if (manaAbilities.size() > 1) {
// Sort mana abilities by numbver of produced manas, to use ability first that produces most mana (maybe also conditional if possible)
// Sort mana abilities by number of produced manas, to use ability first that produces most mana (maybe also conditional if possible)
Collections.sort(manaAbilities, new Comparator<ActivatedManaAbilityImpl>() {
@Override
public int compare(ActivatedManaAbilityImpl a1, ActivatedManaAbilityImpl a2) {
@ -1472,18 +1472,25 @@ public class ComputerPlayer extends PlayerImpl implements Player {
int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().convertedManaCost();
if (numAvailable < 0) {
numAvailable = 0;
}
if (numAvailable > max) {
numAvailable = max;
} else {
if (numAvailable < min) {
numAvailable = min;
}
if (numAvailable > max) {
numAvailable = max;
}
}
return numAvailable;
}
@Override
public int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variablCost) {
log.debug("announceXMana");
log.debug("announceXCost");
//TODO: improve this
int value = RandomUtil.nextInt(max + 1);
if (value < min) {
value = min;
}
if (value < max) {
value++;
}
@ -1902,7 +1909,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
}
double total = mana.getBlack() + mana.getBlue() + mana.getGreen() + mana.getRed() + mana.getWhite();
// most frequent land is forest by defalt
// most frequent land is forest by default
int mostLand = 0;
String mostLandName = "Forest";
if (mana.getGreen() > 0) {
@ -1999,7 +2006,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
// but also check it can be targeted
betterCard = target.canTarget(getId(), card.getId(), source, game);
} else {
// target object wasn't provided, so acceptings it anyway
// target object wasn't provided, so accepting it anyway
betterCard = true;
}
}

View file

@ -890,12 +890,12 @@ public class PlayerStub implements Player {
@Override
public int announceXMana(int min, int max, String message, Game game, Ability ability) {
return 0;
return min;
}
@Override
public int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variableCost) {
return 0;
return min;
}
@Override