Adding a system to compare two AI implementations (AIPlayerBaka and AIPlayerBakaB). This can be used to make sure a change to the AI is not making the AI weaker, for example.

This commit is contained in:
wagic.the.homebrew
2011-09-20 11:32:24 +00:00
parent 4c45e971c6
commit 44d9951246
14 changed files with 1921 additions and 19 deletions

View File

@@ -9,6 +9,12 @@
// Instances for Factory
#include "AIPlayerBaka.h"
#ifdef AI_CHANGE_TESTING
#include "AIPlayerBakaB.h"
#endif
const char * const MTG_LAND_TEXTS[] = { "artifact", "forest", "island", "mountain", "swamp", "plains", "other lands" };
int AIAction::currentId = 0;
@@ -123,6 +129,7 @@ AIPlayer::AIPlayer(string file, string fileSmall, MTGDeck * deck) :
agressivity = 50;
forceBestAbilityUse = false;
playMode = Player::MODE_AI;
mFastTimerMode = false;
}
@@ -278,5 +285,60 @@ void AIPlayer::Render()
#endif
}
#ifdef AI_CHANGE_TESTING
AIPlayer * AIPlayerFactory::createAIPlayerTest(MTGAllCards * collection, Player * opponent, int deckid)
{
char deckFile[512];
string avatarFilename; // default imagename
char deckFileSmall[512];
if (deckid == GameStateDuel::MENUITEM_EVIL_TWIN)
{ //Evil twin
sprintf(deckFile, "%s", opponent->deckFile.c_str());
DebugTrace("Evil Twin => " << opponent->deckFile);
avatarFilename = "avatar.jpg";
sprintf(deckFileSmall, "%s", "ai_baka_eviltwin");
}
else
{
if (!deckid)
{
//random deck
int nbdecks = 0;
int found = 1;
while (found && nbdecks < options[Options::AIDECKS_UNLOCKED].number)
{
found = 0;
char buffer[512];
sprintf(buffer, "ai/baka/deck%i.txt", nbdecks + 1);
if (FileExists(buffer))
{
found = 1;
nbdecks++;
}
}
if (!nbdecks)
return NULL;
deckid = 1 + WRand() % (nbdecks);
}
sprintf(deckFile, "ai/baka/deck%i.txt", deckid);
DeckMetaData *aiMeta = DeckManager::GetInstance()->getDeckMetaDataByFilename( deckFile, true);
avatarFilename = aiMeta->getAvatarFilename();
sprintf(deckFileSmall, "ai_baka_deck%i", deckid);
}
int deckSetting = EASY;
if ( opponent )
{
bool isOpponentAI = opponent->isAI() == 1;
DeckMetaData *meta = DeckManager::GetInstance()->getDeckMetaDataByFilename( opponent->deckFile, isOpponentAI);
if ( meta->getVictoryPercentage() >= 65)
deckSetting = HARD;
}
// AIPlayerBaka will delete MTGDeck when it's time
AIPlayerBakaB * baka = NEW AIPlayerBakaB(deckFile, deckFileSmall, avatarFilename, NEW MTGDeck(deckFile, collection,0, deckSetting));
baka->deckId = deckid;
return baka;
}
#endif