mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 05:09:16 -08:00
fixes + optimizations + updates to monte carlo ai
This commit is contained in:
parent
23616432e4
commit
7fce6c552d
16 changed files with 312 additions and 228 deletions
|
|
@ -374,9 +374,14 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
|||
|
||||
@Override
|
||||
public void addCost(Cost cost) {
|
||||
if (cost != null) {
|
||||
this.costs.add(cost);
|
||||
}
|
||||
if (cost != null) {
|
||||
if (cost instanceof ManaCost) {
|
||||
this.addManaCost((ManaCost)cost);
|
||||
}
|
||||
else {
|
||||
this.costs.add(cost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -99,8 +99,6 @@ public abstract class ActivatedAbilityImpl<T extends ActivatedAbilityImpl<T>> ex
|
|||
if (cost != null) {
|
||||
if (cost instanceof PhyrexianManaCost) {
|
||||
this.addManaCost((PhyrexianManaCost)cost);
|
||||
} else if (cost instanceof ManaCost) {
|
||||
this.addManaCost((ManaCost) cost);
|
||||
} else {
|
||||
this.addCost(cost);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import mage.Constants.Layer;
|
|||
import mage.Constants.SubLayer;
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
|
@ -245,17 +246,20 @@ public class ContinuousEffects implements Serializable {
|
|||
public List<RequirementEffect> getApplicableRequirementEffects(Permanent permanent, Game game) {
|
||||
List<RequirementEffect> effects = new ArrayList<RequirementEffect>();
|
||||
//get all applicable Requirement effects on the battlefield
|
||||
for (Permanent perm: game.getBattlefield().getActivePermanents(permanent.getControllerId(), game)) {
|
||||
for (Entry<Effect, Ability> entry: perm.getAbilities().getEffects(game, Zone.BATTLEFIELD, EffectType.REQUIREMENT).entrySet()) {
|
||||
if (((RequirementEffect)entry.getKey()).applies(permanent, entry.getValue(), game)) {
|
||||
effects.add((RequirementEffect)entry.getKey());
|
||||
abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (Permanent perm: game.getBattlefield().getActivePermanents(permanent.getControllerId(), game)) {
|
||||
// for (Entry<Effect, Ability> entry: perm.getAbilities().getEffects(game, Zone.BATTLEFIELD, EffectType.REQUIREMENT).entrySet()) {
|
||||
// if (((RequirementEffect)entry.getKey()).applies(permanent, entry.getValue(), game)) {
|
||||
// effects.add((RequirementEffect)entry.getKey());
|
||||
// abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for (RequirementEffect effect: requirementEffects) {
|
||||
if (effect.applies(permanent, abilityMap.get(effect.getId()), game))
|
||||
effects.add(effect);
|
||||
Ability ability = abilityMap.get(effect.getId());
|
||||
if (!(ability instanceof StaticAbility) || ability.getZone() == game.getZone(ability.getSourceId())) {
|
||||
if (effect.applies(permanent, ability, game))
|
||||
effects.add(effect);
|
||||
}
|
||||
}
|
||||
return effects;
|
||||
}
|
||||
|
|
@ -263,17 +267,20 @@ public class ContinuousEffects implements Serializable {
|
|||
public List<RestrictionEffect> getApplicableRestrictionEffects(Permanent permanent, Game game) {
|
||||
List<RestrictionEffect> effects = new ArrayList<RestrictionEffect>();
|
||||
//get all applicable Restriction effects on the battlefield
|
||||
for (Permanent perm: game.getBattlefield().getActivePermanents(permanent.getControllerId(), game)) {
|
||||
for (Entry<Effect, Ability> entry: perm.getAbilities().getEffects(game, Zone.BATTLEFIELD, EffectType.RESTRICTION).entrySet()) {
|
||||
if (((RestrictionEffect)entry.getKey()).applies(permanent, entry.getValue(), game)) {
|
||||
effects.add((RestrictionEffect)entry.getKey());
|
||||
abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (Permanent perm: game.getBattlefield().getActivePermanents(permanent.getControllerId(), game)) {
|
||||
// for (Entry<Effect, Ability> entry: perm.getAbilities().getEffects(game, Zone.BATTLEFIELD, EffectType.RESTRICTION).entrySet()) {
|
||||
// if (((RestrictionEffect)entry.getKey()).applies(permanent, entry.getValue(), game)) {
|
||||
// effects.add((RestrictionEffect)entry.getKey());
|
||||
// abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for (RestrictionEffect effect: restrictionEffects) {
|
||||
if (effect.applies(permanent, abilityMap.get(effect.getId()), game))
|
||||
effects.add(effect);
|
||||
Ability ability = abilityMap.get(effect.getId());
|
||||
if (!(ability instanceof StaticAbility) || ability.getZone() == game.getZone(ability.getSourceId())) {
|
||||
if (effect.applies(permanent, ability, game))
|
||||
effects.add(effect);
|
||||
}
|
||||
}
|
||||
return effects;
|
||||
}
|
||||
|
|
@ -289,49 +296,55 @@ public class ContinuousEffects implements Serializable {
|
|||
if (planeswalkerRedirectionEffect.applies(event, null, game))
|
||||
replaceEffects.add(planeswalkerRedirectionEffect);
|
||||
//get all applicable Replacement effects in each players hand and graveyard
|
||||
for (Card card: game.getCards()) {
|
||||
Zone zone = game.getState().getZone(card.getId());
|
||||
if (zone == Zone.HAND || zone == Zone.GRAVEYARD) {
|
||||
for (Entry<ReplacementEffect, Ability> entry: card.getAbilities().getReplacementEffects(zone).entrySet()) {
|
||||
if (entry.getKey().applies(event, entry.getValue(), game)) {
|
||||
replaceEffects.add(entry.getKey());
|
||||
abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (Card card: game.getCards()) {
|
||||
// Zone zone = game.getState().getZone(card.getId());
|
||||
// if (zone == Zone.HAND || zone == Zone.GRAVEYARD) {
|
||||
// for (Entry<ReplacementEffect, Ability> entry: card.getAbilities().getReplacementEffects(zone).entrySet()) {
|
||||
// if (entry.getKey().applies(event, entry.getValue(), game)) {
|
||||
// replaceEffects.add(entry.getKey());
|
||||
// abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//get all applicable Replacement effects on the battlefield
|
||||
for (Permanent permanent: game.getBattlefield().getAllPermanents()) {
|
||||
for (Entry<ReplacementEffect, Ability> entry: permanent.getAbilities().getReplacementEffects(Zone.BATTLEFIELD).entrySet()) {
|
||||
if (entry.getKey().applies(event, entry.getValue(), game)) {
|
||||
replaceEffects.add(entry.getKey());
|
||||
abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (Permanent permanent: game.getBattlefield().getAllPermanents()) {
|
||||
// for (Entry<ReplacementEffect, Ability> entry: permanent.getAbilities().getReplacementEffects(Zone.BATTLEFIELD).entrySet()) {
|
||||
// if (entry.getKey().applies(event, entry.getValue(), game)) {
|
||||
// replaceEffects.add(entry.getKey());
|
||||
// abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//get all applicable Replacement effects on players
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
for (Entry<ReplacementEffect, Ability> entry: player.getAbilities().getReplacementEffects(Zone.BATTLEFIELD).entrySet()) {
|
||||
if (entry.getKey().applies(event, entry.getValue(), game)) {
|
||||
replaceEffects.add(entry.getKey());
|
||||
abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (Player player: game.getPlayers().values()) {
|
||||
// for (Entry<ReplacementEffect, Ability> entry: player.getAbilities().getReplacementEffects(Zone.BATTLEFIELD).entrySet()) {
|
||||
// if (entry.getKey().applies(event, entry.getValue(), game)) {
|
||||
// replaceEffects.add(entry.getKey());
|
||||
// abilityMap.put(entry.getKey().getId(), entry.getValue());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//get all applicable transient Replacement effects
|
||||
for (ReplacementEffect effect: replacementEffects) {
|
||||
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
|
||||
if (effect.applies(event, abilityMap.get(effect.getId()), game)) {
|
||||
replaceEffects.add(effect);
|
||||
}
|
||||
}
|
||||
Ability ability = abilityMap.get(effect.getId());
|
||||
if (!(ability instanceof StaticAbility) || ability.getZone() == game.getZone(ability.getSourceId())) {
|
||||
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
|
||||
if (effect.applies(event, ability, game)) {
|
||||
replaceEffects.add(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PreventionEffect effect: preventionEffects) {
|
||||
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
|
||||
if (effect.applies(event, abilityMap.get(effect.getId()), game)) {
|
||||
replaceEffects.add(effect);
|
||||
}
|
||||
}
|
||||
Ability ability = abilityMap.get(effect.getId());
|
||||
if (!(ability instanceof StaticAbility) || ability.getZone() == game.getZone(ability.getSourceId())) {
|
||||
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
|
||||
if (effect.applies(event, ability, game)) {
|
||||
replaceEffects.add(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return replaceEffects;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ import org.apache.log4j.Logger;
|
|||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.watchers.common.PlayerDamagedBySourceWatcher;
|
||||
|
||||
public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializable {
|
||||
|
|
@ -192,6 +193,15 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
watcher.setSourceId(card.getId());
|
||||
state.getWatchers().add(watcher);
|
||||
}
|
||||
for (StaticAbility ability: card.getAbilities().getStaticAbilities(Zone.ALL)) {
|
||||
for (Mode mode: ability.getModes().values()) {
|
||||
for (Effect effect: mode.getEffects()) {
|
||||
if (effect instanceof ContinuousEffect) {
|
||||
state.addEffect((ContinuousEffect)effect, ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1228,8 +1228,9 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
Map<String, Ability> playableActivated = new HashMap<String, Ability>();
|
||||
for (Permanent permanent: game.getBattlefield().getAllActivePermanents(playerId)) {
|
||||
for (ActivatedAbility ability: permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD)) {
|
||||
if (canPlay(ability, available, game))
|
||||
playableActivated.put(ability.toString(), ability);
|
||||
if (!playableActivated.containsKey(ability.toString()))
|
||||
if (canPlay(ability, available, game))
|
||||
playableActivated.put(ability.toString(), ability);
|
||||
}
|
||||
}
|
||||
playable.addAll(playableActivated.values());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue