From 058747a42a3cd6adebb15fc0c85a75fbe0a75552 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 22:14:25 +0000 Subject: [PATCH] - The AI will now attack with Signal Pest. - Fixed a possible infinite loop in the attack code. - Added SVar:RemRandomDeck:True to Soulcatchers' Aerie. --- .gitattributes | 2 +- res/cardsfolder/soulcatchers_aerie.txt | 23 +++++++++--------- src/forge/CombatUtil.java | 10 ++++---- src/forge/ComputerUtil_Attack2.java | 33 ++++++++++++++++---------- 4 files changed, 38 insertions(+), 30 deletions(-) diff --git a/.gitattributes b/.gitattributes index 3856ae73edb..d27b2c7084d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6165,7 +6165,7 @@ res/cardsfolder/soul_stair_expedition.txt -text svneol=native#text/plain res/cardsfolder/soul_warden.txt -text svneol=native#text/plain res/cardsfolder/soulbound_guardians.txt -text svneol=native#text/plain res/cardsfolder/soulcatcher.txt -text svneol=native#text/plain -res/cardsfolder/soulcatchers_aerie.txt svneol=native#text/plain +res/cardsfolder/soulcatchers_aerie.txt -text svneol=native#text/plain res/cardsfolder/souldrinker.txt -text svneol=native#text/plain res/cardsfolder/soulquake.txt svneol=native#text/plain res/cardsfolder/souls_attendant.txt -text svneol=native#text/plain diff --git a/res/cardsfolder/soulcatchers_aerie.txt b/res/cardsfolder/soulcatchers_aerie.txt index a317d1e73b9..baa89cd292e 100644 --- a/res/cardsfolder/soulcatchers_aerie.txt +++ b/res/cardsfolder/soulcatchers_aerie.txt @@ -1,12 +1,13 @@ -Name:Soulcatchers' Aerie -ManaCost:1 W -Types:Enchantment -Text:no text -T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | ValidCard$ Bird | TriggerZones$ Battlefield | Execute$ TrigPutCounter | TriggerDescription$ Whenever a Bird is put into your graveyard from the battlefield, put a feather counter on CARDNAME. -SVar:TrigPutCounter:AB$PutCounter | Cost$ 0 | Defined$ Self | CounterType$ FEATHER | CounterNum$ 1 -K:stPumpAll:Bird:X/X:no Condition:Bird creatures get +1/+1 for each feather counter on CARDNAME. -SVar:X:Count$CardCounters.FEATHER -SVar:Rarity:Uncommon -SVar:Picture:http://www.wizards.com/global/images/magic/general/soulcatchers_aerie.jpg -SetInfo:JUD|Uncommon|http://magiccards.info/scans/en/ju/25.jpg +Name:Soulcatchers' Aerie +ManaCost:1 W +Types:Enchantment +Text:no text +T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | ValidCard$ Bird | TriggerZones$ Battlefield | Execute$ TrigPutCounter | TriggerDescription$ Whenever a Bird is put into your graveyard from the battlefield, put a feather counter on CARDNAME. +SVar:TrigPutCounter:AB$PutCounter | Cost$ 0 | Defined$ Self | CounterType$ FEATHER | CounterNum$ 1 +K:stPumpAll:Bird:X/X:no Condition:Bird creatures get +1/+1 for each feather counter on CARDNAME. +SVar:X:Count$CardCounters.FEATHER +SVar:RemRandomDeck:True +SVar:Rarity:Uncommon +SVar:Picture:http://www.wizards.com/global/images/magic/general/soulcatchers_aerie.jpg +SetInfo:JUD|Uncommon|http://magiccards.info/scans/en/ju/25.jpg End \ No newline at end of file diff --git a/src/forge/CombatUtil.java b/src/forge/CombatUtil.java index a73d725dc1c..1afe38de1db 100644 --- a/src/forge/CombatUtil.java +++ b/src/forge/CombatUtil.java @@ -597,11 +597,11 @@ public class CombatUtil { } //Returns the damage an unblocked attacker would deal - public static int damageIfUnblocked(Card attacker, Player attacked) + public static int damageIfUnblocked(Card attacker, Player attacked, Combat combat) { int damage = attacker.getNetCombatDamage(); int sum = 0; - damage += predictPowerBonusOfAttacker(attacker,null,null); + damage += predictPowerBonusOfAttacker(attacker,null,combat); if (!attacker.hasKeyword("Infect")) { sum = attacked.predictDamage(damage, attacker, true); if (attacker.hasKeyword("Double Strike")) sum += attacked.predictDamage(damage, attacker, true); @@ -610,7 +610,7 @@ public class CombatUtil { } //Returns the poison an unblocked attacker would deal - public static int poisonIfUnblocked(Card attacker, Player attacked) + public static int poisonIfUnblocked(Card attacker, Player attacked, Combat combat) { int damage = attacker.getNetCombatDamage(); int poison = 0; @@ -628,7 +628,7 @@ public class CombatUtil { { int sum = 0; for(Card attacker: attackers) { - sum += damageIfUnblocked(attacker, attacked); + sum += damageIfUnblocked(attacker, attacked, null); } return sum; } @@ -638,7 +638,7 @@ public class CombatUtil { { int sum = 0; for(Card attacker: attackers) { - sum += poisonIfUnblocked(attacker, attacked); + sum += poisonIfUnblocked(attacker, attacked, null); } return sum; } diff --git a/src/forge/ComputerUtil_Attack2.java b/src/forge/ComputerUtil_Attack2.java index 562e1dd7edc..99d6ded5ed5 100644 --- a/src/forge/ComputerUtil_Attack2.java +++ b/src/forge/ComputerUtil_Attack2.java @@ -66,6 +66,19 @@ public class ComputerUtil_Attack2 { return list; }//sortAttackers() + //Is there any reward for attacking? (for 0/1 creatures there is not) + public boolean isEffectiveAttacker(Card attacker, Combat combat) + { + if (CombatUtil.damageIfUnblocked(attacker, AllZone.HumanPlayer, combat) > 0) return true; + if (CombatUtil.poisonIfUnblocked(attacker, AllZone.HumanPlayer, combat) > 0) return true; + + ArrayList registeredTriggers = AllZone.TriggerHandler.getRegisteredTriggers(); + for(Trigger trigger : registeredTriggers) + if (CombatUtil.combatTriggerWillTrigger(attacker,null,trigger, combat)) return true; + + return false; + } + public CardList getPossibleAttackers(CardList in) { CardList list = new CardList(in.toArray()); @@ -239,14 +252,6 @@ public class ComputerUtil_Attack2 { attackersLeft.remove(attacker); } } - - attackersLeft = attackersLeft.filter(new CardListFilter() { - public boolean addCard(Card c) { - return (0 < AllZone.HumanPlayer.predictDamage(c.getNetCombatDamage(),c,true) || c.getName().equals("Guiltfeeder")); - } - }); - - if (attackersLeft.isEmpty()) return combat; // ******************* // start of edits @@ -289,7 +294,7 @@ public class ComputerUtil_Attack2 { candidateAttackers.add(pCard); if(pCard.getNetCombatDamage() > 0){ - candidateUnblockedDamage += CombatUtil.damageIfUnblocked(pCard,AllZone.HumanPlayer); + candidateUnblockedDamage += CombatUtil.damageIfUnblocked(pCard,AllZone.HumanPlayer,combat); computerForces += 1; } @@ -330,7 +335,7 @@ public class ComputerUtil_Attack2 { } // until the attackers are used up or the player would run out of life int attackRounds = 1; - while(attritionalAttackers.size() > 0 && playerLife > 0){ + while(attritionalAttackers.size() > 0 && playerLife > 0 && attackRounds < 99){ // sum attacker damage int damageThisRound = 0; for(int y = 0; y < attritionalAttackers.size(); y++){ @@ -367,7 +372,7 @@ public class ComputerUtil_Attack2 { } } if(isUnblockableCreature){ - unblockableDamage += CombatUtil.damageIfUnblocked(attacker,AllZone.HumanPlayer); + unblockableDamage += CombatUtil.damageIfUnblocked(attacker,AllZone.HumanPlayer,combat); } } if(unblockableDamage > 0){turnsUntilDeathByUnblockable = AllZone.HumanPlayer.life/unblockableDamage;} @@ -426,9 +431,9 @@ public class ComputerUtil_Attack2 { //do assault (all creatures attack) if the computer would win the game //or if the computer has 4 creatures and the player has 1 - else if(bAssault || (humanList.size() == 1 && 3 < attackers.size())) + else if(bAssault) { - System.out.println("Assault"); + System.out.println("Assault"); CardListUtil.sortAttack(attackersLeft); for(int i = 0; i < attackersLeft.size(); i++) if (CombatUtil.canAttack(attackersLeft.get(i), combat)) combat.addAttacker(attackersLeft.get(i)); @@ -490,6 +495,8 @@ public class ComputerUtil_Attack2 { boolean canKillAllDangerous = true; // indicates if the attacker can kill all single blockers with wither or infect boolean isWorthLessThanAllKillers = true; boolean canBeBlocked = false; + + if (!isEffectiveAttacker(attacker,combat)) return false; // look at the attacker in relation to the blockers to establish a number of factors about the attacking // context that will be relevant to the attackers decision according to the selected strategy