- Added poison counter check into the testsuite

- Decorelated the testsuite AI timer from the game timer to be able to have reproduceable results with AI tests.
- Created a random generator wrapper class
- Used two seperate instances of this random generator for AI and for the game
- Added methods to load randoms into AI from a testcase
- Fixed a probleme with undo and premade decks introduced in r4035
- Added basic test to test AI proliferate code
- Cleaned up goblin_artillery test
- Added AI tests into the testsuite test list
- Fixed looping bug into the multi target AI code
This commit is contained in:
Xawotihs
2011-10-30 14:31:27 +00:00
parent 53b9bc412f
commit 2f4dd4cd2a
19 changed files with 195 additions and 98 deletions
+10 -7
View File
@@ -22,13 +22,14 @@
using std::queue;
class AIStats;
class AIPlayer;
class AIAction
{
protected:
static int currentId;
public:
Player * owner;
AIPlayer * owner;
MTGAbility * ability;
NestedAbility * nability;
Player * player;
@@ -39,26 +40,26 @@ public:
Targetable * playerAbilityTarget;
//player targeting through abilities is handled completely seperate from spell targeting.
AIAction(Player * owner, MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
AIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
: owner(owner), ability(a), player(NULL), click(c), target(t),playerAbilityTarget(NULL)
{
id = currentId++;
};
AIAction(Player * owner, MTGCardInstance * c, MTGCardInstance * t = NULL);
AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t = NULL);
AIAction(Player * owner, Player * p)//player targeting through spells
AIAction(AIPlayer * owner, Player * p)//player targeting through spells
: owner(owner), ability(NULL), player(p), click(NULL), target(NULL),playerAbilityTarget(NULL)
{
};
AIAction(Player * owner, MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
AIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
: owner(owner), ability(a), player(NULL), click(c), mAbilityTargets(targetCards),playerAbilityTarget(NULL)
{
id = currentId++;
};
AIAction(Player * owner, MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
AIAction(AIPlayer * owner, MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
: owner(owner), ability(a), click(c),target(NULL), playerAbilityTarget(p)
{
id = currentId++;
@@ -76,6 +77,7 @@ protected:
queue<AIAction *> clickstream;
int clickMultiTarget(TargetChooser * tc,vector<Targetable*>&potentialTargets);
int clickSingleTarget(TargetChooser * tc,vector<Targetable*>&potentialTargets, MTGCardInstance * Choosencard = NULL);
RandomGenerator randomGenerator;
public:
@@ -98,8 +100,9 @@ public:
int isAI(){return 1;};
void setFastTimerMode(bool mode = true) { mFastTimerMode = mode; };
RandomGenerator* getRandomGenerator(){return &randomGenerator;};
bool parseLine(const string& s);
};
+5 -5
View File
@@ -18,24 +18,24 @@ protected:
public:
int efficiency;
OrderedAIAction(Player * owner, MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
OrderedAIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
: AIAction(owner, a, c, t), efficiency(-1)
{
};
OrderedAIAction(Player * owner, MTGCardInstance * c, MTGCardInstance * t = NULL);
OrderedAIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t = NULL);
OrderedAIAction(Player * owner, Player * p)//player targeting through spells
OrderedAIAction(AIPlayer * owner, Player * p)//player targeting through spells
: AIAction(owner,p), efficiency(-1)
{
};
OrderedAIAction(Player * owner, MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
OrderedAIAction(AIPlayer * owner, MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
: AIAction(owner,a, c, targetCards), efficiency(-1)
{
};
OrderedAIAction(Player * owner, MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
OrderedAIAction(AIPlayer * owner, MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
: AIAction(owner, a, p, c), efficiency(-1)
{
};
+2
View File
@@ -45,6 +45,7 @@ class GameObserver{
bool mLoading;
void nextGamePhase();
void shuffleLibrary(Player* p);
RandomGenerator randomGenerator;
public:
int currentPlayerId;
@@ -123,6 +124,7 @@ class GameObserver{
void Mulligan(Player* player = NULL);
Player* getPlayer(size_t index) { return players[index];};
bool isStarted() { return (mLayers!=NULL);};
RandomGenerator* getRandomGenerator() { return &randomGenerator; };
};
#endif
+3 -4
View File
@@ -18,7 +18,7 @@ protected:
JTexture * mAvatarTex;
JQuadPtr mAvatar;
bool loadAvatar(string file, string resName = "playerAvatar");
bool premade;
public:
enum ENUM_PLAY_MODE
@@ -95,20 +95,19 @@ public:
** Returns the path to the stats file of currently selected deck.
*/
std::string GetCurrentDeckStatsFile();
bool parseLine(const string& s);
virtual bool parseLine(const string& s);
friend ostream& operator<<(ostream&, const Player&);
};
class HumanPlayer: public Player
{
protected:
bool premade;
public:
HumanPlayer(GameObserver *observer, string deckFile, string deckFileSmall, bool premade = false, MTGDeck * deck = NULL);
void End(){
if(!premade && opponent())
DeckStats::GetInstance()->saveStats(this, opponent(), observer);
};
friend ostream& operator<<(ostream&, const HumanPlayer&);
};
#endif
+23 -3
View File
@@ -63,11 +63,31 @@ std::string wordWrap(const std::string& s, float width, int fontId);
//basic hash function
unsigned long hash_djb2(const char *str);
void loadRandValues(string s);
ostream& saveRandValues(ostream& out);
// This class wraps random generation and the pre-loading/saving of randoms
// The idea is to make it instantiable to be able to handle randoms differently per class of group of classes.
// In particular, to be able to control the AI randoms independently of the other game randoms so that we can actually test AI
class RandomGenerator
{
protected:
queue<int> loadedRandomValues;
queue<int> usedRandomValues;
bool log;
public:
RandomGenerator(bool doLog = false) : log(doLog) {};
void loadRandValues(string s);
ostream& saveUsedRandValues(ostream& out);
ostream& saveLoadedRandValues(ostream& out);
int random();
template<typename Iter> void random_shuffle(Iter first, Iter last)
{
ptrdiff_t i, n;
n = (last-first);
for (i=n-1; i>0; --i) swap (first[i],first[random()%(i+1)]);
};
};
int filesize(const char * filename);
int WRand(bool log = false);
ptrdiff_t MRand (ptrdiff_t i);
#ifdef LINUX
void dumpStack();