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_
|
#ifndef _MTGGAMEZONES_H_
|
||||||
#define _MTGGAMEZONES_H_
|
#define _MTGGAMEZONES_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
using std::map;
|
||||||
|
|
||||||
#include "MTGDeck.h"
|
#include "MTGDeck.h"
|
||||||
#include "MTGCardInstance.h"
|
#include "MTGCardInstance.h"
|
||||||
|
|
||||||
@@ -14,7 +17,9 @@ class MTGGameZone {
|
|||||||
protected:
|
protected:
|
||||||
Player * owner;
|
Player * owner;
|
||||||
public:
|
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];
|
MTGCardInstance * cards[MTG_MAX_PLAYER_CARDS];
|
||||||
|
map<MTGCardInstance *,int> cardsMap;
|
||||||
int nb_cards;
|
int nb_cards;
|
||||||
MTGGameZone();
|
MTGGameZone();
|
||||||
~MTGGameZone();
|
~MTGGameZone();
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#ifndef _SUBTYPES_H_
|
#ifndef _SUBTYPES_H_
|
||||||
#define _SUBTYPES_H_
|
#define _SUBTYPES_H_
|
||||||
|
|
||||||
#define MAX_SUBTYPES 1000
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::map;
|
||||||
|
|
||||||
class Subtypes{
|
class Subtypes{
|
||||||
protected:
|
protected:
|
||||||
int nb_items;
|
int nb_items;
|
||||||
string values[MAX_SUBTYPES];
|
map<string,int> values;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Subtypes * subtypesList;
|
static Subtypes * subtypesList;
|
||||||
Subtypes();
|
Subtypes();
|
||||||
int offset;
|
|
||||||
int Add(const char * subtype);
|
int Add(const char * subtype);
|
||||||
int find(const char * subtype);
|
int find(const char * subtype);
|
||||||
int Add(string subtype);
|
int Add(string subtype);
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ void MTGGameZone::setOwner(Player * player){
|
|||||||
|
|
||||||
MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
|
MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
|
||||||
int i;
|
int i;
|
||||||
|
cardsMap.erase(card);
|
||||||
for (i=0; i<(nb_cards); i++) {
|
for (i=0; i<(nb_cards); i++) {
|
||||||
if (cards[i] == card){
|
if (cards[i] == card){
|
||||||
cards[i] = cards[nb_cards -1];
|
cards[i] = cards[nb_cards -1];
|
||||||
@@ -146,11 +147,7 @@ MTGCardInstance * MTGGameZone::removeCard(MTGCardInstance * card){
|
|||||||
}
|
}
|
||||||
|
|
||||||
MTGCardInstance * MTGGameZone::hasCard(MTGCardInstance * card){
|
MTGCardInstance * MTGGameZone::hasCard(MTGCardInstance * card){
|
||||||
for (int i=0; i<(nb_cards); i++) {
|
if (cardsMap.find(card) != cardsMap.end()) return card;
|
||||||
if (cards[i] == card){
|
|
||||||
return cards[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -196,6 +193,7 @@ void MTGGameZone::addCard(MTGCardInstance * card){
|
|||||||
if (!card) return;
|
if (!card) return;
|
||||||
cards[nb_cards] = card;
|
cards[nb_cards] = card;
|
||||||
nb_cards++;
|
nb_cards++;
|
||||||
|
cardsMap[card] = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +201,7 @@ MTGCardInstance * MTGGameZone::draw(){
|
|||||||
if (!nb_cards) return NULL;
|
if (!nb_cards) return NULL;
|
||||||
nb_cards--;
|
nb_cards--;
|
||||||
lastCardDrawn = cards[nb_cards];
|
lastCardDrawn = cards[nb_cards];
|
||||||
|
cardsMap.erase(cards[nb_cards]);
|
||||||
return cards[nb_cards];
|
return cards[nb_cards];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ Subtypes * Subtypes::subtypesList = NEW Subtypes();
|
|||||||
|
|
||||||
|
|
||||||
Subtypes::Subtypes(){
|
Subtypes::Subtypes(){
|
||||||
nb_items = 0;
|
nb_items = 100;
|
||||||
offset = 100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subtypes::Add(string value){
|
int Subtypes::Add(string value){
|
||||||
@@ -21,9 +20,9 @@ int Subtypes::Add(string value){
|
|||||||
OutputDebugString(buf);
|
OutputDebugString(buf);
|
||||||
#endif
|
#endif
|
||||||
std::transform( value.begin(), value.end(), value.begin(), ::tolower );
|
std::transform( value.begin(), value.end(), value.begin(), ::tolower );
|
||||||
values[nb_items] = value;
|
|
||||||
nb_items++;
|
nb_items++;
|
||||||
return nb_items + offset - 1;
|
values[value] = nb_items;
|
||||||
|
return nb_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Subtypes::Add(const char * subtype){
|
int Subtypes::Add(const char * subtype){
|
||||||
@@ -34,11 +33,8 @@ int Subtypes::Add(const char * subtype){
|
|||||||
|
|
||||||
int Subtypes::find(string value){
|
int Subtypes::find(string value){
|
||||||
std::transform( value.begin(), value.end(), value.begin(), ::tolower );
|
std::transform( value.begin(), value.end(), value.begin(), ::tolower );
|
||||||
for (int i = 0; i < nb_items; i++){
|
map<string,int>::iterator it = values.find(value);
|
||||||
if(values[i].compare(value) == 0){
|
if (it != values.end()) return it->second;
|
||||||
return i + offset;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,6 @@ int TestSuiteAI::Act(float dt){
|
|||||||
GameObserver * g = GameObserver::GetInstance();
|
GameObserver * g = GameObserver::GetInstance();
|
||||||
g->gameOver = NULL; // Prevent draw rule from losing the game
|
g->gameOver = NULL; // Prevent draw rule from losing the game
|
||||||
timer+= dt;
|
timer+= dt;
|
||||||
char buf[4096];
|
|
||||||
sprintf(buf, "%f\n", timer);
|
|
||||||
OutputDebugString (buf);
|
|
||||||
if (timer < suite->timerLimit) return 1;
|
if (timer < suite->timerLimit) return 1;
|
||||||
timer = 0;
|
timer = 0;
|
||||||
string action = suite->getNextAction();
|
string action = suite->getNextAction();
|
||||||
@@ -241,7 +238,7 @@ void TestSuite::initGame(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TestSuite::Log(const char * text){
|
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){
|
if (file){
|
||||||
file << text;
|
file << text;
|
||||||
file << "\n";
|
file << "\n";
|
||||||
@@ -256,30 +253,31 @@ int TestSuite::Log(const char * text){
|
|||||||
}
|
}
|
||||||
int TestSuite::assertGame(){
|
int TestSuite::assertGame(){
|
||||||
//compare the game state with the results
|
//compare the game state with the results
|
||||||
Log("=============================");
|
|
||||||
Log(files[currentfile-1].c_str());
|
|
||||||
char result[4096];
|
char result[4096];
|
||||||
|
sprintf(result,"<h3>%s</h3>",files[currentfile-1].c_str());
|
||||||
|
Log(result);
|
||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
GameObserver * g = GameObserver::GetInstance();
|
GameObserver * g = GameObserver::GetInstance();
|
||||||
if (g->currentGamePhase != endState.phase){
|
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);
|
Log(result);
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 2; i++){
|
for (int i = 0; i < 2; i++){
|
||||||
Player * p = g->players[i];
|
Player * p = g->players[i];
|
||||||
if (p->life != endState.playerData[i].life){
|
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);
|
Log(result);
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
if (! p->getManaPool()->canAfford(endState.playerData[i].manapool)){
|
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);
|
Log(result);
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
if(! endState.playerData[i].manapool->canAfford(p->getManaPool())){
|
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);
|
Log(result);
|
||||||
error++;
|
error++;
|
||||||
|
|
||||||
@@ -288,7 +286,7 @@ int TestSuite::assertGame(){
|
|||||||
for (int j = 0; j < 4; j++){
|
for (int j = 0; j < 4; j++){
|
||||||
MTGGameZone * zone = playerZones[j];
|
MTGGameZone * zone = playerZones[j];
|
||||||
if (zone->nb_cards != endState.playerData[i].zones[j].nbitems){
|
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++;
|
error++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -296,7 +294,7 @@ int TestSuite::assertGame(){
|
|||||||
int cardid = endState.playerData[i].zones[j].cards[k];
|
int cardid = endState.playerData[i].zones[j].cards[k];
|
||||||
int realcardid = zone->cards[k]->getMTGId();
|
int realcardid = zone->cards[k]->getMTGId();
|
||||||
if ( realcardid!= cardid){
|
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);
|
Log(result);
|
||||||
error++;
|
error++;
|
||||||
}
|
}
|
||||||
@@ -304,7 +302,7 @@ int TestSuite::assertGame(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (error) return 0;
|
if (error) return 0;
|
||||||
Log("==Test Succesful !==");
|
Log("<span class=\"success\">==Test Succesful !==</span>");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,9 +325,14 @@ TestSuite::TestSuite(const char * filename){
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
ofstream file2 ("Res/test/results.txt");
|
ofstream file2 ("Res/test/results.html");
|
||||||
if (file2){
|
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();
|
file2.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user