- Modified the testsuite and gameobserver to be able to replay all the testcases based on the actions logged during the first pass. This allows to test the action logging and replay used during undo. It's only activated in multithreaded mode and it does not work on Momir tests. - Modified choice logging and replay to use menuId instead of ability index, as, for some obscur reasons related to Lord, those ability indexes may change. - Fixed bug in nextphase logging wrongly generating click actions - Added a "stack" zone to the click ability logging to be able to replay properly interrupt - Fixed a wonderful bug mixing card names with zone names in the actions execution engine - Added a "combatok" action logging/execution - Added a "clone" virtual method to MTGCardInstance and Token to be able to clone correctly the right object type. Used that in MTGGameZones::removeCard
125 lines
2.8 KiB
C++
125 lines
2.8 KiB
C++
#ifndef _TESTSUITE_AI_H_
|
|
#define _TESTSUITE_AI_H_
|
|
|
|
#ifdef TESTSUITE
|
|
|
|
#define MAX_TESTSUITE_ACTIONS 100
|
|
#define MAX_TESTUITE_CARDS 100
|
|
|
|
#include "Threading.h"
|
|
#include "AIPlayerBaka.h"
|
|
|
|
class TestSuiteActions
|
|
{
|
|
public:
|
|
int nbitems;
|
|
string actions[MAX_TESTSUITE_ACTIONS];
|
|
void add(string action);
|
|
TestSuiteActions();
|
|
void cleanup();
|
|
};
|
|
|
|
|
|
class TestSuiteGame;
|
|
class TestSuite;
|
|
class TestSuiteAI;
|
|
class TestSuiteState
|
|
{
|
|
public:
|
|
GamePhase phase;
|
|
void parsePlayerState(int playerId, string s);
|
|
TestSuiteState();
|
|
~TestSuiteState();
|
|
|
|
vector<TestSuiteAI*> players;
|
|
void cleanup(TestSuiteGame* tsGame);
|
|
};
|
|
|
|
class TestSuiteGame
|
|
{
|
|
friend class TestSuiteAI;
|
|
friend class TestSuite;
|
|
protected:
|
|
string filename;
|
|
int summoningSickness;
|
|
bool forceAbility;
|
|
GameType gameType;
|
|
unsigned int seed;
|
|
int aiMaxCalls;
|
|
TestSuiteState endState;
|
|
TestSuiteState initState;
|
|
TestSuiteActions actions;
|
|
float timerLimit;
|
|
bool isOK;
|
|
int currentAction;
|
|
GameObserver* observer;
|
|
|
|
static boost::mutex mMutex;
|
|
virtual void handleResults(bool wasAI, int error);
|
|
TestSuite* testsuite;
|
|
bool load();
|
|
|
|
public:
|
|
virtual ~TestSuiteGame();
|
|
TestSuiteGame(TestSuite* testsuite);
|
|
TestSuiteGame(TestSuite* testsuite, string _filename);
|
|
void ResetManapools();
|
|
void initGame();
|
|
void assertGame();
|
|
MTGPlayerCards * buildDeck(Player* player, int playerId);
|
|
GameType getGameType() { return gameType; };
|
|
string getNextAction();
|
|
Interruptible * getActionByMTGId(int mtgid);
|
|
static int Log(const char * text);
|
|
void setObserver(GameObserver* anObserver) {observer = anObserver; };
|
|
};
|
|
|
|
class TestSuite : public TestSuiteGame
|
|
{
|
|
private:
|
|
int currentfile;
|
|
int nbfiles;
|
|
string files[1024];
|
|
|
|
void cleanup();
|
|
vector<boost::thread*> mWorkerThread;
|
|
Rules* mRules;
|
|
bool mProcessing;
|
|
|
|
public:
|
|
int startTime, endTime;
|
|
unsigned int seed;
|
|
int nbFailed, nbTests, nbAIFailed, nbAITests;
|
|
TestSuite(const char * filename);
|
|
~TestSuite();
|
|
void initGame(GameObserver* g);
|
|
void pregameTests();
|
|
int loadNext();
|
|
string getNextFile() {
|
|
boost::mutex::scoped_lock lock(mMutex);
|
|
if (currentfile >= nbfiles) return "";
|
|
currentfile++;
|
|
return files[currentfile - 1];
|
|
};
|
|
static void ThreadProc(void* inParam);
|
|
void setRules(Rules* rules) {mRules = rules;};
|
|
void handleResults(bool wasAI, int error);
|
|
};
|
|
|
|
class TestSuiteAI:public AIPlayerBaka
|
|
{
|
|
private:
|
|
MTGCardInstance * getCard(string action);
|
|
float timer;
|
|
TestSuiteGame * suite;
|
|
|
|
public:
|
|
TestSuiteAI(TestSuiteGame *tsGame, int playerId);
|
|
virtual int Act(float dt);
|
|
virtual int displayStack();
|
|
bool summoningSickness() {return (suite->summoningSickness == 1); }
|
|
};
|
|
|
|
#endif
|
|
#endif
|