mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
added X cost options to AI
This commit is contained in:
parent
d1f0f5bf43
commit
1945538041
18 changed files with 150 additions and 31 deletions
|
@ -669,7 +669,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean playXMana(VariableManaCost cost, Game game) {
|
||||
public boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game) {
|
||||
logger.debug("playXMana");
|
||||
//put everything into X
|
||||
for (Permanent perm: this.getAvailableManaProducers(game)) {
|
||||
|
|
|
@ -42,9 +42,14 @@ import java.util.concurrent.TimeoutException;
|
|||
import mage.Constants.Outcome;
|
||||
import mage.Constants.PhaseStep;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.common.PassAbility;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.costs.mana.VariableManaCost;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.SearchEffect;
|
||||
import mage.cards.Cards;
|
||||
|
@ -497,6 +502,20 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game) {
|
||||
//SimulatedPlayer.simulateVariableCosts method adds a generic mana cost for each option
|
||||
for (ManaCost manaCost: costs) {
|
||||
if (manaCost instanceof GenericManaCost) {
|
||||
cost.setPayment(manaCost.getPayment());
|
||||
logger.debug("using X = " + cost.getPayment().count());
|
||||
break;
|
||||
}
|
||||
}
|
||||
cost.setPaid();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void playNext(Game game, UUID activePlayerId, SimulationNode node) {
|
||||
boolean skip = false;
|
||||
while (true) {
|
||||
|
@ -611,12 +630,15 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
|||
|
||||
@Override
|
||||
public void selectAttackers(Game game) {
|
||||
logger.debug("selectAttackers");
|
||||
if (logger.isDebugEnabled() && combat == null || combat.getGroups().isEmpty())
|
||||
logger.debug("not attacking");
|
||||
if (combat != null) {
|
||||
UUID opponentId = game.getCombat().getDefenders().iterator().next();
|
||||
for (UUID attackerId: combat.getAttackers()) {
|
||||
this.declareAttacker(attackerId, opponentId, game);
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("attacking with:" + game.getPermanent(attackerId).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -629,6 +651,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
|
|||
if (i < combat.getGroups().size()) {
|
||||
for (UUID blockerId: combat.getGroups().get(i).getBlockers()) {
|
||||
this.declareBlocker(blockerId, groups.get(i).getAttackers().get(0), game);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("blocking with:" + game.getPermanent(blockerId).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,29 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.player.ai;
|
||||
|
@ -13,6 +36,8 @@ import mage.abilities.keyword.DoubleStrikeAbility;
|
|||
import mage.abilities.keyword.FirstStrikeAbility;
|
||||
import mage.abilities.keyword.TrampleAbility;
|
||||
import mage.abilities.mana.ManaAbility;
|
||||
import mage.counters.BoostCounter;
|
||||
import mage.counters.Counter;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
@ -39,9 +64,9 @@ public class GameStateEvaluator {
|
|||
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next());
|
||||
if (game.isGameOver()) {
|
||||
if (player.hasLost() || opponent.hasWon())
|
||||
return Integer.MIN_VALUE;
|
||||
return Integer.MIN_VALUE + 1;
|
||||
if (opponent.hasLost() || player.hasWon())
|
||||
return Integer.MAX_VALUE;
|
||||
return Integer.MAX_VALUE - 1;
|
||||
}
|
||||
int lifeScore = (player.getLife() - opponent.getLife()) * LIFE_FACTOR;
|
||||
int permanentScore = 0;
|
||||
|
@ -73,6 +98,11 @@ public class GameStateEvaluator {
|
|||
if (!(ability instanceof ManaAbility) && ability.canActivate(ability.getControllerId(), game))
|
||||
value += ability.getEffects().size();
|
||||
}
|
||||
for (Counter counter: permanent.getCounters().values()) {
|
||||
if (!(counter instanceof BoostCounter)) {
|
||||
value += counter.getCount();
|
||||
}
|
||||
}
|
||||
value += permanent.getAbilities().getStaticAbilities(Zone.BATTLEFIELD).size();
|
||||
value += permanent.getAbilities().getTriggeredAbilities(Zone.BATTLEFIELD).size();
|
||||
value += permanent.getManaCost().convertedManaCost();
|
||||
|
|
|
@ -38,6 +38,10 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.common.PassAbility;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.costs.mana.VariableManaCost;
|
||||
import mage.abilities.mana.ManaOptions;
|
||||
import mage.choices.Choice;
|
||||
import mage.filter.FilterAbility;
|
||||
|
@ -99,13 +103,23 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
|||
for (Ability ability: playables) {
|
||||
List<Ability> options = game.getPlayer(playerId).getPlayableOptions(ability, game);
|
||||
if (options.size() == 0) {
|
||||
allActions.add(ability);
|
||||
if (ability.getManaCosts().getVariableCosts().size() > 0) {
|
||||
simulateVariableCosts(ability, game);
|
||||
}
|
||||
else {
|
||||
allActions.add(ability);
|
||||
}
|
||||
// simulateAction(game, previousActions, ability);
|
||||
}
|
||||
else {
|
||||
// ExecutorService simulationExecutor = Executors.newFixedThreadPool(4);
|
||||
for (Ability option: options) {
|
||||
allActions.add(option);
|
||||
if (ability.getManaCosts().getVariableCosts().size() > 0) {
|
||||
simulateVariableCosts(option, game);
|
||||
}
|
||||
else {
|
||||
allActions.add(option);
|
||||
}
|
||||
// SimulationWorker worker = new SimulationWorker(game, this, previousActions, option);
|
||||
// simulationExecutor.submit(worker);
|
||||
}
|
||||
|
@ -126,6 +140,30 @@ public class SimulatedPlayer extends ComputerPlayer<SimulatedPlayer> {
|
|||
// }
|
||||
// }
|
||||
|
||||
//add a generic mana cost for each amount possible
|
||||
protected void simulateVariableCosts(Ability ability, Game game) {
|
||||
int numAvailable = getAvailableManaProducers(game).size();
|
||||
for (int i = 0; i < numAvailable; i++) {
|
||||
Ability newAbility = ability.copy();
|
||||
newAbility.addManaCost(new GenericManaCost(i));
|
||||
allActions.add(newAbility);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game) {
|
||||
//simulateVariableCosts method adds a generic mana cost for each option
|
||||
for (ManaCost manaCost: costs) {
|
||||
if (manaCost instanceof GenericManaCost) {
|
||||
cost.setPayment(manaCost.getPayment());
|
||||
logger.debug("simulating -- X = " + cost.getPayment().count());
|
||||
break;
|
||||
}
|
||||
}
|
||||
cost.setPaid();
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Combat> addAttackers(Game game) {
|
||||
Map<Integer, Combat> engagements = new HashMap<Integer, Combat>();
|
||||
//useful only for two player games - will only attack first opponent
|
||||
|
|
|
@ -51,6 +51,7 @@ import mage.abilities.ActivatedAbility;
|
|||
import mage.abilities.SpecialAction;
|
||||
import mage.abilities.costs.common.SacrificeSourceCost;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.costs.mana.VariableManaCost;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.choices.ChoiceImpl;
|
||||
|
@ -355,7 +356,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean playXMana(VariableManaCost cost, Game game) {
|
||||
public boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game) {
|
||||
game.firePlayXManaEvent(playerId, "Pay {X}: {X}=" + cost.getAmount());
|
||||
waitForResponse();
|
||||
if (response.getBoolean() != null) {
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -39,6 +39,7 @@ public interface ManaCost extends Cost {
|
|||
public Mana getMana();
|
||||
public Mana getPayment();
|
||||
public void assignPayment(ManaPool pool);
|
||||
public void setPayment(Mana mana);
|
||||
@Override
|
||||
public String getText();
|
||||
public ManaCost getUnpaid();
|
||||
|
|
|
@ -209,6 +209,11 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
|
|||
this.paid = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPayment(Mana mana) {
|
||||
this.payment.add(mana);
|
||||
}
|
||||
|
||||
protected void addColoredOption(ColoredManaSymbol symbol) {
|
||||
switch (symbol) {
|
||||
case B:
|
||||
|
|
|
@ -116,7 +116,7 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
for (ManaCost cost: this.getUnpaidVariableCosts()) {
|
||||
VariableManaCost vCost = (VariableManaCost) cost;
|
||||
while (!vCost.isPaid()) {
|
||||
if (player.playXMana(vCost, game))
|
||||
if (player.playXMana(vCost, (ManaCosts<ManaCost>) this, game))
|
||||
vCost.assignPayment(player.getManaPool());
|
||||
else
|
||||
return false;
|
||||
|
@ -155,6 +155,9 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
|||
return variableCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPayment(Mana mana) { }
|
||||
|
||||
@Override
|
||||
public void assignPayment(ManaPool pool) {
|
||||
//attempt to pay colored costs first
|
||||
|
|
|
@ -38,7 +38,6 @@ import mage.players.ManaPool;
|
|||
*/
|
||||
public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements VariableCost {
|
||||
|
||||
protected Mana manaPaid = new Mana();
|
||||
protected int multiplier;
|
||||
|
||||
public VariableManaCost() {
|
||||
|
@ -53,7 +52,6 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
|
|||
|
||||
public VariableManaCost(VariableManaCost cost) {
|
||||
super(cost);
|
||||
this.manaPaid = cost.manaPaid.copy();
|
||||
this.multiplier = cost.multiplier;
|
||||
}
|
||||
|
||||
|
@ -64,7 +62,7 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
|
|||
|
||||
@Override
|
||||
public void assignPayment(ManaPool pool) {
|
||||
manaPaid.add(pool.getMana());
|
||||
payment.add(pool.getMana());
|
||||
pool.emptyPool();
|
||||
}
|
||||
|
||||
|
@ -87,19 +85,9 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearPaid() {
|
||||
paid = false;
|
||||
manaPaid.clear();
|
||||
}
|
||||
|
||||
public Mana getPaid() {
|
||||
return manaPaid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return manaPaid.count() / multiplier;
|
||||
return payment.count() / multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,6 +59,7 @@ public interface Card extends MageObject {
|
|||
|
||||
public boolean moveToZone(Zone zone, UUID sourceId, Game game, boolean flag);
|
||||
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game);
|
||||
public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId);
|
||||
public boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId);
|
||||
public void checkTriggers(Zone zone, GameEvent event, Game game);
|
||||
|
||||
|
|
|
@ -246,6 +246,28 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId) {
|
||||
ZoneChangeEvent event = new ZoneChangeEvent(this.objectId, ability.getId(), controllerId, fromZone, Zone.STACK);
|
||||
if (!game.replaceEvent(event)) {
|
||||
if (event.getFromZone() != null) {
|
||||
switch (event.getFromZone()) {
|
||||
case GRAVEYARD:
|
||||
game.getPlayer(ownerId).removeFromGraveyard(this, game);
|
||||
break;
|
||||
default:
|
||||
//logger.warning("moveToZone, not fully implemented: from="+event.getFromZone() + ", to="+event.getToZone());
|
||||
}
|
||||
game.rememberLKI(objectId, event.getFromZone(), this);
|
||||
}
|
||||
game.getStack().push(new Spell(this, ability.copy(), controllerId));
|
||||
game.setZone(objectId, event.getToZone());
|
||||
game.fireEvent(event);
|
||||
return game.getZone(objectId) == Zone.STACK;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game) {
|
||||
Zone fromZone = game.getZone(objectId);
|
||||
|
|
|
@ -297,17 +297,17 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
|
|||
|
||||
@Override
|
||||
public boolean moveToZone(Zone zone, UUID sourceId, Game game, boolean flag) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
throw new UnsupportedOperationException("Unsupported operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToExile(UUID exileId, String name, UUID sourceId, Game game) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
throw new UnsupportedOperationException("Unsupported operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putOntoBattlefield(Game game, Zone fromZone, UUID sourceId, UUID controllerId) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
throw new UnsupportedOperationException("Unsupported operation");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -322,6 +322,11 @@ public class Spell<T extends Spell<T>> implements StackObject, Card {
|
|||
|
||||
@Override
|
||||
public List<Mana> getMana() {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
return card.getMana();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cast(Game game, Zone fromZone, SpellAbility ability, UUID controllerId) {
|
||||
throw new UnsupportedOperationException("Unsupported operation");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import mage.abilities.SpellAbility;
|
|||
import mage.abilities.TriggeredAbilities;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.costs.mana.VariableManaCost;
|
||||
import mage.abilities.effects.ReplacementEffect;
|
||||
import mage.abilities.mana.ManaOptions;
|
||||
|
@ -149,7 +150,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
public abstract boolean chooseUse(Outcome outcome, String message, Game game);
|
||||
public abstract boolean choose(Outcome outcome, Choice choice, Game game);
|
||||
public abstract boolean playMana(ManaCost unpaid, Game game);
|
||||
public abstract boolean playXMana(VariableManaCost cost, Game game);
|
||||
public abstract boolean playXMana(VariableManaCost cost, ManaCosts<ManaCost> costs, Game game);
|
||||
public abstract int chooseEffect(List<ReplacementEffect> rEffects, Game game);
|
||||
public abstract TriggeredAbility chooseTriggeredAbility(TriggeredAbilities abilities, Game game);
|
||||
public abstract void selectAttackers(Game game);
|
||||
|
|
|
@ -375,7 +375,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), playerId))) {
|
||||
game.bookmarkState();
|
||||
removeFromHand(card, game);
|
||||
card.moveToZone(Zone.STACK, ability.getId(), game, false);
|
||||
card.cast(game, Zone.HAND, ability, playerId);
|
||||
Ability spellAbility = game.getStack().getSpell(ability.getId()).getSpellAbility();
|
||||
if (spellAbility.activate(game, noMana)) {
|
||||
for (KickerAbility kicker: card.getAbilities().getKickerAbilities()) {
|
||||
|
|
Loading…
Reference in a new issue