- had some problems compiling for the PSP. I assume I was the only one, please let me know if the "include JLogger" lines are not needed (they were needed for me)
- Fix a memory leak when playing in "random deck" mode
- Prevent the AI from playing cards with a cost it cannot understand (ExtraCosts with a target).
This commit is contained in:
wagic.the.homebrew@gmail.com
2010-11-18 14:04:24 +00:00
parent 09afcea7da
commit f7bcbb42dc
7 changed files with 68 additions and 51 deletions

View File

@@ -53,42 +53,46 @@ class CmpAbilities { // compares Abilities efficiency
}; };
class AIPlayer: public Player{ class AIPlayer: public Player{
protected: protected:
MTGCardInstance * nextCardToPlay; //Variables used by Test suite
queue<AIAction *> clickstream; MTGCardInstance * nextCardToPlay;
void tapLandsForMana(ManaCost * cost, MTGCardInstance * card = NULL); queue<AIAction *> clickstream;
int orderBlockers(); void tapLandsForMana(ManaCost * cost, MTGCardInstance * card = NULL);
int combatDamages(); int orderBlockers();
int interruptIfICan(); int combatDamages();
int chooseAttackers(); int interruptIfICan();
int chooseBlockers(); int chooseAttackers();
int canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy); int chooseBlockers();
int effectBadOrGood(MTGCardInstance * card, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL); int canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy);
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0); int effectBadOrGood(MTGCardInstance * card, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL);
AIStats * getStats(); int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
//Variables used by Test suite AIStats * getStats();
public:
int agressivity; // returns 1 if the AI algorithm supports a given cost (ex:simple mana cost), 0 otherwise (ex: cost involves Sacrificing a target)
bool Checked; int CanHandleCost(ManaCost * cost);
bool forceBestAbilityUse;
void End(){}; public:
virtual int displayStack() {return 0;}; AIStats * stats;
int receiveEvent(WEvent * event); int agressivity;
void Render(); bool Checked;
AIStats * stats; bool forceBestAbilityUse;
ManaCost * getPotentialMana(MTGCardInstance * card = NULL); void End(){};
AIPlayer(MTGDeck * deck, string deckFile, string deckFileSmall); virtual int displayStack() {return 0;};
virtual ~AIPlayer(); int receiveEvent(WEvent * event);
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0); void Render();
virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL); ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
virtual int Act(float dt); AIPlayer(MTGDeck * deck, string deckFile, string deckFileSmall);
virtual int affectCombatDamages(CombatStep); virtual ~AIPlayer();
int isAI(){return 1;}; virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
int canHandleCost(MTGAbility * ability); virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL);
int selectAbility(); virtual int Act(float dt);
int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, map<AIAction *, int,CmpAbilities> * ranking); virtual int affectCombatDamages(CombatStep);
int useAbility(); int isAI(){return 1;};
virtual int getEfficiency(AIAction * action); int canHandleCost(MTGAbility * ability);
int selectAbility();
int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, map<AIAction *, int,CmpAbilities> * ranking);
int useAbility();
virtual int getEfficiency(AIAction * action);
}; };

View File

@@ -159,22 +159,28 @@ int AIPlayer::getEfficiency(AIAction * action)
return action->getEfficiency(); return action->getEfficiency();
} }
//Can't yet handle extraCost objects (ex: sacrifice) if they require a target :(
int AIPlayer::CanHandleCost(ManaCost * cost)
{
if (!cost) return 1;
ExtraCosts * ec = cost->extraCosts;
if (!ec) return 1;
for (size_t i = 0; i < ec->costs.size(); ++i)
{
if (ec->costs[i]->tc)
return 0;
}
return 1;
}
int AIPlayer::canHandleCost(MTGAbility * ability) int AIPlayer::canHandleCost(MTGAbility * ability)
{ {
//Can't handle sacrifice costs that require a target yet :( return CanHandleCost(ability->cost);
if (ability->cost)
{
ExtraCosts * ec = ability->cost->extraCosts;
if (ec)
{
for (size_t i = 0; i < ec->costs.size(); i++)
{
if (ec->costs[i]->tc)
return 0;
}
}
}
return 1;
} }
int AIAction::getEfficiency() int AIAction::getEfficiency()
@@ -871,6 +877,8 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
card = NULL; card = NULL;
while ((card = cd.nextmatch(game->hand, card))) while ((card = cd.nextmatch(game->hand, card)))
{ {
if (!CanHandleCost(card->getManaCost()))
continue;
if (card->hasType(Subtypes::TYPE_CREATURE) && this->castrestrictedcreature < 0 && this->castrestrictedspell < 0) if (card->hasType(Subtypes::TYPE_CREATURE) && this->castrestrictedcreature < 0 && this->castrestrictedspell < 0)
continue; continue;
if (card->hasType(Subtypes::TYPE_ENCHANTMENT) && this->castrestrictedspell < 0) if (card->hasType(Subtypes::TYPE_ENCHANTMENT) && this->castrestrictedspell < 0)

View File

@@ -1,6 +1,7 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include <JGE.h> #include <JGE.h>
#include <JLogger.h>
#include <JRenderer.h> #include <JRenderer.h>
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
#include <time.h> #include <time.h>

View File

@@ -6,7 +6,7 @@
#include "Damage.h" #include "Damage.h"
#include "Rules.h" #include "Rules.h"
#include "ExtraCost.h" #include "ExtraCost.h"
#include <JLogger.h>
#include <JRenderer.h> #include <JRenderer.h>
GameObserver * GameObserver::mInstance = NULL; GameObserver * GameObserver::mInstance = NULL;

View File

@@ -17,6 +17,7 @@
#include "PlayerData.h" #include "PlayerData.h"
#include "utils.h" #include "utils.h"
#include "WFont.h" #include "WFont.h"
#include <JLogger.h>
static const char* GAME_VERSION = "WTH?! 0.13.1 - by wololo"; static const char* GAME_VERSION = "WTH?! 0.13.1 - by wololo";

View File

@@ -10,6 +10,7 @@
#include "MTGAbility.h" #include "MTGAbility.h"
#include "DeckManager.h" #include "DeckManager.h"
#include "AIPlayer.h" #include "AIPlayer.h"
#include <JLogger.h>
int Rules::getMTGId(string cardName) int Rules::getMTGId(string cardName)
{ {
@@ -297,6 +298,7 @@ Player * Rules::loadPlayerRandom(int isAI, int mode)
else else
player = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, ""); player = NEW AIPlayerBaka(tempDeck, deckFile, deckFileSmall, "");
delete tempDeck;
return player; return player;
} }

View File

@@ -12,6 +12,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include "WFont.h" #include "WFont.h"
#include <JLogger.h>
//#define FORCE_LOW_CACHE_MEMORY //#define FORCE_LOW_CACHE_MEMORY
const unsigned int kConstrainedCacheLimit = 8 * 1024 * 1024; const unsigned int kConstrainedCacheLimit = 8 * 1024 * 1024;