diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index fab73100d..b9417c503 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -1,6 +1,9 @@ #ifndef _MTGGAMEZONES_H_ #define _MTGGAMEZONES_H_ +#include +using std::map; + #include "MTGDeck.h" #include "MTGCardInstance.h" @@ -14,7 +17,9 @@ class MTGGameZone { protected: Player * owner; public: + //Both cards and cardsMap contain the cards of a zone. The long term objective is to get rid of the array MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS]; + map cardsMap; int nb_cards; MTGGameZone(); ~MTGGameZone(); diff --git a/projects/mtg/include/Subtypes.h b/projects/mtg/include/Subtypes.h index 37fc54952..14aaa935c 100644 --- a/projects/mtg/include/Subtypes.h +++ b/projects/mtg/include/Subtypes.h @@ -1,20 +1,20 @@ #ifndef _SUBTYPES_H_ #define _SUBTYPES_H_ -#define MAX_SUBTYPES 1000 #include +#include using std::string; +using std::map; class Subtypes{ protected: - int nb_items; - string values[MAX_SUBTYPES]; + int nb_items; + map values; public: static Subtypes * subtypesList; Subtypes(); - int offset; int Add(const char * subtype); int find(const char * subtype); int Add(string subtype); diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index 2a887fc78..f682320ee 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -134,6 +134,7 @@ void MTGGameZone::setOwner(Player * player){ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){ int i; + cardsMap.erase(card); for (i=0; i<(nb_cards); i++) { if (cards[i] == card){ cards[i] = cards[nb_cards -1]; @@ -146,11 +147,7 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){ } MTGCardInstance * MTGGameZone::hasCard(MTGCardInstance * card){ - for (int i=0; i<(nb_cards); i++) { - if (cards[i] == card){ - return cards[i]; - } - } + if (cardsMap.find(card) != cardsMap.end()) return card; return NULL; } @@ -196,6 +193,7 @@ void MTGGameZone::addCard(MTGCardInstance * card){ if (!card) return; cards[nb_cards] = card; nb_cards++; + cardsMap[card] = 1; } @@ -203,6 +201,7 @@ MTGCardInstance * MTGGameZone::draw(){ if (!nb_cards) return NULL; nb_cards--; lastCardDrawn = cards[nb_cards]; + cardsMap.erase(cards[nb_cards]); return cards[nb_cards]; } diff --git a/projects/mtg/src/Subtypes.cpp b/projects/mtg/src/Subtypes.cpp index a0ddf1ef1..d207c397a 100644 --- a/projects/mtg/src/Subtypes.cpp +++ b/projects/mtg/src/Subtypes.cpp @@ -8,8 +8,7 @@ Subtypes * Subtypes::subtypesList = NEW Subtypes(); Subtypes::Subtypes(){ - nb_items = 0; - offset = 100; + nb_items = 100; } int Subtypes::Add(string value){ @@ -21,9 +20,9 @@ int Subtypes::Add(string value){ OutputDebugString(buf); #endif std::transform( value.begin(), value.end(), value.begin(), ::tolower ); - values[nb_items] = value; nb_items++; - return nb_items + offset - 1; + values[value] = nb_items; + return nb_items; } int Subtypes::Add(const char * subtype){ @@ -34,11 +33,8 @@ int Subtypes::Add(const char * subtype){ int Subtypes::find(string value){ std::transform( value.begin(), value.end(), value.begin(), ::tolower ); - for (int i = 0; i < nb_items; i++){ - if(values[i].compare(value) == 0){ - return i + offset; - } - } + map::iterator it = values.find(value); + if (it != values.end()) return it->second; return 0; } diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 872d5b6ed..0172630b8 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -45,9 +45,6 @@ int TestSuiteAI::Act(float dt){ GameObserver * g = GameObserver::GetInstance(); g->gameOver = NULL; // Prevent draw rule from losing the game timer+= dt; -char buf[4096]; -sprintf(buf, "%f\n", timer); -OutputDebugString (buf); if (timer < suite->timerLimit) return 1; timer = 0; string action = suite->getNextAction(); @@ -241,7 +238,7 @@ void TestSuite::initGame(){ } int TestSuite::Log(const char * text){ - ofstream file ("Res/test/results.txt",ios_base::app); + ofstream file ("Res/test/results.html",ios_base::app); if (file){ file << text; file << "\n"; @@ -256,30 +253,31 @@ int TestSuite::Log(const char * text){ } int TestSuite::assertGame(){ //compare the game state with the results - Log("============================="); - Log(files[currentfile-1].c_str()); char result[4096]; + sprintf(result,"

%s

",files[currentfile-1].c_str()); + Log(result); + int error = 0; GameObserver * g = GameObserver::GetInstance(); if (g->currentGamePhase != endState.phase){ - sprintf(result, "==phase problem. Expected %i, got %i==",endState.phase, g->currentGamePhase); + sprintf(result, "==phase problem. Expected %i, got %i==
",endState.phase, g->currentGamePhase); Log(result); error++; } for (int i = 0; i < 2; i++){ Player * p = g->players[i]; if (p->life != endState.playerData[i].life){ - sprintf(result, "==life problem for player %i. Expected %i, got %i==",i,endState.playerData[i].life, p->life); + sprintf(result, "==life problem for player %i. Expected %i, got %i==
",i,endState.playerData[i].life, p->life); Log(result); error++; } if (! p->getManaPool()->canAfford(endState.playerData[i].manapool)){ - sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==",endState.playerData[i].manapool->getConvertedCost(),p->getManaPool()->getConvertedCost(),i); + sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==
",endState.playerData[i].manapool->getConvertedCost(),p->getManaPool()->getConvertedCost(),i); Log(result); error++; } if(! endState.playerData[i].manapool->canAfford(p->getManaPool())){ - sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==",endState.playerData[i].manapool->getConvertedCost(),p->getManaPool()->getConvertedCost(),i); + sprintf(result, "==Mana problem. Was expecting %i but got %i for player %i==
",endState.playerData[i].manapool->getConvertedCost(),p->getManaPool()->getConvertedCost(),i); Log(result); error++; @@ -288,7 +286,7 @@ int TestSuite::assertGame(){ for (int j = 0; j < 4; j++){ MTGGameZone * zone = playerZones[j]; if (zone->nb_cards != endState.playerData[i].zones[j].nbitems){ - Log("==Card number not the same=="); + Log("==Card number not the same==
"); error++; return 0; } @@ -296,7 +294,7 @@ int TestSuite::assertGame(){ int cardid = endState.playerData[i].zones[j].cards[k]; int realcardid = zone->cards[k]->getMTGId(); if ( realcardid!= cardid){ - sprintf(result, "==Card ID not the same. Expected %i, got %i==", cardid, realcardid); + sprintf(result, "==Card ID not the same. Expected %i, got %i==
", cardid, realcardid); Log(result); error++; } @@ -304,7 +302,7 @@ int TestSuite::assertGame(){ } } if (error) return 0; - Log("==Test Succesful !=="); + Log("==Test Succesful !=="); return 1; } @@ -327,9 +325,14 @@ TestSuite::TestSuite(const char * filename){ file.close(); } - ofstream file2 ("Res/test/results.txt"); + ofstream file2 ("Res/test/results.html"); if (file2){ - file2 << "\n"; + file2 << ""; + file2 << ""; + file2 << "\n"; file2.close(); }