mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
[AI] enhanced targeting. card fixes
This commit is contained in:
parent
2200fb8572
commit
eefedc03b9
10 changed files with 91 additions and 5 deletions
|
|
@ -607,6 +607,32 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
for (TreeOptimizer optimizer : optimizers) {
|
||||
optimizer.optimize(game, allActions);
|
||||
}
|
||||
Collections.sort(allActions, new Comparator<Ability>() {
|
||||
@Override
|
||||
public int compare(Ability ability, Ability ability1) {
|
||||
String rule = ability.toString();
|
||||
String rule1 = ability1.toString();
|
||||
if (rule.equals("Pass")) {
|
||||
return 1;
|
||||
}
|
||||
if (rule1.equals("Pass")) {
|
||||
return -1;
|
||||
}
|
||||
if (rule.startsWith("Play")) {
|
||||
return -1;
|
||||
}
|
||||
if (rule1.startsWith("Play")) {
|
||||
return 1;
|
||||
}
|
||||
if (rule.startsWith("Cast")) {
|
||||
return -1;
|
||||
}
|
||||
if (rule1.startsWith("Cast")) {
|
||||
return 1;
|
||||
}
|
||||
return ability.getRule().compareTo(ability1.getRule());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected boolean allPassed(Game game) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ 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.cards.Card;
|
||||
import mage.choices.Choice;
|
||||
import mage.game.Game;
|
||||
|
|
@ -118,6 +119,7 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
for (Ability ability: playables) {
|
||||
List<Ability> options = game.getPlayer(playerId).getPlayableOptions(ability, game);
|
||||
options = filterOptions(game, options, ability, suggested);
|
||||
options = optimizeOptions(game, options, ability);
|
||||
if (options.isEmpty()) {
|
||||
if (ability.getManaCosts().getVariableCosts().size() > 0) {
|
||||
simulateVariableCosts(ability, game);
|
||||
|
|
@ -221,6 +223,39 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
return options;
|
||||
}
|
||||
|
||||
protected List<Ability> optimizeOptions(Game game, List<Ability> options, Ability ability) {
|
||||
if (options.isEmpty()) {
|
||||
return options;
|
||||
}
|
||||
|
||||
// determine if all effects are bad
|
||||
Iterator<Ability> iterator = options.iterator();
|
||||
boolean bad = false;
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (effect.getOutcome().isGood()) {
|
||||
bad = false;
|
||||
break;
|
||||
} else {
|
||||
bad = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (bad) {
|
||||
// remove its own creatures for bad effects
|
||||
while (iterator.hasNext()) {
|
||||
Ability ability1 = iterator.next();
|
||||
if (ability1.getTargets().size() == 1) {
|
||||
Permanent permanent = game.getPermanent(ability1.getFirstTarget());
|
||||
if (permanent != null && permanent.getControllerId().equals(playerId)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
//add a generic mana cost for each amount possible
|
||||
protected void simulateVariableCosts(Ability ability, Game game) {
|
||||
int numAvailable = getAvailableManaProducers(game).size();
|
||||
|
|
|
|||
|
|
@ -91,7 +91,15 @@ public class ArtificialScoringSystem {
|
|||
}
|
||||
}
|
||||
}
|
||||
score += equipments*50 + enchantments*100;
|
||||
score += equipments*50 /*+ enchantments*100*/;
|
||||
|
||||
if (!permanent.canAttack(game)) {
|
||||
score -= 100;
|
||||
}
|
||||
|
||||
if (!permanent.canBlockAny(game)) {
|
||||
score -= 30;
|
||||
}
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -88,7 +88,7 @@ class BowerPassageEffect extends RestrictionEffect<BowerPassageEffect> {
|
|||
|
||||
@Override
|
||||
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
|
||||
if (attacker.getControllerId().equals(source.getControllerId()) && blocker.getAbilities().contains(FlyingAbility.getInstance())) {
|
||||
if (attacker != null && attacker.getControllerId().equals(source.getControllerId()) && blocker.getAbilities().contains(FlyingAbility.getInstance())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class HuntedGhoulEffect extends RestrictionEffect<HuntedGhoulEffect> {
|
|||
|
||||
@Override
|
||||
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
|
||||
if (attacker.getSubtype().contains("Human")) {
|
||||
if (attacker != null && attacker.getSubtype().contains("Human")) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.innistrad;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.Constants.Rarity;
|
||||
|
|
@ -44,6 +43,8 @@ import mage.players.Player;
|
|||
import mage.target.TargetPlayer;
|
||||
import mage.target.common.TargetCardInYourGraveyard;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
|
|
@ -93,6 +94,7 @@ class GraveyardShovelEffect extends OneShotEffect<GraveyardShovelEffect> {
|
|||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (targetPlayer != null && controller != null) {
|
||||
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard();
|
||||
target.setRequired(true);
|
||||
if (targetPlayer.chooseTarget(Outcome.Exile, target, source, game)) {
|
||||
Card card = game.getCard(target.getFirstTarget());
|
||||
if (card != null) {
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ public interface Permanent extends Card, Controllable {
|
|||
public void setMinBlockedBy(int minBlockedBy);
|
||||
public boolean canAttack(Game game);
|
||||
public boolean canBlock(UUID attackerId, Game game);
|
||||
public boolean canBlockAny(Game game);
|
||||
public boolean removeFromCombat(Game game);
|
||||
public boolean isDeathtouched();
|
||||
|
||||
|
|
|
|||
|
|
@ -801,6 +801,20 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBlockAny(Game game) {
|
||||
if (tapped)
|
||||
return false;
|
||||
|
||||
//20101001 - 509.1b
|
||||
for (RestrictionEffect effect : game.getContinuousEffects().getApplicableRestrictionEffects(this, game)) {
|
||||
if (!effect.canBlock(null, this, game.getContinuousEffects().getAbility(effect.getId()), game))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttacking(boolean attacking) {
|
||||
this.attacking = attacking;
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ public class TargetPermanent<T extends TargetPermanent<T>> extends TargetObject<
|
|||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<UUID>();
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue