mirror of
https://github.com/correl/mage.git
synced 2025-04-14 01:01:08 -09:00
Fixed AI choosing target with maxNumberOfTargets > 1.
Fixed chooseMode to return the first mode. Refactored a bit.
This commit is contained in:
parent
12728ca92a
commit
d48bcf6d06
3 changed files with 36 additions and 33 deletions
Mage.Server.Plugins
Mage.Player.AI.MA/src/mage/player/ai
Mage.Player.AI/src/main/java/mage/player/ai
Mage.Player.AIMinimax/src/mage/player/ai
|
@ -44,7 +44,6 @@ import mage.cards.Card;
|
||||||
import mage.cards.Cards;
|
import mage.cards.Cards;
|
||||||
import mage.choices.Choice;
|
import mage.choices.Choice;
|
||||||
import mage.filter.FilterAbility;
|
import mage.filter.FilterAbility;
|
||||||
import mage.filter.common.FilterCreatureForAttack;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.combat.Combat;
|
import mage.game.combat.Combat;
|
||||||
import mage.game.combat.CombatGroup;
|
import mage.game.combat.CombatGroup;
|
||||||
|
@ -56,7 +55,6 @@ import mage.game.turn.*;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
import mage.target.TargetCard;
|
import mage.target.TargetCard;
|
||||||
import mage.util.Logging;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -365,6 +363,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
protected Integer addActionsTimed(final FilterAbility filter) {
|
protected Integer addActionsTimed(final FilterAbility filter) {
|
||||||
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
||||||
|
@Override
|
||||||
public Integer call() throws Exception
|
public Integer call() throws Exception
|
||||||
{
|
{
|
||||||
return addActions(root, filter, maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
return addActions(root, filter, maxDepth, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
|
@ -552,7 +551,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean choose(Outcome outcome, Choice choice, Game game) {
|
public boolean choose(Outcome outcome, Choice choice, Game game) {
|
||||||
if (choices.size() == 0)
|
if (choices.isEmpty())
|
||||||
return super.choose(outcome, choice, game);
|
return super.choose(outcome, choice, game);
|
||||||
if (!choice.isChosen()) {
|
if (!choice.isChosen()) {
|
||||||
for (String achoice: choices) {
|
for (String achoice: choices) {
|
||||||
|
@ -569,7 +568,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||||
if (targets.size() == 0)
|
if (targets.isEmpty())
|
||||||
return super.chooseTarget(outcome, cards, target, source, game);
|
return super.chooseTarget(outcome, cards, target, source, game);
|
||||||
if (!target.doneChosing()) {
|
if (!target.doneChosing()) {
|
||||||
for (UUID targetId: targets) {
|
for (UUID targetId: targets) {
|
||||||
|
@ -586,7 +585,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||||
if (targets.size() == 0)
|
if (targets.isEmpty())
|
||||||
return super.choose(outcome, cards, target, game);
|
return super.choose(outcome, cards, target, game);
|
||||||
if (!target.doneChosing()) {
|
if (!target.doneChosing()) {
|
||||||
for (UUID targetId: targets) {
|
for (UUID targetId: targets) {
|
||||||
|
|
|
@ -776,15 +776,18 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||||
log.debug("chooseTarget");
|
log.debug("chooseTarget");
|
||||||
|
if (cards != null && cards.isEmpty()) {
|
||||||
|
if (!target.isRequired())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Card> cardChoices = new ArrayList<Card>(cards.getCards(target.getFilter(), game));
|
||||||
while (!target.doneChosing()) {
|
while (!target.doneChosing()) {
|
||||||
if (cards.isEmpty()) {
|
Card card = pickTarget(cardChoices, outcome, target, source, game);
|
||||||
if (!target.isRequired())
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Card card = pickTarget(new ArrayList<Card>(cards.getCards(target.getFilter(), game)), outcome, target, source, game);
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
target.addTarget(card.getId(), source, game);
|
target.addTarget(card.getId(), source, game);
|
||||||
|
cardChoices.remove(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -794,17 +797,17 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||||
log.debug("choose");
|
log.debug("choose");
|
||||||
if (cards != null && cards.isEmpty()) {
|
if (cards != null && cards.isEmpty()) {
|
||||||
return false;
|
if (!target.isRequired())
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<Card> cardChoices = new ArrayList<Card>(cards.getCards(target.getFilter(), game));
|
||||||
while (!target.doneChosing()) {
|
while (!target.doneChosing()) {
|
||||||
if (cards.isEmpty()) {
|
Card card = pickTarget(cardChoices, outcome, target, null, game);
|
||||||
if (!target.isRequired())
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Card card = pickTarget(new ArrayList<Card>(cards.getCards(target.getFilter(), game)), outcome, target, null, game);
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
target.add(card.getId(), game);
|
target.add(card.getId(), game);
|
||||||
|
cardChoices.remove(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -864,7 +867,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
public Mode chooseMode(Modes modes, Ability source, Game game) {
|
public Mode chooseMode(Modes modes, Ability source, Game game) {
|
||||||
log.debug("chooseMode");
|
log.debug("chooseMode");
|
||||||
//TODO: improve this;
|
//TODO: improve this;
|
||||||
return modes.get(0);
|
return modes.values().iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1000,7 +1003,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card pickBestCard(List<Card> cards, List<Constants.ColoredManaSymbol> chosenColors) {
|
public Card pickBestCard(List<Card> cards, List<Constants.ColoredManaSymbol> chosenColors) {
|
||||||
if (cards.size() == 0) {
|
if (cards.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Card bestCard = null;
|
Card bestCard = null;
|
||||||
|
@ -1016,7 +1019,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card pickWorstCard(List<Card> cards, List<Constants.ColoredManaSymbol> chosenColors) {
|
public Card pickWorstCard(List<Card> cards, List<Constants.ColoredManaSymbol> chosenColors) {
|
||||||
if (cards.size() == 0) {
|
if (cards.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Card worstCard = null;
|
Card worstCard = null;
|
||||||
|
@ -1033,7 +1036,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pickCard(List<Card> cards, Deck deck, Draft draft) {
|
public void pickCard(List<Card> cards, Deck deck, Draft draft) {
|
||||||
if (cards.size() == 0) {
|
if (cards.isEmpty()) {
|
||||||
throw new IllegalArgumentException("No cards to pick from.");
|
throw new IllegalArgumentException("No cards to pick from.");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -1125,17 +1128,17 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
}
|
}
|
||||||
// only two or three color decks are allowed
|
// only two or three color decks are allowed
|
||||||
if (chosenSymbols.size() > 1 && chosenSymbols.size() < 4) {
|
if (chosenSymbols.size() > 1 && chosenSymbols.size() < 4) {
|
||||||
List<Constants.ColoredManaSymbol> chosenColors = new ArrayList<Constants.ColoredManaSymbol>();
|
List<Constants.ColoredManaSymbol> colorsChosen = new ArrayList<Constants.ColoredManaSymbol>();
|
||||||
for (String symbol : chosenSymbols) {
|
for (String symbol : chosenSymbols) {
|
||||||
Constants.ColoredManaSymbol manaSymbol = Constants.ColoredManaSymbol.lookup(symbol.charAt(0));
|
Constants.ColoredManaSymbol manaSymbol = Constants.ColoredManaSymbol.lookup(symbol.charAt(0));
|
||||||
if (manaSymbol != null) {
|
if (manaSymbol != null) {
|
||||||
chosenColors.add(manaSymbol);
|
colorsChosen.add(manaSymbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chosenColors.size() > 1) {
|
if (colorsChosen.size() > 1) {
|
||||||
// no need to remember picks anymore
|
// no need to remember picks anymore
|
||||||
pickedCards = null;
|
pickedCards = null;
|
||||||
return chosenColors;
|
return colorsChosen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,6 +318,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
|
|
||||||
protected void addActionsTimed(final FilterAbility filter) {
|
protected void addActionsTimed(final FilterAbility filter) {
|
||||||
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
FutureTask<Integer> task = new FutureTask<Integer>(new Callable<Integer>() {
|
||||||
|
@Override
|
||||||
public Integer call() throws Exception
|
public Integer call() throws Exception
|
||||||
{
|
{
|
||||||
return addActions(root, filter, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
return addActions(root, filter, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
|
@ -329,8 +330,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
task.get(maxThink, TimeUnit.SECONDS);
|
task.get(maxThink, TimeUnit.SECONDS);
|
||||||
long endTime = System.nanoTime();
|
long endTime = System.nanoTime();
|
||||||
long duration = endTime - startTime;
|
long duration = endTime - startTime;
|
||||||
logger.info("Calculated " + root.nodeCount + " nodes in " + duration/1000000000.0 + "s");
|
logger.info("Calculated " + SimulationNode.nodeCount + " nodes in " + duration/1000000000.0 + "s");
|
||||||
nodeCount += root.nodeCount;
|
nodeCount += SimulationNode.nodeCount;
|
||||||
thinkTime += duration;
|
thinkTime += duration;
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
logger.debug("simulating - timed out");
|
logger.debug("simulating - timed out");
|
||||||
|
@ -343,8 +344,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
}
|
}
|
||||||
long endTime = System.nanoTime();
|
long endTime = System.nanoTime();
|
||||||
long duration = endTime - startTime;
|
long duration = endTime - startTime;
|
||||||
logger.info("Timeout - Calculated " + root.nodeCount + " nodes in " + duration/1000000000.0 + "s");
|
logger.info("Timeout - Calculated " + SimulationNode.nodeCount + " nodes in " + duration/1000000000.0 + "s");
|
||||||
nodeCount += root.nodeCount;
|
nodeCount += SimulationNode.nodeCount;
|
||||||
thinkTime += duration;
|
thinkTime += duration;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
logger.fatal("Simulation error", e);
|
logger.fatal("Simulation error", e);
|
||||||
|
@ -506,7 +507,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean choose(Outcome outcome, Choice choice, Game game) {
|
public boolean choose(Outcome outcome, Choice choice, Game game) {
|
||||||
if (choices.size() == 0)
|
if (choices.isEmpty())
|
||||||
return super.choose(outcome, choice, game);
|
return super.choose(outcome, choice, game);
|
||||||
if (!choice.isChosen()) {
|
if (!choice.isChosen()) {
|
||||||
for (String achoice: choices) {
|
for (String achoice: choices) {
|
||||||
|
@ -523,7 +524,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||||
if (targets.size() == 0)
|
if (targets.isEmpty())
|
||||||
return super.chooseTarget(outcome, cards, target, source, game);
|
return super.chooseTarget(outcome, cards, target, source, game);
|
||||||
if (!target.doneChosing()) {
|
if (!target.doneChosing()) {
|
||||||
for (UUID targetId: targets) {
|
for (UUID targetId: targets) {
|
||||||
|
@ -540,7 +541,7 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||||
if (targets.size() == 0)
|
if (targets.isEmpty())
|
||||||
return super.choose(outcome, cards, target, game);
|
return super.choose(outcome, cards, target, game);
|
||||||
if (!target.doneChosing()) {
|
if (!target.doneChosing()) {
|
||||||
for (UUID targetId: targets) {
|
for (UUID targetId: targets) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue