From 2e21b7197bb92e33d4358e8fbd3942864cce2168 Mon Sep 17 00:00:00 2001 From: BetaSteward <betasteward@gmail> Date: Mon, 16 Jan 2012 18:49:11 -0500 Subject: [PATCH] fixes and optimizations for monte carlo ai --- Mage/src/mage/abilities/Abilities.java | 1 + Mage/src/mage/abilities/AbilitiesImpl.java | 14 ++++++++++++++ Mage/src/mage/abilities/AbilityImpl.java | 2 +- Mage/src/mage/game/permanent/PermanentImpl.java | 2 +- Mage/src/mage/players/PlayerImpl.java | 5 ++++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Mage/src/mage/abilities/Abilities.java b/Mage/src/mage/abilities/Abilities.java index 1079191615..fe90578b00 100644 --- a/Mage/src/mage/abilities/Abilities.java +++ b/Mage/src/mage/abilities/Abilities.java @@ -261,4 +261,5 @@ public interface Abilities<T extends Ability> extends List<T>, Serializable { public Map<ReplacementEffect, Ability> getReplacementEffects(Zone zone); public Map<Effect, Ability> getEffects(Game game, Zone zone, EffectType effectType); + public String getValue(); } diff --git a/Mage/src/mage/abilities/AbilitiesImpl.java b/Mage/src/mage/abilities/AbilitiesImpl.java index db18782667..ea1aa575d5 100644 --- a/Mage/src/mage/abilities/AbilitiesImpl.java +++ b/Mage/src/mage/abilities/AbilitiesImpl.java @@ -29,6 +29,7 @@ package mage.abilities; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -286,4 +287,17 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab return total; } + @Override + public String getValue() { + List<String> abilities = new ArrayList<String>(); + for (T ability: this) { + abilities.add(ability.toString()); + } + Collections.sort(abilities); + StringBuilder sb = new StringBuilder(); + for (String s: abilities) { + sb.append(s); + } + return sb.toString(); + } } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 2a04e6aa0e..8a967bcd36 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -102,7 +102,7 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability { this.zone = ability.zone; this.name = ability.name; this.usesStack = ability.usesStack; - this.manaCosts = ability.manaCosts.copy(); + this.manaCosts = ability.manaCosts; this.manaCostsToPay = ability.manaCostsToPay.copy(); this.costs = ability.costs.copy(); this.optionalCosts = ability.optionalCosts.copy(); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index a9a3d771b0..1c5785fc3c 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -151,7 +151,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl StringBuilder sb = new StringBuilder(1024); sb.append(controllerId).append(name).append(tapped).append(damage); sb.append(subtype).append(supertype).append(power.getValue()).append(toughness.getValue()); - sb.append(abilities); + sb.append(abilities.getValue()); for (Counter counter: counters.values()) { sb.append(counter.getName()).append(counter.getCount()); } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 3afd4ce259..c27edaa56e 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -1224,12 +1224,15 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser playable.add(ability); } } + // eliminate duplicate activated abilities + 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)) - playable.add(ability); + playableActivated.put(ability.toString(), ability); } } + playable.addAll(playableActivated.values()); return playable; }