Latest min-max branch
This commit is contained in:
@@ -248,7 +248,7 @@ void JFileSystem::clearZipCache()
|
|||||||
|
|
||||||
bool JFileSystem::AttachZipFile(const string &zipfile, char *password /* = NULL */)
|
bool JFileSystem::AttachZipFile(const string &zipfile, char *password /* = NULL */)
|
||||||
{
|
{
|
||||||
if (mZipAvailable && mZipFile != NULL)
|
if (mZipAvailable && mZipFile.is_open())
|
||||||
{
|
{
|
||||||
if (mZipFileName != zipfile)
|
if (mZipFileName != zipfile)
|
||||||
DetachZipFile(); // close the previous zip file
|
DetachZipFile(); // close the previous zip file
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
friend ostream& operator<<(ostream&, const Action&);
|
friend ostream& operator<<(ostream&, const Action&);
|
||||||
friend istream& operator>>(istream&, Action&);
|
friend istream& operator>>(istream&, Action&);
|
||||||
};
|
};
|
||||||
|
|
||||||
class AIAction
|
class AIAction
|
||||||
@@ -84,6 +84,10 @@ public:
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
int Act();
|
int Act();
|
||||||
|
ostream& logSimpleAct(ostream& out, MTGCardInstance* click);
|
||||||
|
ostream& logMultiAct(ostream& out, vector<Targetable*>& actionTargets);
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& out, AIAction& a);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ class GameObserver{
|
|||||||
string startupGameSerialized;
|
string startupGameSerialized;
|
||||||
bool parseLine(const string& s);
|
bool parseLine(const string& s);
|
||||||
virtual void logAction(const string& s);
|
virtual void logAction(const string& s);
|
||||||
bool processAction(const string& s);
|
|
||||||
bool processActions(bool undo
|
bool processActions(bool undo
|
||||||
#ifdef TESTSUITE
|
#ifdef TESTSUITE
|
||||||
, TestSuiteGame* testgame
|
, TestSuiteGame* testgame
|
||||||
@@ -69,6 +68,7 @@ class GameObserver{
|
|||||||
);
|
);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool processAction(const string& s);
|
||||||
int currentPlayerId;
|
int currentPlayerId;
|
||||||
CombatStep combatStep;
|
CombatStep combatStep;
|
||||||
int turn;
|
int turn;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public:
|
|||||||
std::string GetCurrentDeckStatsFile();
|
std::string GetCurrentDeckStatsFile();
|
||||||
virtual bool parseLine(const string& s);
|
virtual bool parseLine(const string& s);
|
||||||
friend ostream& operator<<(ostream&, const Player&);
|
friend ostream& operator<<(ostream&, const Player&);
|
||||||
friend istream& operator>>(istream&, Player&);
|
friend istream& operator>>(istream&, Player&);
|
||||||
bool operator<(Player& aPlayer);
|
bool operator<(Player& aPlayer);
|
||||||
bool isDead();
|
bool isDead();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -67,6 +67,52 @@ AIAction::AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should be "const AIAction& " instead, but compiler is annoying to enable that.
|
||||||
|
ostream& operator<<(ostream& out, AIAction& a)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
if (a.player && !a.playerAbilityTarget)
|
||||||
|
{
|
||||||
|
out << "p" + (a.owner->getObserver()->getPlayerId(a.player) + 1) << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (a.ability)
|
||||||
|
{
|
||||||
|
a.logSimpleAct(out, a.click);
|
||||||
|
// we're ignoring ability and we shouldn't
|
||||||
|
if (a.target && !a.mAbilityTargets.size())
|
||||||
|
{
|
||||||
|
a.logSimpleAct(out, a.target);
|
||||||
|
// sounds broken if target is a player ... or not, it's the following case
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(a.playerAbilityTarget && !a.mAbilityTargets.size())
|
||||||
|
{
|
||||||
|
out << "p" + (a.owner->getObserver()->getPlayerId((Player*)a.playerAbilityTarget) + 1) << endl;
|
||||||
|
// with this log we're losing what player clicked on who ... which is bad.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(a.mAbilityTargets.size())
|
||||||
|
{
|
||||||
|
a.logMultiAct(out, a.mAbilityTargets);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(a.mAbilityTargets.size())
|
||||||
|
{
|
||||||
|
a.logMultiAct(out, a.mAbilityTargets);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (a.click)
|
||||||
|
{ //Shouldn't be used, really...
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
int AIAction::Act()
|
int AIAction::Act()
|
||||||
{
|
{
|
||||||
GameObserver * g = owner->getObserver();
|
GameObserver * g = owner->getObserver();
|
||||||
@@ -107,6 +153,49 @@ int AIAction::Act()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ostream& AIAction::logSimpleAct(ostream& out, MTGCardInstance* click)
|
||||||
|
{
|
||||||
|
string currentPlayer = "p" + (owner->getObserver()->getPlayerId(owner) + 1);
|
||||||
|
out << currentPlayer << click->currentZone->getName() << "[" << click->currentZone->getIndex(click) << "]" << endl;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& AIAction::logMultiAct(ostream& out, vector<Targetable*>& actionTargets)
|
||||||
|
{
|
||||||
|
GameObserver * g = owner->getObserver();
|
||||||
|
TargetChooser * tc = g->getCurrentTargetChooser();
|
||||||
|
do {
|
||||||
|
if(!tc) break;
|
||||||
|
vector<Targetable*>::iterator ite = actionTargets.begin();
|
||||||
|
while(ite != actionTargets.end())
|
||||||
|
{
|
||||||
|
MTGCardInstance * card = ((MTGCardInstance *) (*ite));
|
||||||
|
if(card == (MTGCardInstance*)tc->source)//click source first.
|
||||||
|
{
|
||||||
|
g->cardClick(card);
|
||||||
|
ite = actionTargets.erase(ite);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++ite;
|
||||||
|
}
|
||||||
|
|
||||||
|
//shuffle to make it less predictable, otherwise ai will always seem to target from right to left. making it very obvious.
|
||||||
|
owner->getRandomGenerator()->random_shuffle(actionTargets.begin(), actionTargets.end());
|
||||||
|
|
||||||
|
for(int k = 0 ;k < int(actionTargets.size()) && k < tc->maxtargets; k++)
|
||||||
|
{
|
||||||
|
if (MTGCardInstance * card = dynamic_cast<MTGCardInstance *>(actionTargets[k]))
|
||||||
|
{
|
||||||
|
if(k+1 == int(actionTargets.size()))
|
||||||
|
tc->done = true;
|
||||||
|
g->cardClick(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tc->attemptsToFill++;
|
||||||
|
} while (0);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
int AIAction::clickMultiAct(vector<Targetable*>& actionTargets)
|
int AIAction::clickMultiAct(vector<Targetable*>& actionTargets)
|
||||||
{
|
{
|
||||||
GameObserver * g = owner->getObserver();
|
GameObserver * g = owner->getObserver();
|
||||||
|
|||||||
@@ -66,9 +66,12 @@ void AIPlayerMinMax::LookAround()
|
|||||||
vector<AIAction>::iterator it;
|
vector<AIAction>::iterator it;
|
||||||
for(it = potentialActions.begin(); it != potentialActions.end(); it++)
|
for(it = potentialActions.begin(); it != potentialActions.end(); it++)
|
||||||
{
|
{
|
||||||
|
stringstream theCommand;
|
||||||
|
theCommand << (*it);
|
||||||
|
|
||||||
GameObserver g;
|
GameObserver g;
|
||||||
g.load(stream.str());
|
g.load(stream.str());
|
||||||
// g.processAction((*it));
|
g.processAction(theCommand.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user