From 4624f7730a1e66a7d43af82ff29b7275436ee8c4 Mon Sep 17 00:00:00 2001 From: jendave Date: Sun, 7 Aug 2011 01:02:37 +0000 Subject: [PATCH] - Simplified the code found in forge.ComputerAI_General and forge.ComputerUtil_Attack2. --- src/forge/ComputerAI_General.java | 17 +++++++++++------ src/forge/ComputerUtil_Attack2.java | 18 +++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/forge/ComputerAI_General.java b/src/forge/ComputerAI_General.java index b2a1d1badcb..f35c2f44713 100644 --- a/src/forge/ComputerAI_General.java +++ b/src/forge/ComputerAI_General.java @@ -55,7 +55,8 @@ public class ComputerAI_General implements Computer { if (c.getSVar("PlayMain1").equals("TRUE")) return true; - if(c.isCreature() && (c.getKeyword().contains("Haste")) || c.getKeyword().contains("Exalted")) return true; + if (c.isCreature() + && (c.hasKeyword("Haste")) || c.hasKeyword("Exalted")) return true; CardList buffed = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); //get all cards the computer controls with BuffedBy for(int j = 0; j < buffed.size(); j++) { @@ -119,8 +120,10 @@ public class ComputerAI_General implements Computer { //Don't play permanents with Flash before humans declare attackers step all = all.filter(new CardListFilter() { public boolean addCard(Card c) { - if(c.isPermanent() && c.getKeyword().contains("Flash") && (AllZone.Phase.isPlayerTurn(AllZone.ComputerPlayer) - || AllZone.Phase.isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility))) + if (c.isPermanent() + && c.hasKeyword("Flash") + && (AllZone.Phase.isPlayerTurn(AllZone.ComputerPlayer) + || AllZone.Phase.isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility))) return false; return true; } @@ -156,8 +159,10 @@ public class ComputerAI_General implements Computer { //Don't play permanents with Flash before humans declare attackers step all = all.filter(new CardListFilter() { public boolean addCard(Card c) { - if(c.isPermanent() && c.getKeyword().contains("Flash") && (AllZone.Phase.isPlayerTurn(AllZone.ComputerPlayer) - || AllZone.Phase.isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility))) + if (c.isPermanent() + && c.hasKeyword("Flash") + && (AllZone.Phase.isPlayerTurn(AllZone.ComputerPlayer) + || AllZone.Phase.isBefore(Constant.Phase.Combat_Declare_Attackers_InstantAbility))) return false; return true; } @@ -253,7 +258,7 @@ public class ComputerAI_General implements Computer { for(int i = 0; i < att.length; i++) { // tapping of attackers happens after Propaganda is paid for - //if(!att[i].getKeyword().contains("Vigilance")) att[i].tap(); + //if (!att[i].hasKeyword("Vigilance")) att[i].tap(); Log.debug("Computer just assigned " + att[i].getName() + " as an attacker."); } diff --git a/src/forge/ComputerUtil_Attack2.java b/src/forge/ComputerUtil_Attack2.java index 29fc7adfb72..a27a9c02905 100644 --- a/src/forge/ComputerUtil_Attack2.java +++ b/src/forge/ComputerUtil_Attack2.java @@ -165,7 +165,7 @@ public class ComputerUtil_Attack2 { //re-add creatures with vigilance for (Card c:attackers) { - if (c.getKeyword().contains("Vigilance")) + if (c.hasKeyword("Vigilance")) notNeededAsBlockers.add(c); } @@ -255,10 +255,10 @@ public class ComputerUtil_Attack2 { //Atackers that don't really have a choice for (Card attacker : attackers) { - if ( (attacker.getKeyword().contains("CARDNAME attacks each turn if able.") - || attacker.getKeyword().contains("At the beginning of the end step, destroy CARDNAME.") - || attacker.getKeyword().contains("At the beginning of the end step, exile CARDNAME.") - || attacker.getKeyword().contains("At the beginning of the end step, sacrifice CARDNAME.") + if ( (attacker.hasKeyword("CARDNAME attacks each turn if able.") + || attacker.hasKeyword("At the beginning of the end step, destroy CARDNAME.") + || attacker.hasKeyword("At the beginning of the end step, exile CARDNAME.") + || attacker.hasKeyword("At the beginning of the end step, sacrifice CARDNAME.") || attacker.getSacrificeAtEOT() || attacker.getSirenAttackOrDestroy()) && CombatUtil.canAttack(attacker, combat)) { @@ -483,7 +483,7 @@ public class ComputerUtil_Attack2 { CardList list = AllZoneUtil.getPlayerCardsInPlay(player); list = list.filter(new CardListFilter(){ public boolean addCard(Card c) { - return c.getKeyword().contains("Exalted"); + return c.hasKeyword("Exalted"); } }); @@ -494,7 +494,7 @@ public class ComputerUtil_Attack2 { { int n = c.getNetCombatDamage(); - if(c.getKeyword().contains("Double Strike")) + if (c.hasKeyword("Double Strike")) n *= 2; return n; @@ -523,9 +523,9 @@ public class ComputerUtil_Attack2 { } } // see if this attacking creature can destroy this defender, if not record that it can't kill everything - if(!CombatUtil.canDestroyBlocker(defender, attacker, combat, false)){ + if (!CombatUtil.canDestroyBlocker(defender, attacker, combat, false)) { canKillAll = false; - if(defender.getKeyword().contains("Wither") || defender.getKeyword().contains("Infect")){ + if (defender.hasKeyword("Wither") || defender.hasKeyword("Infect")) { canKillAllDangerous = false; // there is a dangerous creature that can survive an attack from this creature } }