From f7331b7066b8b5c955afbcec792105a53c45e18d Mon Sep 17 00:00:00 2001 From: "wagic.the.homebrew@gmail.com" Date: Mon, 28 Sep 2009 13:34:49 +0000 Subject: [PATCH] Erwan - Fix one card in ZEN - Fix AI and counters (issue 75, see tests/manual/torture_ai.txt) - Fix counters target --- projects/mtg/bin/Res/test/_tests.txt | 1 + .../mtg/bin/Res/test/manual/torture_ai.txt | 20 ++++++++++++ projects/mtg/bin/Res/test/torture.txt | 32 +++++++++++++++++++ projects/mtg/include/AIPlayer.h | 2 +- projects/mtg/include/AllAbilities.h | 2 +- projects/mtg/include/MTGAbility.h | 3 +- projects/mtg/src/AIPlayer.cpp | 6 ++-- projects/mtg/src/MTGAbility.cpp | 9 ++++-- 8 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 projects/mtg/bin/Res/test/manual/torture_ai.txt create mode 100644 projects/mtg/bin/Res/test/torture.txt diff --git a/projects/mtg/bin/Res/test/_tests.txt b/projects/mtg/bin/Res/test/_tests.txt index d417e0d11..9eccb1ba2 100644 --- a/projects/mtg/bin/Res/test/_tests.txt +++ b/projects/mtg/bin/Res/test/_tests.txt @@ -219,6 +219,7 @@ telekinetic_sliver.txt terror.txt terror2.txt titanic_ultimatum.txt +torture.txt tranquil_domain.txt unwilling_recruit.txt volcanic_island.txt diff --git a/projects/mtg/bin/Res/test/manual/torture_ai.txt b/projects/mtg/bin/Res/test/manual/torture_ai.txt new file mode 100644 index 000000000..aeb2df2c1 --- /dev/null +++ b/projects/mtg/bin/Res/test/manual/torture_ai.txt @@ -0,0 +1,20 @@ +#Bug:Does torture correctly cast torture on opponent's creatures ? +[INIT] +SECONDMAIN +[PLAYER1] +inplay:grizzly bears +[PLAYER2] +hand:torture +inplay:air elemental,swamp,plains +[DO] +ai +ai +[ASSERT] +COMBATEND +[PLAYER1] +inplay:Wildslayer Elves,Armadillo Cloak +life:25 +[PLAYER2] +graveyard:grizzly bears +life:17 +[END] \ No newline at end of file diff --git a/projects/mtg/bin/Res/test/torture.txt b/projects/mtg/bin/Res/test/torture.txt new file mode 100644 index 000000000..d27b585b4 --- /dev/null +++ b/projects/mtg/bin/Res/test/torture.txt @@ -0,0 +1,32 @@ +#Bug: Torture doesn't put counters +[INIT] +FIRSTMAIN +[PLAYER1] +inplay:grizzly bears,swamp,mountain +hand:torture +manapool:{B} +[PLAYER2] +[DO] +torture +grizzly bears +swamp +mountain +torture +next +#begin +next +#attackers +grizzly bears +next +#blockers +next +#damage +next +#end combat +[ASSERT] +COMBATEND +[PLAYER1] +inplay:grizzly bears,swamp,mountain,torture +[PLAYER2] +life:19 +[END] \ No newline at end of file diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index 925e9f457..f2a9fad8e 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -57,7 +57,7 @@ class AIPlayer: public Player{ int chooseAttackers(); int chooseBlockers(); int canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy); - int effectBadOrGood(MTGCardInstance * card); + int effectBadOrGood(MTGCardInstance * card, int mode = MODE_PUTINTOPLAY); int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0); AIStats * getStats(); public: diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index 1f2b3f5bd..5d009b383 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -159,7 +159,7 @@ class AACounter: public ActivatedAbility{ int power; int toughness; AACounter(int id, MTGCardInstance * source, MTGCardInstance * target, int power, int toughness, int nb, ManaCost * cost = NULL, int doTap = 0) : ActivatedAbility(id, source, cost, 0, doTap), nb(nb), power(power), toughness(toughness) { - target = target; + this->target = target; } diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index 5efd20acc..77bd1ff03 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -31,6 +31,7 @@ using std::map; #define BAKA_EFFECT_DONTKNOW 0 #define MODE_PUTINTOPLAY 1 #define MODE_ABILITY 2 +#define MODE_TARGET 3 #define COUNT_POWER 1 @@ -205,7 +206,7 @@ class AbilityFactory{ MTGAbility * parseMagicLine(string s, int id, Spell * spell, MTGCardInstance *card, int activated = 0, int forceUEOT = 0); public: int abilityEfficiency(MTGAbility * a, Player * p, int mode = MODE_ABILITY); - int magicText(int id, Spell * spell, MTGCardInstance * card = NULL); + int magicText(int id, Spell * spell, MTGCardInstance * card = NULL, int mode = MODE_PUTINTOPLAY); static int computeX(Spell * spell, MTGCardInstance * card); int destroyAllInPlay(TargetChooser * tc, int bury = 0); int moveAll(TargetChooser * tc, string destinationZone); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 44829d250..a238db6da 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -281,10 +281,10 @@ int AIPlayer::interruptIfICan(){ return 0; } -int AIPlayer::effectBadOrGood(MTGCardInstance * card){ +int AIPlayer::effectBadOrGood(MTGCardInstance * card, int mode){ int id = card->getMTGId(); AbilityFactory * af = NEW AbilityFactory(); - int autoGuess = af->magicText(id,NULL,card); + int autoGuess = af->magicText(id,NULL,card, mode); delete af; if (autoGuess) return autoGuess; return BAKA_EFFECT_DONTKNOW; @@ -305,7 +305,7 @@ int AIPlayer::chooseTarget(TargetChooser * tc){ if (!tc) return 0; if (!(gameObs->currentlyActing() == this)) return 0; Player * target = this; - int cardEffect = effectBadOrGood(tc->source); + int cardEffect = effectBadOrGood(tc->source, MODE_TARGET); if (cardEffect != BAKA_EFFECT_GOOD){ target = this->opponent(); } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index fd8d02799..22f142c12 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -655,6 +655,11 @@ int AbilityFactory::abilityEfficiency(MTGAbility * a, Player * p, int mode){ if (dynamic_cast(a)) return BAKA_EFFECT_BAD; if (dynamic_cast(a)) return BAKA_EFFECT_GOOD; if (dynamic_cast(a)) return BAKA_EFFECT_BAD; + if (AACounter * ac = dynamic_cast(a)) { + bool negative_effect = ac->power < 0 || ac->toughness < 0; + if ((ac->nb > 0 && negative_effect) || (ac->nb < 0 && !negative_effect)) return BAKA_EFFECT_BAD; + return BAKA_EFFECT_GOOD ; + } if (dynamic_cast(a)) return BAKA_EFFECT_GOOD; if (dynamic_cast(a)) return BAKA_EFFECT_BAD; //TODO if (dynamic_cast(a)) return BAKA_EFFECT_GOOD; @@ -709,7 +714,7 @@ int AbilityFactory::computeX(Spell * spell, MTGCardInstance * card){ * - target (if there ie a "target(" in the string, then this is a TargetAbility) * - doTap (a dirty way to know if tapping is included in the cost... */ -int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ +int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card, int mode){ int dryMode = 0; if (!spell) dryMode = 1; @@ -741,7 +746,7 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){ MTGAbility * a = parseMagicLine(line, result, spell, card); if (dryMode){ - result = abilityEfficiency(a, card->controller(),MODE_PUTINTOPLAY); + result = abilityEfficiency(a, card->controller(),mode); SAFE_DELETE(a); return result; }