Erwan
- the testsuite now outputs an HTML result file with colors - hopefully speed improvements for the game on PSP (needs testing on the actual device)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#ifndef _MTGGAMEZONES_H_
|
||||
#define _MTGGAMEZONES_H_
|
||||
|
||||
#include <map>
|
||||
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<MTGCardInstance *,int> cardsMap;
|
||||
int nb_cards;
|
||||
MTGGameZone();
|
||||
~MTGGameZone();
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
#ifndef _SUBTYPES_H_
|
||||
#define _SUBTYPES_H_
|
||||
|
||||
#define MAX_SUBTYPES 1000
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
using std::string;
|
||||
using std::map;
|
||||
|
||||
class Subtypes{
|
||||
protected:
|
||||
int nb_items;
|
||||
string values[MAX_SUBTYPES];
|
||||
int nb_items;
|
||||
map<string,int> values;
|
||||
|
||||
public:
|
||||
static Subtypes * subtypesList;
|
||||
Subtypes();
|
||||
int offset;
|
||||
int Add(const char * subtype);
|
||||
int find(const char * subtype);
|
||||
int Add(string subtype);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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<string,int>::iterator it = values.find(value);
|
||||
if (it != values.end()) return it->second;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,"<h3>%s</h3>",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, "<span class=\"error\">==phase problem. Expected %i, got %i==</span><br />",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, "<span class=\"error\">==life problem for player %i. Expected %i, got %i==</span><br />",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, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />",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, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />",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("<span class=\"error\">==Card number not the same==</span><br />");
|
||||
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, "<span class=\"error\">==Card ID not the same. Expected %i, got %i==</span><br />", cardid, realcardid);
|
||||
Log(result);
|
||||
error++;
|
||||
}
|
||||
@@ -304,7 +302,7 @@ int TestSuite::assertGame(){
|
||||
}
|
||||
}
|
||||
if (error) return 0;
|
||||
Log("==Test Succesful !==");
|
||||
Log("<span class=\"success\">==Test Succesful !==</span>");
|
||||
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 << "<html><head>";
|
||||
file2 << "<meta http-equiv=\"refresh\" content=\"10\" >";
|
||||
file2 << "<STYLE type='text/css'>";
|
||||
file2 << ".success {color:green}\n";
|
||||
file2 << ".error {color:red}\n";
|
||||
file2 << "</STYLE></head><body>\n";
|
||||
file2.close();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user