- Adding new icons from J
- fixed a bug with Zombie Master (for real this time, I swear !)
- The AI should play Wrath of god in a more "clever" way
This commit is contained in:
wagic.the.homebrew
2008-11-16 10:37:13 +00:00
parent 0b5c940ae3
commit c50ea49e74
8 changed files with 334 additions and 275 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@@ -51,3 +51,4 @@ terror.txt
volcanic_island.txt
white_knight1.txt
wrath_of_god.txt
zombie_master.txt

View File

@@ -0,0 +1,24 @@
#Testing Zombie Master crash ?
[INIT]
COMBATATTACKERS
[PLAYER1]
inplay:1188,129693,135216
[PLAYER2]
inplay:1299
[DO]
129693
1188
next
1299
next
next
129693
[ASSERT]
COMBATEND
[PLAYER1]
inplay:135216,129693
graveyard:1188
[PLAYER2]
life:18
inplay:1299
[END]

View File

@@ -882,7 +882,8 @@ class ALord:public ListMaintainerAbility{
card->addToToughness(toughness);
if (ability != -1) card->basicAbilities[ability] +=1;
if (regenCost){
AStandardRegenerate * regen = NEW AStandardRegenerate(0, card, card, regenCost);
ManaCost * _regenCost = NEW ManaCost(regenCost);
AStandardRegenerate * regen = NEW AStandardRegenerate(0, card, card, _regenCost);
regenerations[card] = regen;
game->addObserver(regen);
}

View File

@@ -22,10 +22,11 @@ using std::map;
//Two stupid variables used to give a hint to the AI:
// Should I cast a spell on an enemy or friendly unit ?
#define BAKA_EFFECT_GOOD 10
#define BAKA_EFFECT_BAD 11
#define BAKA_EFFECT_GOOD 1
#define BAKA_EFFECT_BAD -1
#define BAKA_EFFECT_DONTKNOW 0
#define COUNT_POWER 1
class MTGAbility: public ActionElement{
protected:
@@ -183,6 +184,7 @@ class GenericTriggeredAbility:public TriggeredAbility{
/* Ability Factory */
class AbilityFactory{
private:
int countCards(TargetChooser * tc, Player * player = NULL, int option = 0);
int destroyAllInPlay(TargetChooser * tc, int bury = 0);
int putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone, Player * p);
Trigger * parseTrigger(string magicText);
@@ -195,3 +197,4 @@ class AbilityFactory{
#include "MTGCardInstance.h"
#endif

View File

@@ -76,31 +76,7 @@ void AIPlayer::tapLandsForMana(ManaCost * potentialMana, ManaCost * cost){
delete(diff);
/*
for (int i=MTG_NB_COLORS-1; i>= 0; i--){
#if defined (WIN32) || defined (LINUX)
char buf[4096];
sprintf(buf,"Testing %s \n" ,MTG_LAND_TEXTS[i]);
OutputDebugString(buf);
#endif
currentCost = cost->getCost(i);
while(currentCost){
#if defined (WIN32) || defined (LINUX)
sprintf(buf,"Cost for %s is %i \n" ,MTG_LAND_TEXTS[i], currentCost);
OutputDebugString(buf);
#endif
MTGCardInstance * card = NULL;
while(currentCost && (card = cd.nextmatch(game->inPlay, card))){
if (i==MTG_COLOR_ARTIFACT || card->hasSubtype(MTG_LAND_TEXTS[i]) ){
currentCost--;
gameObs->cardClick(card);
}
}
}
}
*/
#if defined (WIN32) || defined (LINUX)
OutputDebugString("ok land tapped");
#endif
@@ -167,7 +143,7 @@ int AIPlayer::effectBadOrGood(MTGCardInstance * card){
int autoGuess = af->magicText(id,NULL,card);
delete af;
if (autoGuess) return autoGuess;
return BAKA_EFFECT_BAD;
return BAKA_EFFECT_DONTKNOW;
}
int AIPlayer::chooseTarget(TargetChooser * tc){
@@ -184,7 +160,7 @@ int AIPlayer::chooseTarget(TargetChooser * tc){
if (!(gameObs->currentlyActing() == this)) return 0;
Player * target = this;
int cardEffect = effectBadOrGood(tc->source);
if (cardEffect == BAKA_EFFECT_BAD){
if (cardEffect != BAKA_EFFECT_GOOD){
target = this->opponent();
}
@@ -467,6 +443,15 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * potentialMana, const c
int hasTarget = (chooseTarget(tc));
delete tc;
if (!hasTarget)continue;
}else{
int shouldPlayPercentage = 10;
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD){
shouldPlayPercentage = 90;
}else if(BAKA_EFFECT_DONTKNOW == shouldPlay){
shouldPlayPercentage = 70;
}
if (rand() % 100 > shouldPlayPercentage) continue;
}
nextCardToPlay = card;
maxCost = currentCost;

View File

@@ -9,11 +9,33 @@
#include "../include/MTGDeck.h"
int AbilityFactory::countCards(TargetChooser * tc, Player * player, int option){
int result = 0;
GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2 ; i++){
if (player && player!= game->players[i]) continue;
for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){
MTGCardInstance * current = game->players[i]->game->inPlay->cards[j];
if (tc->canTarget(current)){
switch (option){
case COUNT_POWER:
result+= current->power;
break;
default:
result++;
break;
}
}
}
}
return result;
}
int AbilityFactory::destroyAllInPlay(TargetChooser * tc, int bury){
tc->source = NULL; // This is to prevent protection from... as objects that destroy all do not actually target
GameObserver * game = GameObserver::GetInstance();
for (int i = 0; i < 2 ; i++){
for (int j = 0; j < game->players[i]->game->inPlay->nb_cards; j++){
for (int j = game->players[i]->game->inPlay->nb_cards-1; j >=0 ; j--){
MTGCardInstance * current = game->players[i]->game->inPlay->cards[j];
if (tc->canTarget(current)){
if (bury){
@@ -38,7 +60,7 @@ int AbilityFactory::putInPlayFromZone(MTGCardInstance * card, MTGGameZone * zone
Trigger * AbilityFactory::parseTrigger(string magicText){
size_t found = magicText.find("@");
int found = magicText.find("@");
if (found == string::npos) return NULL;
//Next Time...
@@ -199,8 +221,8 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Bury
found = s.find("bury");
if (found != string::npos){
if (dryMode) return BAKA_EFFECT_BAD;
if (trigger){
if (dryMode) return BAKA_EFFECT_BAD;
BuryEvent * action = NEW BuryEvent();
game->addObserver(NEW GenericTriggeredAbility(id, card,trigger,action));
}else{
@@ -210,9 +232,21 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
string starget = s.substr(found + 4,end - found - 4);
TargetChooserFactory tcf;
TargetChooser * targetAll = tcf.createTargetChooser(starget, card);
if (dryMode){
int myNbCards = countCards(targetAll,card->controller());
int opponentNbCards = countCards(targetAll, card->controller()->opponent());
int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER);
int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER);
delete targetAll;
if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD;
}else{
this->destroyAllInPlay(targetAll,1);
delete targetAll;
}
}else{
if (dryMode) return BAKA_EFFECT_BAD;
if (tc){
game->addObserver(NEW ABurier(id, card,tc));
}else{
@@ -227,16 +261,27 @@ int AbilityFactory::magicText(int id, Spell * spell, MTGCardInstance * card){
//Destroy
found = s.find("destroy");
if (found != string::npos){
if (dryMode) return BAKA_EFFECT_BAD; //TODO compute according to nb in case of destroy all
found = s.find("all(");
if (found != string::npos){
int end = s.find(")");
string starget = s.substr(found + 4,end - found - 4);
TargetChooserFactory tcf;
TargetChooser * targetAll = tcf.createTargetChooser(starget, card);
if (dryMode){
int myNbCards = countCards(targetAll,card->controller());
int opponentNbCards = countCards(targetAll, card->controller()->opponent());
int myCardsPower = countCards(targetAll,card->controller(),COUNT_POWER);
int opponentCardsPower = countCards(targetAll, card->controller()->opponent(),COUNT_POWER);
delete targetAll;
if (myNbCards < opponentNbCards || myCardsPower < opponentCardsPower) return BAKA_EFFECT_GOOD;
return BAKA_EFFECT_BAD;
}else{
this->destroyAllInPlay(targetAll);
delete targetAll;
}
}else{
if (dryMode) return BAKA_EFFECT_BAD;
if (tc){
game->addObserver(NEW ADestroyer(id, card,tc));
}else{

View File

@@ -294,9 +294,9 @@ int TestSuite::assertGame(){
}
for (int k = 0; k < endState.playerData[i].zones[j].nbitems; k++){
int cardid = endState.playerData[i].zones[j].cards[k];
int realcardid = zone->cards[k]->getMTGId();
if ( realcardid!= cardid){
sprintf(result, "<span class=\"error\">==Card ID not the same. Expected %i, got %i==</span><br />", cardid, realcardid);
MTGCardInstance * card = getCardByMTGId(cardid);
if (!card || !zone->hasCard(card)){
sprintf(result, "<span class=\"error\">==Card ID not the same. Didn't find %i</span><br />", cardid);
Log(result);
error++;
}