- Modified gameObserver and related classes to be able to work with a precise JGE instance given at construction and not the static global one. That allows to run gameObserver without JGE instance (for example in a worker thread).
- Added an "ACTION_LOGGING_TESTING" mode in the gameObserver. When this is defined, the game reloads itself in every update. I want to use that to track undo problems. Be aware that it kills performances and crashes with the testsuite if you want to activate it. - Various cleanup/refactor of the game observer. - Added a gameObserver == operator to compare two games - Added player mode to the player serialization - Added a multi-threaded mode to AI_CHANGE_TESTING. For the moment it's only useable with Qt. If you want to use it without, just defined a thread_count higher than 1. - Refactored random generator class to use list intead of queue - Defined a specific type for interrupt decision instead of int
This commit is contained in:
@@ -29,12 +29,14 @@ AIAction::AIAction(AIPlayer * owner, MTGCardInstance * c, MTGCardInstance * t)
|
||||
if (owner->getObserver()->getCardSelector()->GetDrawMode() != DrawMode::kText)
|
||||
{
|
||||
//DebugTrace("Prefetching AI card going into play: " << c->getImageName());
|
||||
owner->getObserver()->getResourceManager()->RetrieveCard(c, RETRIEVE_THUMB);
|
||||
if(owner->getObserver()->getResourceManager())
|
||||
owner->getObserver()->getResourceManager()->RetrieveCard(c, RETRIEVE_THUMB);
|
||||
|
||||
// also cache the large image if we're using kNormal mode
|
||||
if (owner->getObserver()->getCardSelector()->GetDrawMode() == DrawMode::kNormal)
|
||||
{
|
||||
owner->getObserver()->getResourceManager()->RetrieveCard(c);
|
||||
if(owner->getObserver()->getResourceManager())
|
||||
owner->getObserver()->getResourceManager()->RetrieveCard(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1223,7 +1223,7 @@ int AIPlayerBaka::createAbilityTargets(MTGAbility * a, MTGCardInstance * c, Rank
|
||||
if(!realTargets.size() || (int(realTargets.size()) < a->getActionTc()->maxtargets && a->getActionTc()->targetMin))
|
||||
return 0;
|
||||
OrderedAIAction aiAction(this, a, c,realTargets);
|
||||
aiAction.target = (MTGCardInstance*)realTargets[0];
|
||||
aiAction.target = dynamic_cast<MTGCardInstance*>(realTargets[0]);
|
||||
ranking[aiAction] = 1;
|
||||
}
|
||||
return 1;
|
||||
@@ -1770,6 +1770,7 @@ int AIPlayerBaka::computeActions()
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef AI_CHANGE_TESTING
|
||||
static bool findingCard = false;
|
||||
//this guard is put in place to prevent Ai from
|
||||
//ever running computeActions() function WHILE its already doing so.
|
||||
@@ -1779,6 +1780,8 @@ int AIPlayerBaka::computeActions()
|
||||
{//is already looking kick me out of this function!
|
||||
return 0;
|
||||
}
|
||||
#endif //AI_CHANGE_TESTING
|
||||
|
||||
Interruptible * action = observer->mLayers->stackLayer()->getAt(-1);
|
||||
Spell * spell = dynamic_cast<Spell *>(action);
|
||||
Player * lastStackActionController = spell ? spell->source->controller() : NULL;
|
||||
@@ -1791,7 +1794,9 @@ int AIPlayerBaka::computeActions()
|
||||
bool ipotential = false;
|
||||
if(p->game->hand->hasType("instant") || p->game->hand->hasAbility(Constants::FLASH))
|
||||
{
|
||||
#ifndef AI_CHANGE_TESTING
|
||||
findingCard = true;
|
||||
#endif //AI_CHANGE_TESTING
|
||||
ManaCost * icurrentMana = getPotentialMana();
|
||||
icurrentMana->add(this->getManaPool());
|
||||
if (icurrentMana->getConvertedCost())
|
||||
@@ -1822,12 +1827,16 @@ int AIPlayerBaka::computeActions()
|
||||
gotPayments.clear();
|
||||
}
|
||||
}
|
||||
#ifndef AI_CHANGE_TESTING
|
||||
findingCard = false;
|
||||
#endif //AI_CHANGE_TESTING
|
||||
nextCardToPlay = NULL;
|
||||
return 1;
|
||||
}
|
||||
nextCardToPlay = NULL;
|
||||
#ifndef AI_CHANGE_TESTING
|
||||
findingCard = false;
|
||||
#endif //AI_CHANGE_TESTING
|
||||
return 1;
|
||||
}
|
||||
else if(observer->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0)
|
||||
|
||||
@@ -349,7 +349,7 @@ void ActionLayer::setMenuObject(Targetable * object, bool must)
|
||||
|
||||
SAFE_DELETE(abilitiesMenu);
|
||||
|
||||
abilitiesMenu = NEW SimpleMenu(10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str());
|
||||
abilitiesMenu = NEW SimpleMenu(observer->getInput(), 10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str());
|
||||
currentActionCard = NULL;
|
||||
for (size_t i = 0; i < mObjects.size(); i++)
|
||||
{
|
||||
@@ -375,7 +375,7 @@ void ActionLayer::setCustomMenuObject(Targetable * object, bool must,vector<MTGA
|
||||
}
|
||||
menuObject = object;
|
||||
SAFE_DELETE(abilitiesMenu);
|
||||
abilitiesMenu = NEW SimpleMenu(10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str());
|
||||
abilitiesMenu = NEW SimpleMenu(observer->getInput(), 10, this, Fonts::MAIN_FONT, 100, 100, object->getDisplayName().c_str());
|
||||
currentActionCard = NULL;
|
||||
abilitiesMenu->isMultipleChoice = false;
|
||||
if(abilities.size())
|
||||
|
||||
@@ -553,7 +553,7 @@ int ActionStack::AddNextGamePhase()
|
||||
NextGamePhase * next = NEW NextGamePhase(observer, mObjects.size());
|
||||
addAction(next);
|
||||
int playerId = (observer->currentActionPlayer == observer->players[1]) ? 1 : 0;
|
||||
interruptDecision[playerId] = 1;
|
||||
interruptDecision[playerId] = DONT_INTERRUPT;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -573,7 +573,7 @@ int ActionStack::setIsInterrupting(Player * player, bool log)
|
||||
|
||||
if (!gModRules.game.canInterrupt())
|
||||
{
|
||||
cancelInterruptOffer(1, log);
|
||||
cancelInterruptOffer(DONT_INTERRUPT, log);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -586,7 +586,7 @@ int ActionStack::setIsInterrupting(Player * player, bool log)
|
||||
}
|
||||
|
||||
int playerId = (player == observer->players[1]) ? 1 : 0;
|
||||
interruptDecision[playerId] = -1;
|
||||
interruptDecision[playerId] = INTERRUPT;
|
||||
observer->isInterrupting = player;
|
||||
if(log)
|
||||
observer->logAction(player, "yes");
|
||||
@@ -597,7 +597,7 @@ int ActionStack::addAction(Interruptible * action)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
interruptDecision[i] = 0;
|
||||
interruptDecision[i] = NOT_DECIDED;
|
||||
}
|
||||
Add(action);
|
||||
lastActionController = observer->currentlyActing();
|
||||
@@ -634,7 +634,7 @@ ActionStack::ActionStack(GameObserver* game)
|
||||
: GuiLayer(game), currentTutorial(0)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
interruptDecision[i] = 0;
|
||||
interruptDecision[i] = NOT_DECIDED;
|
||||
askIfWishesToInterrupt = NULL;
|
||||
timer = -1;
|
||||
currentState = -1;
|
||||
@@ -698,15 +698,15 @@ int ActionStack::resolve()
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (interruptDecision[i] != 2)
|
||||
interruptDecision[i] = 0;
|
||||
interruptDecision[i] = NOT_DECIDED;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
if (interruptDecision[i] != 2)
|
||||
interruptDecision[i] = 0;
|
||||
if (interruptDecision[i] != DONT_INTERRUPT_ALL)
|
||||
interruptDecision[i] = NOT_DECIDED;
|
||||
}
|
||||
}
|
||||
lastActionController = NULL;
|
||||
@@ -955,7 +955,7 @@ void ActionStack::Update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
void ActionStack::cancelInterruptOffer(int cancelMode, bool log)
|
||||
void ActionStack::cancelInterruptOffer(InterruptDecision cancelMode, bool log)
|
||||
{
|
||||
int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0;
|
||||
interruptDecision[playerId] = cancelMode;
|
||||
@@ -969,7 +969,7 @@ void ActionStack::cancelInterruptOffer(int cancelMode, bool log)
|
||||
void ActionStack::endOfInterruption(bool log)
|
||||
{
|
||||
int playerId = (observer->isInterrupting == observer->players[1]) ? 1 : 0;
|
||||
interruptDecision[playerId] = 0;
|
||||
interruptDecision[playerId] = NOT_DECIDED;
|
||||
observer->isInterrupting = NULL;
|
||||
if(log)
|
||||
observer->logAction(playerId, "endinterruption");
|
||||
@@ -994,7 +994,7 @@ bool ActionStack::CheckUserInput(JButton key)
|
||||
}
|
||||
else if ((JGE_BTN_PRI == key))
|
||||
{
|
||||
cancelInterruptOffer(2);
|
||||
cancelInterruptOffer(DONT_INTERRUPT_ALL);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -2359,7 +2359,7 @@ int MenuAbility::reactToChoiceClick(Targetable * object,int choice,int control)
|
||||
mClone->resolve();
|
||||
SAFE_DELETE(mClone);
|
||||
if (source->controller() == game->isInterrupting)
|
||||
game->mLayers->stackLayer()->cancelInterruptOffer(1, false);
|
||||
game->mLayers->stackLayer()->cancelInterruptOffer(ActionStack::DONT_INTERRUPT, false);
|
||||
this->forceDestroy = 1;
|
||||
removeMenu = true;
|
||||
return reactToTargetClick(object);
|
||||
@@ -3913,7 +3913,7 @@ AAConnect * AAConnect::clone() const
|
||||
//Tutorial Messaging
|
||||
|
||||
ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * source, string message, int limit)
|
||||
: MTGAbility(observer, 0, source), IconButtonsController(0, 0), mLimit(limit)
|
||||
: MTGAbility(observer, 0, source), IconButtonsController(observer->getInput(), 0, 0), mLimit(limit)
|
||||
{
|
||||
mBgTex = NULL;
|
||||
|
||||
@@ -3923,16 +3923,19 @@ ATutorialMessage::ATutorialMessage(GameObserver* observer, MTGCardInstance * sou
|
||||
for (int i = 0; i < 9; i++)
|
||||
mBg[i] = NULL;
|
||||
|
||||
string gfx = game->getResourceManager()->graphicsFile(message);
|
||||
if (fileExists(gfx.c_str()))
|
||||
if(game->getResourceManager())
|
||||
{
|
||||
mIsImage = true;
|
||||
mMessage = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
mMessage = _(message); //translate directly here, remove this and translate at rendering time if it bites us
|
||||
boost::replace_all(mMessage, "\\n", "\n");
|
||||
string gfx = game->getResourceManager()->graphicsFile(message);
|
||||
if (fileExists(gfx.c_str()))
|
||||
{
|
||||
mIsImage = true;
|
||||
mMessage = message;
|
||||
}
|
||||
else
|
||||
{
|
||||
mMessage = _(message); //translate directly here, remove this and translate at rendering time if it bites us
|
||||
boost::replace_all(mMessage, "\\n", "\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (mIsImage)
|
||||
|
||||
@@ -178,7 +178,8 @@ bool CardDisplay::CheckUserInput(JButton key)
|
||||
int n = mCurr;
|
||||
int x1,y1;
|
||||
JButton key;
|
||||
if (JGE::GetInstance()->GetLeftClickCoordinates(x1, y1))
|
||||
JGE* jge = observer->getInput();
|
||||
if (jge && jge->GetLeftClickCoordinates(x1, y1))
|
||||
{
|
||||
for (size_t i = 0; i < mObjects.size(); i++)
|
||||
{
|
||||
@@ -218,7 +219,7 @@ bool CardDisplay::CheckUserInput(JButton key)
|
||||
mObjects[mCurr]->Entering();
|
||||
result = true;
|
||||
}
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -187,7 +187,9 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
Target* oldactive = active;
|
||||
|
||||
int x,y;
|
||||
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
JGE* jge = observer->getInput();
|
||||
if(!jge) return false;
|
||||
if(jge->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
active = closest<True> (cards, limitor, static_cast<float> (x), static_cast<float> (y));
|
||||
}
|
||||
@@ -223,7 +225,7 @@ bool CardSelector::CheckUserInput(JButton key)
|
||||
return true;
|
||||
default:
|
||||
{
|
||||
if(!JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
if(!jge->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ hgeParticleSystem* DeckMenu::stars = NULL;
|
||||
// *** Need to make this configurable in a file somewhere to allow for class reuse
|
||||
|
||||
DeckMenu::DeckMenu(int id, JGuiListener* listener, int fontId, const string _title, const int& startIndex, bool showDetailsOverride) :
|
||||
JGuiController(id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOverride )
|
||||
JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsScreen( showDetailsOverride )
|
||||
{
|
||||
|
||||
backgroundName = "DeckMenuBackdrop";
|
||||
|
||||
@@ -43,36 +43,39 @@ void DuelLayers::CheckUserInput(int isAI)
|
||||
{
|
||||
JButton key;
|
||||
int x, y;
|
||||
while ((key = JGE::GetInstance()->ReadButton()) || JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
JGE* jge = observer->getInput();
|
||||
if(!jge) return;
|
||||
|
||||
while ((key = jge->ReadButton()) || jge->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
if ((!isAI) && ((0 != key) || JGE::GetInstance()->GetLeftClickCoordinates(x, y)))
|
||||
if ((!isAI) && ((0 != key) || jge->GetLeftClickCoordinates(x, y)))
|
||||
{
|
||||
if (stack->CheckUserInput(key)) {
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
break;
|
||||
}
|
||||
if (combat->CheckUserInput(key)) {
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
break;
|
||||
}
|
||||
if (avatars->CheckUserInput(key)) {
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
break; //avatars need to check their input before action (CTRL_CROSS)
|
||||
}
|
||||
if (action->CheckUserInput(key)) {
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
break;
|
||||
}
|
||||
if (hand->CheckUserInput(key)) {
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
break;
|
||||
}
|
||||
if (mCardSelector->CheckUserInput(key)) {
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
JGE::GetInstance()->LeftClickedProcessed();
|
||||
jge->LeftClickedProcessed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,28 +17,6 @@
|
||||
#include "TestSuiteAI.h"
|
||||
#endif
|
||||
|
||||
void GameObserver::initialize()
|
||||
{
|
||||
mGameType = GAME_TYPE_CLASSIC;
|
||||
currentPlayer = NULL;
|
||||
currentActionPlayer = NULL;
|
||||
isInterrupting = NULL;
|
||||
currentPlayerId = 0;
|
||||
currentGamePhase = -1;
|
||||
targetChooser = NULL;
|
||||
cardWaitingForTargets = NULL;
|
||||
mExtraPayment = NULL;
|
||||
gameOver = NULL;
|
||||
phaseRing = NULL;
|
||||
replacementEffects = NEW ReplacementEffects();
|
||||
combatStep = BLOCKERS;
|
||||
mRules = NULL;
|
||||
connectRule = false;
|
||||
mLoading = false;
|
||||
mLayers = NULL;
|
||||
mTrash = new Trash();
|
||||
}
|
||||
|
||||
void GameObserver::cleanup()
|
||||
{
|
||||
SAFE_DELETE(targetChooser);
|
||||
@@ -69,6 +47,10 @@ void GameObserver::cleanup()
|
||||
|
||||
GameObserver::~GameObserver()
|
||||
{
|
||||
#ifdef ACTION_LOGGING_TESTING
|
||||
if(oldGame) SAFE_DELETE(oldGame);
|
||||
#endif //ACTION_LOGGING_TESTING
|
||||
|
||||
LOG("==Destroying GameObserver==");
|
||||
for (size_t i = 0; i < players.size(); ++i)
|
||||
{
|
||||
@@ -89,13 +71,34 @@ GameObserver::~GameObserver()
|
||||
SAFE_DELETE(mTrash);
|
||||
}
|
||||
|
||||
GameObserver::GameObserver(WResourceManager *resourceManager)
|
||||
: randomGenerator(true), mResourceManager(resourceManager)
|
||||
GameObserver::GameObserver(WResourceManager *output, JGE* input)
|
||||
: randomGenerator(true), mResourceManager(output), mJGE(input)
|
||||
|
||||
{
|
||||
updateCtr = 0;
|
||||
#ifdef ACTION_LOGGING_TESTING
|
||||
oldGame = 0;
|
||||
#endif //ACTION_LOGGING_TESTING
|
||||
ExtraRules = new MTGCardInstance[2]();
|
||||
|
||||
initialize();
|
||||
mGameType = GAME_TYPE_CLASSIC;
|
||||
currentPlayer = NULL;
|
||||
currentActionPlayer = NULL;
|
||||
isInterrupting = NULL;
|
||||
currentPlayerId = 0;
|
||||
currentGamePhase = -1;
|
||||
targetChooser = NULL;
|
||||
cardWaitingForTargets = NULL;
|
||||
mExtraPayment = NULL;
|
||||
gameOver = NULL;
|
||||
phaseRing = NULL;
|
||||
replacementEffects = NEW ReplacementEffects();
|
||||
combatStep = BLOCKERS;
|
||||
mRules = NULL;
|
||||
connectRule = false;
|
||||
mLoading = false;
|
||||
mLayers = NULL;
|
||||
mTrash = new Trash();
|
||||
}
|
||||
|
||||
int GameObserver::getCurrentGamePhase()
|
||||
@@ -417,9 +420,80 @@ bool GameObserver::removeObserver(ActionElement * observer)
|
||||
|
||||
}
|
||||
|
||||
bool GameObserver::operator==(const GameObserver& aGame)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (aGame.currentGamePhase != currentGamePhase)
|
||||
{
|
||||
error++;
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
TestSuiteAI * p = (TestSuiteAI *) (aGame.players[i]);
|
||||
|
||||
if (p->life != players[i]->life)
|
||||
{
|
||||
error++;
|
||||
}
|
||||
if (p->poisonCount != players[i]->poisonCount)
|
||||
{
|
||||
error++;
|
||||
}
|
||||
if (!p->getManaPool()->canAfford(players[i]->getManaPool()))
|
||||
{
|
||||
error++;
|
||||
}
|
||||
if (!players[i]->getManaPool()->canAfford(p->getManaPool()))
|
||||
{
|
||||
error++;
|
||||
}
|
||||
MTGGameZone * aZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay };
|
||||
MTGGameZone * thisZones[] = { players[i]->game->graveyard,
|
||||
players[i]->game->library,
|
||||
players[i]->game->hand,
|
||||
players[i]->game->inPlay };
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
MTGGameZone * zone = aZones[j];
|
||||
if (zone->nb_cards != thisZones[j]->nb_cards)
|
||||
{
|
||||
error++;
|
||||
}
|
||||
for (size_t k = 0; k < (size_t)thisZones[j]->nb_cards; k++)
|
||||
{
|
||||
MTGCardInstance* cardToCheck = (k<thisZones[j]->cards.size())?thisZones[j]->cards[k]:0;
|
||||
MTGCardInstance* card = (k<aZones[j]->cards.size())?aZones[j]->cards[k]:0;
|
||||
if(!card || !cardToCheck || cardToCheck->getId() != card->getId())
|
||||
{
|
||||
error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (error == 0);
|
||||
}
|
||||
|
||||
void GameObserver::Update(float dt)
|
||||
{
|
||||
/*******************/
|
||||
updateCtr++;
|
||||
#ifdef ACTION_LOGGING_TESTING
|
||||
if(!oldGame || (!(*oldGame == *this) &&
|
||||
!mLoading && mLayers->stackLayer()->isCalm()))
|
||||
{ // constant game check
|
||||
stringstream stream;
|
||||
stream << *this;
|
||||
if(oldGame) SAFE_DELETE(oldGame);
|
||||
oldGame = new GameObserver();
|
||||
oldGame->mRules = mRules;
|
||||
oldGame->load(stream.str());
|
||||
assert(*this == *oldGame);
|
||||
}
|
||||
#endif // ACTION_LOGGING_TESTING
|
||||
|
||||
/*******************/
|
||||
Player * player = currentPlayer;
|
||||
if (Constants::MTG_PHASE_COMBATBLOCKERS == currentGamePhase && BLOCKERS == combatStep)
|
||||
{
|
||||
@@ -1368,7 +1442,12 @@ bool GameObserver::load(const string& ss, bool undo)
|
||||
else
|
||||
{
|
||||
if(players.size() == 0 || !players[0])
|
||||
players.push_back(new HumanPlayer(this, deckFile, deckFileSmall));
|
||||
{
|
||||
if (s.find("mode=") == 0)
|
||||
{
|
||||
createPlayer(s.substr(5));
|
||||
}
|
||||
}
|
||||
players[0]->parseLine(s);
|
||||
}
|
||||
break;
|
||||
@@ -1379,9 +1458,12 @@ bool GameObserver::load(const string& ss, bool undo)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(players.size() == 1 || !players[1]) {
|
||||
AIPlayerFactory playerCreator;
|
||||
players.push_back(playerCreator.createAIPlayer(this, MTGCollection(), players[0]));
|
||||
if(players.size() == 1 || !players[1])
|
||||
{
|
||||
if (s.find("mode=") == 0)
|
||||
{
|
||||
createPlayer(s.substr(5));
|
||||
}
|
||||
}
|
||||
players[1]->parseLine(s);
|
||||
}
|
||||
@@ -1556,6 +1638,27 @@ void GameObserver::Mulligan(Player* player)
|
||||
player->takeMulligan();
|
||||
}
|
||||
|
||||
void GameObserver::createPlayer(const string& playerMode)
|
||||
{
|
||||
Player::Mode aMode = (Player::Mode)atoi(playerMode.c_str());
|
||||
switch(aMode)
|
||||
{
|
||||
case Player::MODE_AI:
|
||||
AIPlayerFactory playerCreator;
|
||||
// FIXME: gonna break in AI vs AI mode
|
||||
players.push_back(playerCreator.createAIPlayer(this, MTGCollection(), players[0]));
|
||||
break;
|
||||
case Player::MODE_HUMAN:
|
||||
players.push_back(new HumanPlayer(this, "", ""));
|
||||
break;
|
||||
case Player::MODE_TEST_SUITE:
|
||||
// FIXME, not real TestPlayer, but we don't care here.
|
||||
players.push_back(new Player(this, "", ""));
|
||||
players.back()->playMode = Player::MODE_TEST_SUITE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TESTSUITE
|
||||
void GameObserver::loadTestSuitePlayer(int playerId, TestSuiteGame* testSuite)
|
||||
{
|
||||
|
||||
@@ -184,7 +184,7 @@ void GameStateAwards::Update(float dt)
|
||||
case JGE_BTN_MENU:
|
||||
showMenu = true;
|
||||
SAFE_DELETE(menu);
|
||||
menu = NEW SimpleMenu(EXIT_AWARDS_MENU, this, Fonts::MENU_FONT, 50, 170);
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), EXIT_AWARDS_MENU, this, Fonts::MENU_FONT, 50, 170);
|
||||
if (mState == STATE_DETAILS)
|
||||
menu->Add(kBackToTrophiesID, "Back to Trophies");
|
||||
menu->Add(kBackToMainMenuID, "Back to Main Menu");
|
||||
|
||||
@@ -454,7 +454,7 @@ void GameStateDeckViewer::Update(float dt)
|
||||
sprintf(buffer, "%s : %i %s", _(card->data->getName()).c_str(), price, _("credits").c_str());
|
||||
const float menuXOffset = SCREEN_WIDTH_F - 300;
|
||||
const float menuYOffset = SCREEN_HEIGHT_F / 2;
|
||||
subMenu = NEW SimpleMenu(MENU_CARD_PURCHASE, this, Fonts::MAIN_FONT, menuXOffset, menuYOffset, buffer);
|
||||
subMenu = NEW SimpleMenu(JGE::GetInstance(), MENU_CARD_PURCHASE, this, Fonts::MAIN_FONT, menuXOffset, menuYOffset, buffer);
|
||||
subMenu->Add(MENU_ITEM_YES, "Yes");
|
||||
subMenu->Add(MENU_ITEM_NO, "No", "", true);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ void GameStateDuel::Start()
|
||||
renderer->EnableVSync(true);
|
||||
OpponentsDeckid = 0;
|
||||
|
||||
game = NEW GameObserver(WResourceManager::Instance());
|
||||
game = NEW GameObserver(WResourceManager::Instance(), JGE::GetInstance());
|
||||
|
||||
#ifdef TESTSUITE
|
||||
SAFE_DELETE(testSuite);
|
||||
@@ -200,7 +200,7 @@ void GameStateDuel::loadTestSuitePlayers()
|
||||
if (!testSuite) return;
|
||||
initRand(testSuite->seed);
|
||||
SAFE_DELETE(game);
|
||||
game = new GameObserver(WResourceManager::Instance());
|
||||
game = new GameObserver(WResourceManager::Instance(), JGE::GetInstance());
|
||||
testSuite->setObserver(game);
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
@@ -274,6 +274,28 @@ void GameStateDuel::setGamePhase(int newGamePhase) {
|
||||
JGE::GetInstance()->SendCommand("enterduelphase:" + string(stateStrings[mGamePhase]));
|
||||
}
|
||||
|
||||
#ifdef AI_CHANGE_TESTING
|
||||
boost::mutex GameStateDuel::mMutex;
|
||||
|
||||
void GameStateDuel::ThreadProc(void* inParam)
|
||||
{
|
||||
GameStateDuel* instance = reinterpret_cast<GameStateDuel*>(inParam);
|
||||
float counter = 1.0f;
|
||||
while(instance->mGamePhase != DUEL_STATE_BACK_TO_MAIN_MENU)
|
||||
{
|
||||
GameObserver observer;
|
||||
observer.loadPlayer(0, PLAYER_TYPE_TESTSUITE);
|
||||
observer.loadPlayer(1, PLAYER_TYPE_TESTSUITE);
|
||||
observer.startGame(instance->mParent->gameType, instance->mParent->rules);
|
||||
|
||||
while(!observer.gameOver)
|
||||
observer.Update(counter++);
|
||||
|
||||
instance->handleResults(&observer);
|
||||
}
|
||||
}
|
||||
#endif //AI_CHANGE_TESTING
|
||||
|
||||
void GameStateDuel::Update(float dt)
|
||||
{
|
||||
switch (mGamePhase)
|
||||
@@ -421,12 +443,20 @@ void GameStateDuel::Update(float dt)
|
||||
#ifdef AI_CHANGE_TESTING
|
||||
if (mParent->players[0] == PLAYER_TYPE_CPU_TEST && mParent->players[1] == PLAYER_TYPE_CPU_TEST)
|
||||
{
|
||||
totalTestGames++;
|
||||
if (game->gameOver == game->players[0])
|
||||
testPlayer2Victories++;
|
||||
handleResults(game);
|
||||
End();
|
||||
Start();
|
||||
}
|
||||
if(mWorkerThread.empty())
|
||||
{ // "I don't like to wait" mode
|
||||
size_t thread_count = 1;
|
||||
#ifdef QT_CONFIG
|
||||
thread_count = QThread::idealThreadCount();
|
||||
#endif
|
||||
for(size_t i = 0; i < (thread_count-1); i++)
|
||||
mWorkerThread.push_back(boost::thread(ThreadProc, this));
|
||||
}
|
||||
|
||||
#endif
|
||||
if (mParent->players[0] == PLAYER_TYPE_CPU && mParent->players[1] == PLAYER_TYPE_CPU)
|
||||
{
|
||||
@@ -438,7 +468,7 @@ void GameStateDuel::Update(float dt)
|
||||
{
|
||||
if (!menu)
|
||||
{
|
||||
menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25,
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), DUEL_MENU_GAME_MENU, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25,
|
||||
game->players[1]->deckName.c_str());
|
||||
int cardsinhand = game->currentPlayer->game->hand->nb_cards;
|
||||
|
||||
@@ -498,6 +528,14 @@ void GameStateDuel::Update(float dt)
|
||||
case DUEL_STATE_BACK_TO_MAIN_MENU:
|
||||
if (menu)
|
||||
{
|
||||
#ifdef AI_CHANGE_TESTING
|
||||
while(mWorkerThread.size())
|
||||
{
|
||||
mWorkerThread.back().join();
|
||||
mWorkerThread.pop_back();
|
||||
}
|
||||
#endif //AI_CHANGE_TESTING
|
||||
|
||||
menu->Update(dt);
|
||||
if (menu->isClosed())
|
||||
{
|
||||
|
||||
@@ -353,7 +353,7 @@ void GameStateMenu::setLang(int id)
|
||||
void GameStateMenu::loadLangMenu()
|
||||
{
|
||||
LOG("GameStateMenu::loadLangMenu");
|
||||
subMenuController = NEW SimpleMenu(MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150, 60);
|
||||
subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_LANGUAGE_SELECTION, this, Fonts::MENU_FONT, 150, 60);
|
||||
if (!subMenuController)
|
||||
return;
|
||||
|
||||
@@ -418,7 +418,7 @@ void GameStateMenu::ensureMGuiController()
|
||||
{
|
||||
if (!mGuiController)
|
||||
{
|
||||
mGuiController = NEW JGuiController(100, this);
|
||||
mGuiController = NEW JGuiController(JGE::GetInstance(), 100, this);
|
||||
if (mGuiController)
|
||||
{
|
||||
WFont * mFont = WResourceManager::Instance()->GetWFont(Fonts::MENU_FONT);
|
||||
@@ -617,7 +617,7 @@ void GameStateMenu::Update(float dt)
|
||||
if (!hasChosenGameType)
|
||||
{
|
||||
currentState = MENU_STATE_MAJOR_SUBMENU;
|
||||
subMenuController = NEW SimpleMenu(MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
||||
subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
||||
if (subMenuController)
|
||||
{
|
||||
for (size_t i = 0; i < Rules::RulesList.size(); ++i)
|
||||
@@ -791,7 +791,7 @@ void GameStateMenu::ButtonPressed(int controllerId, int controlId)
|
||||
switch (controlId)
|
||||
{
|
||||
case MENUITEM_PLAY:
|
||||
subMenuController = NEW SimpleMenu(MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
||||
subMenuController = NEW SimpleMenu(JGE::GetInstance(), MENU_FIRST_DUEL_SUBMENU, this, Fonts::MENU_FONT, 150, 60);
|
||||
if (subMenuController)
|
||||
{
|
||||
subMenuController->Add(SUBMENUITEM_1PLAYER, "1 Player");
|
||||
|
||||
@@ -117,7 +117,7 @@ void GameStateOptions::Start()
|
||||
optionsList->failMsg = "";
|
||||
optionsTabs->Add(optionsList);
|
||||
|
||||
optionsMenu = NEW SimpleMenu(-102, this, Fonts::MENU_FONT, 50, 170);
|
||||
optionsMenu = NEW SimpleMenu(JGE::GetInstance(), -102, this, Fonts::MENU_FONT, 50, 170);
|
||||
optionsMenu->Add(kBackToMainMenuID, "Back to Main Menu");
|
||||
optionsMenu->Add(kSaveAndBackToMainMenuID, "Save & Back to Main Menu");
|
||||
optionsMenu->Add(kCancelMenuID, "Cancel");
|
||||
|
||||
@@ -214,12 +214,12 @@ void GameStateShop::beginPurchase(int controlId)
|
||||
SAFE_DELETE(menu);
|
||||
if (mInventory[controlId] <= 0)
|
||||
{
|
||||
menu = NEW SimpleMenu(-145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Sold Out").c_str());
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), -145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Sold Out").c_str());
|
||||
menu->Add(-1, "Ok");
|
||||
}
|
||||
else if (playerdata->credits - mPrices[controlId] < 0)
|
||||
{
|
||||
menu = NEW SimpleMenu(-145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Not enough credits").c_str());
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), -145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, _("Not enough credits").c_str());
|
||||
menu->Add(-1, "Ok");
|
||||
if (options[Options::CHEATMODE].number)
|
||||
{
|
||||
@@ -233,7 +233,7 @@ void GameStateShop::beginPurchase(int controlId)
|
||||
sprintf(buf, _("Purchase Booster: %i credits").c_str(), mPrices[controlId]);
|
||||
else
|
||||
sprintf(buf, _("Purchase Card: %i credits").c_str(), mPrices[controlId]);
|
||||
menu = NEW SimpleMenu(-145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, buf);
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), -145, this, Fonts::MENU_FONT, SCREEN_WIDTH - 300, SCREEN_HEIGHT / 2, buf);
|
||||
|
||||
menu->Add(controlId, "Yes");
|
||||
menu->Add(-1, "No");
|
||||
@@ -495,7 +495,7 @@ void GameStateShop::Update(float dt)
|
||||
menu->Update(dt);
|
||||
else
|
||||
{
|
||||
menu = NEW SimpleMenu(11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20);
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), 11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20);
|
||||
menu->Add(22, "Ask about...");
|
||||
menu->Add(14, "Check task board");
|
||||
if (options[Options::CHEATMODE].number)
|
||||
@@ -525,7 +525,7 @@ void GameStateShop::Update(float dt)
|
||||
{
|
||||
if (!menu)
|
||||
{
|
||||
menu = NEW SimpleMenu(11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20);
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), 11, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 20);
|
||||
menu->Add(15, "Return to shop");
|
||||
menu->Add(12, "Save & Back to Main Menu");
|
||||
menu->Add(kCancelMenuID, "Cancel");
|
||||
|
||||
@@ -44,7 +44,7 @@ void GameStateStory::loadStoriesMenu(const char * root)
|
||||
flow = NEW StoryFlow(stories[0]);
|
||||
break;
|
||||
default:
|
||||
menu = NEW SimpleMenu(103, this, Fonts::MENU_FONT, 150, 60);
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), 103, this, Fonts::MENU_FONT, 150, 60);
|
||||
for (size_t i = 0; i < stories.size(); ++i)
|
||||
{
|
||||
menu->Add(i, stories[i].c_str());
|
||||
@@ -64,7 +64,7 @@ void GameStateStory::Update(float dt)
|
||||
{
|
||||
if (!menu && mEngine->GetButtonClick(JGE_BTN_MENU))
|
||||
{
|
||||
menu = NEW SimpleMenu(100, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25);
|
||||
menu = NEW SimpleMenu(JGE::GetInstance(), 100, this, Fonts::MENU_FONT, SCREEN_WIDTH / 2 - 100, 25);
|
||||
menu->Add(0, "Back to main menu");
|
||||
menu->Add(kCancelMenuID, "Cancel");
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ bool GuiCombat::CheckUserInput(JButton key)
|
||||
DamagerDamaged* oldActive = active;
|
||||
/*
|
||||
int x,y;
|
||||
if(JGE::GetInstance()->GetLeftClickCoordinates(x, y))
|
||||
if(observer->getInput()->GetLeftClickCoordinates(x, y))
|
||||
{
|
||||
DamagerDamaged* old = active;
|
||||
active = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y));
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define SCALE_SELECTED 1.2f
|
||||
#define SCALE_NORMAL 1.0f
|
||||
|
||||
IconButtonsController::IconButtonsController(float x, float y): JGuiController(0, NULL), mX(x), mY(y)
|
||||
IconButtonsController::IconButtonsController(JGE* jge, float x, float y): JGuiController(jge, 0, NULL), mX(x), mY(y)
|
||||
{
|
||||
mListener = this;
|
||||
|
||||
|
||||
@@ -614,7 +614,7 @@ void OptionKey::KeyPressed(LocalKeySym key)
|
||||
g->UngrabKeyboard(this);
|
||||
grabbed = false;
|
||||
|
||||
btnMenu = NEW SimpleMenu(0, this, Fonts::MENU_FONT, 80, 10);
|
||||
btnMenu = NEW SimpleMenu(JGE::GetInstance(), 0, this, Fonts::MENU_FONT, 80, 10);
|
||||
for (int i = sizeof(btnList) / sizeof(btnList[0]) - 1; i >= 0; --i)
|
||||
{
|
||||
const KeyRep& rep = translateKey(btnList[i]);
|
||||
|
||||
@@ -292,6 +292,7 @@ bool Player::parseLine(const string& s)
|
||||
|
||||
ostream& operator<<(ostream& out, const Player& p)
|
||||
{
|
||||
out << "mode=" << p.playMode << endl;
|
||||
out << *(Damageable*)&p;
|
||||
string manapoolstring = p.manaPool->toString();
|
||||
if(manapoolstring != "")
|
||||
|
||||
@@ -28,8 +28,8 @@ JTexture* SimpleMenu::spadeLTex = NULL;
|
||||
JTexture* SimpleMenu::jewelTex = NULL;
|
||||
JTexture* SimpleMenu::sideTex = NULL;
|
||||
|
||||
SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical)
|
||||
: JGuiController(id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical)
|
||||
SimpleMenu::SimpleMenu(JGE* jge, int id, JGuiListener* listener, int fontId, float x, float y, const char * _title, int _maxItems, bool centerHorizontal, bool centerVertical)
|
||||
: JGuiController(jge, id, listener), fontId(fontId), mCenterHorizontal(centerHorizontal), mCenterVertical(centerVertical)
|
||||
{
|
||||
autoTranslate = true;
|
||||
isMultipleChoice = false;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <iomanip>
|
||||
|
||||
SimplePopup::SimplePopup(int id, JGuiListener* listener, const int fontId, const char * _title, DeckMetaData* deckMetaData, MTGAllCards * collection) :
|
||||
JGuiController(id, listener), mFontId(fontId), mCollection(collection)
|
||||
JGuiController(JGE::GetInstance(), id, listener), mFontId(fontId), mCollection(collection)
|
||||
{
|
||||
mX = 19;
|
||||
mY = 66;
|
||||
|
||||
@@ -303,7 +303,7 @@ StoryChoice::StoryChoice(string pageId, string text, int JGOid, float mX, float
|
||||
//Actually loads a duel
|
||||
void StoryDuel::init()
|
||||
{
|
||||
game = new GameObserver();
|
||||
game = new GameObserver(WResourceManager::Instance(), JGE::GetInstance());
|
||||
|
||||
char folder[255], deckFile[255], deckFileSmall[255];
|
||||
sprintf(folder, CAMPAIGNS_FOLDER"%s/%s", mParent->folder.c_str(), pageId.c_str());
|
||||
@@ -410,7 +410,7 @@ int StoryPage::loadElement(TiXmlElement* element)
|
||||
}
|
||||
|
||||
StoryDialog::StoryDialog(TiXmlElement* root, StoryFlow * mParent) :
|
||||
StoryPage(mParent), JGuiListener(), JGuiController(1, NULL)
|
||||
StoryPage(mParent), JGuiListener(), JGuiController(JGE::GetInstance(), 1, NULL)
|
||||
{
|
||||
|
||||
currentY = 0;
|
||||
|
||||
@@ -542,7 +542,7 @@ void WDecoConfirm::Entering(JButton key)
|
||||
|
||||
SAFE_DELETE(confirmMenu);
|
||||
mState = OP_CONFIRMED;
|
||||
confirmMenu = NEW SimpleMenu(444, listener, Fonts::MENU_FONT, 50, 170);
|
||||
confirmMenu = NEW SimpleMenu(JGE::GetInstance(), 444, listener, Fonts::MENU_FONT, 50, 170);
|
||||
confirmMenu->Add(1, confirm.c_str());
|
||||
confirmMenu->Add(2, cancel.c_str());
|
||||
}
|
||||
@@ -1965,7 +1965,7 @@ void WGuiFilterItem::updateValue()
|
||||
SAFE_DELETE(mParent->subMenu);
|
||||
mState = STATE_CHOOSE_TYPE;
|
||||
SAFE_DELETE(mParent->subMenu);
|
||||
mParent->subMenu = NEW SimpleMenu(-1234, this, Fonts::MENU_FONT, 20, 20, "Filter By...", 10);
|
||||
mParent->subMenu = NEW SimpleMenu(JGE::GetInstance(), -1234, this, Fonts::MENU_FONT, 20, 20, "Filter By...", 10);
|
||||
if (mParent->isAvailable(FILTER_SET))
|
||||
{
|
||||
mParent->subMenu->Add(FILTER_SET, "Set");
|
||||
@@ -2033,7 +2033,7 @@ void WGuiFilterItem::updateValue()
|
||||
SAFE_DELETE(mParent->subMenu);
|
||||
mParent->clearArgs();
|
||||
mState = STATE_CHOOSE_VAL;
|
||||
mParent->subMenu = NEW SimpleMenu(-1234, this, Fonts::MENU_FONT, 20, 20, "Filter:");
|
||||
mParent->subMenu = NEW SimpleMenu(JGE::GetInstance(), -1234, this, Fonts::MENU_FONT, 20, 20, "Filter:");
|
||||
if (filterType == FILTER_TYPE)
|
||||
{
|
||||
mParent->addArg("Artifact", "t:Artifact;");
|
||||
@@ -2341,7 +2341,7 @@ WGuiBase::CONFIRM_TYPE WGuiKeyBinder::needsConfirm()
|
||||
confirmationString = ss.str();
|
||||
|
||||
// Then create the menu.
|
||||
confirmMenu = NEW SimpleMenu(0, this, Fonts::MENU_FONT, 40, 130, "Conflict");
|
||||
confirmMenu = NEW SimpleMenu(JGE::GetInstance(), 0, this, Fonts::MENU_FONT, 40, 130, "Conflict");
|
||||
confirmMenu->Add(1, _("Cancel and return to the options menu").c_str());
|
||||
confirmMenu->Add(2, _("This is okay, validate and save").c_str());
|
||||
return CONFIRM_NEED;
|
||||
@@ -2369,7 +2369,7 @@ WGuiBase::CONFIRM_TYPE WGuiKeyBinder::needsConfirm()
|
||||
confirmationString = s;
|
||||
|
||||
confirmingButton = btnToCheck[i];
|
||||
confirmMenu = NEW SimpleMenu(1, this, Fonts::MENU_FONT, 40, 130, "Binding missing");
|
||||
confirmMenu = NEW SimpleMenu(JGE::GetInstance(), 1, this, Fonts::MENU_FONT, 40, 130, "Binding missing");
|
||||
confirmMenu->Add(1, _("Cancel and return to the options menu").c_str());
|
||||
confirmMenu->Add(2, _("This is okay, validate and save").c_str());
|
||||
return CONFIRM_NEED;
|
||||
|
||||
+11
-19
@@ -31,22 +31,19 @@ int RandomGenerator::random()
|
||||
else
|
||||
{
|
||||
result = loadedRandomValues.front();
|
||||
loadedRandomValues.pop();
|
||||
loadedRandomValues.pop_front();
|
||||
}
|
||||
if(log)
|
||||
usedRandomValues.push(result);
|
||||
usedRandomValues.push_back(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
ostream& RandomGenerator::saveUsedRandValues(ostream& out)
|
||||
{
|
||||
while(usedRandomValues.size())
|
||||
list<int>::iterator ite;
|
||||
for(ite=usedRandomValues.begin(); ite != usedRandomValues.end(); ite++)
|
||||
{
|
||||
out << usedRandomValues.front();
|
||||
if(usedRandomValues.size() >= 1)
|
||||
out << ",";
|
||||
|
||||
usedRandomValues.pop();
|
||||
out << *ite << ",";
|
||||
}
|
||||
|
||||
return out;
|
||||
@@ -54,13 +51,10 @@ ostream& RandomGenerator::saveUsedRandValues(ostream& out)
|
||||
|
||||
ostream& RandomGenerator::saveLoadedRandValues(ostream& out)
|
||||
{
|
||||
while(loadedRandomValues.size())
|
||||
list<int>::iterator ite;
|
||||
for(ite=loadedRandomValues.begin(); ite != loadedRandomValues.end(); ite++)
|
||||
{
|
||||
out << loadedRandomValues.front();
|
||||
if(loadedRandomValues.size() >= 1)
|
||||
out << ",";
|
||||
|
||||
loadedRandomValues.pop();
|
||||
out << *ite << ",";
|
||||
}
|
||||
|
||||
return out;
|
||||
@@ -68,10 +62,8 @@ ostream& RandomGenerator::saveLoadedRandValues(ostream& out)
|
||||
|
||||
void RandomGenerator::loadRandValues(string s)
|
||||
{
|
||||
while(loadedRandomValues.size())
|
||||
loadedRandomValues.pop();
|
||||
while(usedRandomValues.size())
|
||||
usedRandomValues.pop();
|
||||
loadedRandomValues.clear();
|
||||
usedRandomValues.clear();
|
||||
|
||||
while (s.size())
|
||||
{
|
||||
@@ -87,7 +79,7 @@ void RandomGenerator::loadRandValues(string s)
|
||||
value = atoi(s.c_str());
|
||||
s = "";
|
||||
}
|
||||
if (value) loadedRandomValues.push(value);
|
||||
if (value) loadedRandomValues.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user