Files
wagic/projects/mtg/include/TestSuiteAI.h
omegablast2002@yahoo.com 76a8f406ec converted the player arrays into vectors, so we can test is a player is actually there at the time we are trying to access its variables.
this fixes 2 crashes I found, the first, 2 color random mode would crash on load.
2nd, ai vs ai testing would randomly crash, this should fix that also.
I noticed 2 color random mode is now trying to search for it's rules and sometimes flashes for a brief moment "error cant read file" or something like that....I could not find the source of that, it doesn't cause it to crash however it causes it to take a sec longer to load, this is before this commit btw, so the issue is still there.
it was trying to load the rules, flashed the error then crashes...i fixed the crash but not the rules error.

please review, i might have left in useless stuff...
I also did notice something, the way we are creating players is kind of all over the place. imo this is bad, it made this conversation extra hard becuase you create one player over here, another type over there, the human over in this direction, back track and create another somewhere else...this needs to be taken into account for a refactor, all player creation should happen in the same function, and at the same times...

the reason these 2 crashes existed was becuase players were being created before "gameobserver" in some modes, and in other modes, no player would exist at the time game was creating to set the player. but we then later call the same function when we actually load the player using the method specific to a mode.

this just leads to headaches, I mean no offense, just a general observation i made when converting this players array. unfortunately that kind of refactor is just a little beyond my coding ability.
2011-10-01 21:29:22 +00:00

98 lines
1.9 KiB
C++

#ifndef _TESTSUITE_AI_H_
#define _TESTSUITE_AI_H_
#ifdef TESTSUITE
#define MAX_TESTSUITE_ACTIONS 100
#define MAX_TESTUITE_CARDS 100
#include "AIPlayerBaka.h"
class TestSuiteActions
{
public:
int nbitems;
string actions[MAX_TESTSUITE_ACTIONS];
void add(string action);
TestSuiteActions();
void cleanup();
};
class TestSuite;
class TestSuiteAI;
class TestSuiteState
{
public:
int phase;
void parsePlayerState(int playerId, string s);
TestSuiteState();
~TestSuiteState();
vector<TestSuiteAI*> players;
void cleanup(TestSuite*);
};
class TestSuitePregame
{
public:
virtual void performTest() = 0;
};
class TestSuite
{
private:
int currentfile;
int nbfiles;
string files[1024];
TestSuiteState endState;
TestSuiteActions actions;
bool forceAbility;
int load(const char * filename);
void cleanup();
public:
/* but only used by the testsuite classes */
float timerLimit;
int aiMaxCalls;
int currentAction;
int summoningSickness;
TestSuiteState initState;
string getNextAction();
MTGPlayerCards * buildDeck(Player*, int playerId);
Interruptible * getActionByMTGId(GameObserver* observer, int mtgid);
int assertGame(GameObserver*);
public:
int startTime, endTime;
int gameType;
unsigned int seed;
int nbFailed, nbTests, nbAIFailed, nbAITests;
TestSuite(const char * filename);
void initGame(GameObserver* g);
void pregameTests();
int loadNext();
static int Log(const char * text);
};
// TODO This should inherit from AIPlayer instead!
class TestSuiteAI:public AIPlayerBaka
{
private:
MTGCardInstance * getCard(string action);
float timer;
TestSuite * suite;
public:
TestSuiteAI(GameObserver *observer, TestSuite * suite, int playerId);
virtual int Act(float dt);
virtual int displayStack();
bool summoningSickness() {return (suite->summoningSickness == 1); }
};
#endif
#endif