mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
* AI player - Fixed a problem that AI uses Sphinx of Jwar Isle ability in an endless loop.
This commit is contained in:
parent
1cb3290cf3
commit
abfe517c17
7 changed files with 57 additions and 22 deletions
|
@ -62,6 +62,7 @@ import mage.target.Targets;
|
|||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import mage.player.ai.ma.optimizers.impl.OutcomeOptimizer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -74,22 +75,23 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
protected int maxDepth;
|
||||
protected int maxNodes;
|
||||
protected int maxThink;
|
||||
protected LinkedList<Ability> actions = new LinkedList<Ability>();
|
||||
protected List<UUID> targets = new ArrayList<UUID>();
|
||||
protected List<String> choices = new ArrayList<String>();
|
||||
protected LinkedList<Ability> actions = new LinkedList<>();
|
||||
protected List<UUID> targets = new ArrayList<>();
|
||||
protected List<String> choices = new ArrayList<>();
|
||||
protected Combat combat;
|
||||
protected int currentScore;
|
||||
protected SimulationNode2 root;
|
||||
private static final String FILE_WITH_INSTRUCTIONS = "config/ai.please.cast.this.txt";
|
||||
private List<String> suggested = new ArrayList<String>();
|
||||
private final List<String> suggested = new ArrayList<>();
|
||||
protected Set<String> actionCache;
|
||||
private static final List<TreeOptimizer> optimizers = new ArrayList<TreeOptimizer>();
|
||||
private static final List<TreeOptimizer> optimizers = new ArrayList<>();
|
||||
protected int lastLoggedTurn = 0;
|
||||
|
||||
static {
|
||||
optimizers.add(new LevelUpOptimizer());
|
||||
optimizers.add(new EquipOptimizer());
|
||||
optimizers.add(new DiscardCardOptimizer());
|
||||
optimizers.add(new OutcomeOptimizer());
|
||||
}
|
||||
|
||||
public ComputerPlayer6(String name, RangeOfInfluence range, int skill) {
|
||||
|
@ -102,7 +104,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
maxThink = skill * 3;
|
||||
maxNodes = Config2.maxNodes;
|
||||
getSuggestedActions();
|
||||
this.actionCache = new HashSet<String>();
|
||||
this.actionCache = new HashSet<>();
|
||||
}
|
||||
|
||||
public ComputerPlayer6(final ComputerPlayer6 player) {
|
||||
|
@ -275,7 +277,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
//GameStateEvaluator2.evaluate(playerId, root.getGame());
|
||||
int bestScore = root.getScore();
|
||||
//if (bestScore > currentScore) {
|
||||
actions = new LinkedList<Ability>(root.abilities);
|
||||
actions = new LinkedList<>(root.abilities);
|
||||
combat = root.combat;
|
||||
//} else {
|
||||
//System.out.println("[" + game.getPlayer(playerId).getName() + "] Action: not better score");
|
||||
|
@ -314,7 +316,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
*/
|
||||
|
||||
logger.info("simulating -- continuing previous action chain");
|
||||
actions = new LinkedList<Ability>(root.abilities);
|
||||
actions = new LinkedList<>(root.abilities);
|
||||
combat = root.combat;
|
||||
return true;
|
||||
} else {
|
||||
|
@ -646,6 +648,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
/**
|
||||
* Various AI optimizations for actions.
|
||||
*
|
||||
* @param game
|
||||
* @param allActions
|
||||
*/
|
||||
protected void optimize(Game game, List<Ability> allActions) {
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package mage.player.ai.ma.optimizers;
|
||||
|
||||
import java.util.List;
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for ai optimizer that cuts the tree of decision.
|
||||
*
|
||||
|
|
|
@ -54,7 +54,7 @@ public abstract class BaseTreeOptimizer implements TreeOptimizer {
|
|||
*/
|
||||
protected void removeAbility(Ability ability) {
|
||||
if (toRemove == null) {
|
||||
toRemove = new ArrayList<Ability>();
|
||||
toRemove = new ArrayList<>();
|
||||
}
|
||||
toRemove.add(ability);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package mage.player.ai.ma.optimizers.impl;
|
||||
|
||||
import java.util.List;
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Removes abilities that require only discard a card for activation.
|
||||
*
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package mage.player.ai.ma.optimizers.impl;
|
||||
|
||||
import java.util.List;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.keyword.EquipAbility;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Make sure that AI won't equip the same creature equip already attached to.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package mage.player.ai.ma.optimizers.impl;
|
||||
|
||||
import java.util.List;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* Removes abilities that require only discard a card for activation.
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class OutcomeOptimizer extends BaseTreeOptimizer {
|
||||
|
||||
@Override
|
||||
public void filter(Game game, List<Ability> actions) {
|
||||
for (Ability ability : actions) {
|
||||
for (Effect effect: ability.getEffects()) {
|
||||
if (effect.getOutcome().equals(Outcome.AIDontUseIt)) {
|
||||
removeAbility(ability);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,10 +28,6 @@
|
|||
package mage.sets.zendikar;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Zone;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
|
@ -43,6 +39,10 @@ import mage.cards.Card;
|
|||
import mage.cards.CardImpl;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
|
@ -61,8 +61,11 @@ public class SphinxOfJwarIsle extends CardImpl<SphinxOfJwarIsle> {
|
|||
this.power = new MageInt(5);
|
||||
this.toughness = new MageInt(5);
|
||||
|
||||
// Flying, shroud
|
||||
this.addAbility(FlyingAbility.getInstance());
|
||||
this.addAbility(ShroudAbility.getInstance());
|
||||
|
||||
// You may look at the top card of your library. (You may do this at any time.)
|
||||
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new SphinxOfJwarIsleEffect(), new GenericManaCost(0)));
|
||||
}
|
||||
|
||||
|
@ -79,7 +82,7 @@ public class SphinxOfJwarIsle extends CardImpl<SphinxOfJwarIsle> {
|
|||
class SphinxOfJwarIsleEffect extends OneShotEffect<SphinxOfJwarIsleEffect> {
|
||||
|
||||
public SphinxOfJwarIsleEffect() {
|
||||
super(Outcome.Neutral);
|
||||
super(Outcome.AIDontUseIt); // AI can't use the information anyway and seems to do it again and again
|
||||
this.staticText = "You may look at the top card of your library";
|
||||
}
|
||||
|
||||
|
@ -101,8 +104,7 @@ class SphinxOfJwarIsleEffect extends OneShotEffect<SphinxOfJwarIsleEffect> {
|
|||
|
||||
Card card = player.getLibrary().getFromTop(game);
|
||||
if (card != null) {
|
||||
Cards cards = new CardsImpl(Zone.PICK);
|
||||
cards.add(card);
|
||||
Cards cards = new CardsImpl(card);
|
||||
player.lookAtCards("Sphinx of Jwar Isle", cards, game);
|
||||
} else {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue