-Fixed bug with fountain of youth
-New alternate format for decks
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-04-02 12:50:18 +00:00
parent 3e1bcbfd22
commit 5952b382a2
13 changed files with 132 additions and 56 deletions
+1 -1
View File
@@ -666,7 +666,7 @@ subtype=Forest
[/card] [/card]
[card] [card]
text={2}, {T}: You gain 1 life. text={2}, {T}: You gain 1 life.
auto={2},{T}:life 1 auto={2},{T}:life:1
id=135273 id=135273
name=Fountain of Youth name=Fountain of Youth
rarity=U rarity=U
+1
View File
@@ -50,6 +50,7 @@ foratog.txt
force_of_nature.txt force_of_nature.txt
force_of_nature2.txt force_of_nature2.txt
force_of_nature3.txt force_of_nature3.txt
fountain_of_youth.txt
ghost_warden.txt ghost_warden.txt
giant_growth.txt giant_growth.txt
giant_growth2.txt giant_growth2.txt
@@ -0,0 +1,17 @@
#Testing Does fountain of youth give +1 life ?
[INIT]
FIRSTMAIN
[PLAYER1]
inplay:fountain of youth
manapool:{2}
[PLAYER2]
[DO]
fountain of youth
[ASSERT]
FIRSTMAIN
[PLAYER1]
inplay:fountain of youth
manapool:{0}
life:21
[PLAYER2]
[END]
+2
View File
@@ -35,6 +35,7 @@ class MtgSets{
static MtgSets * SetsList; static MtgSets * SetsList;
MtgSets(); MtgSets();
int Add(const char * subtype); int Add(const char * subtype);
int find(string value);
}; };
@@ -59,6 +60,7 @@ class MTGAllCards {
MTGAllCards(const char * config_file, const char * set_name); MTGAllCards(const char * config_file, const char * set_name);
MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache); MTGAllCards(const char * config_file, const char * set_name, TexturesCache * cache);
MTGCard * getCardById(int id); MTGCard * getCardById(int id);
MTGCard * getCardByName(string name);
int load(const char * config_file, const char * setName, int autoload = 1); int load(const char * config_file, const char * setName, int autoload = 1);
int countByType(const char * _type); int countByType(const char * _type);
int countByColor(int color); int countByColor(int color);
+2
View File
@@ -10,6 +10,7 @@ using std::map;
#define MTG_MAX_PLAYER_CARDS 100 #define MTG_MAX_PLAYER_CARDS 100
class MTGAllCards; class MTGAllCards;
class MTGDeck;
class MTGCardInstance; class MTGCardInstance;
class Player; class Player;
@@ -88,6 +89,7 @@ class MTGPlayerCards {
MTGAllCards * collection; MTGAllCards * collection;
MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize); MTGPlayerCards(MTGAllCards * _collection, int * idList, int idListSize);
MTGPlayerCards(MTGAllCards * _collection, MTGDeck * deck);
~MTGPlayerCards(); ~MTGPlayerCards();
void initGame(int shuffle = 1, int draw = 1); void initGame(int shuffle = 1, int draw = 1);
void setOwner(Player * player); void setOwner(Player * player);
+8 -4
View File
@@ -37,16 +37,19 @@ class TestSuitePlayerData{
class TestSuite;
class TestSuiteState{ class TestSuiteState{
public: public:
int phase; int phase;
void parsePlayerState(int playerId, string s); void parsePlayerState(int playerId, string s,TestSuite * suite);
TestSuiteState(); TestSuiteState();
TestSuitePlayerData playerData[2]; TestSuitePlayerData playerData[2];
void cleanup(); void cleanup();
}; };
class TestSuite{ class TestSuite{
public: public:
MTGAllCards* collection;
int summoningSickness; int summoningSickness;
float timerLimit; float timerLimit;
int currentAction; int currentAction;
@@ -57,10 +60,10 @@ class TestSuite{
int nbfiles; int nbfiles;
int currentfile; int currentfile;
void load(const char * filename); void load(const char * filename);
TestSuite(const char * filename); TestSuite(const char * filename,MTGAllCards* _collection);
void initGame(); void initGame();
int assertGame(); int assertGame();
MTGPlayerCards * buildDeck(MTGAllCards * collection, int playerId); MTGPlayerCards * buildDeck(int playerId);
string getNextAction(); string getNextAction();
int phaseStrToInt(string s); int phaseStrToInt(string s);
MTGCardInstance * getCardByMTGId(int mtgid); MTGCardInstance * getCardByMTGId(int mtgid);
@@ -68,6 +71,7 @@ class TestSuite{
int loadNext(); int loadNext();
void cleanup(); void cleanup();
int Log(const char * text); int Log(const char * text);
int getMTGId(string name);
}; };
@@ -75,7 +79,7 @@ class TestSuiteAI:public AIPlayer{
public: public:
TestSuite * suite; TestSuite * suite;
float timer; float timer;
TestSuiteAI(MTGAllCards * collection,TestSuite * suite, int playerId); TestSuiteAI(TestSuite * suite, int playerId);
virtual int Act(float dt); virtual int Act(float dt);
virtual int displayStack(){return 1;} virtual int displayStack(){return 1;}
-2
View File
@@ -30,10 +30,8 @@
using std::string; using std::string;
int lowercase(string source);
int filesize(const char * filename); int filesize(const char * filename);
int readfile_to_ints(const char * filename, int * out_buffer);
int fileExists(const char * filename); int fileExists(const char * filename);
#ifdef LINUX #ifdef LINUX
+3 -2
View File
@@ -551,8 +551,9 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, MTGPlayerCa
OutputDebugString(debuf); OutputDebugString(debuf);
#endif #endif
int deck_cards_ids[100]; int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids); MTGDeck * tempDeck = NEW MTGDeck(deckFile, NULL, collection);
MTGPlayerCards * deck = NEW MTGPlayerCards(collection,deck_cards_ids, nb_elements); MTGPlayerCards * deck = NEW MTGPlayerCards(collection,tempDeck);
delete tempDeck;
AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFileSmall, avatarFile); AIPlayerBaka * baka = NEW AIPlayerBaka(deck,deckFileSmall, avatarFile);
return baka; return baka;
} }
+7 -5
View File
@@ -66,7 +66,7 @@ void GameStateDuel::Start()
#ifdef TESTSUITE #ifdef TESTSUITE
if (testSuite) delete testSuite; if (testSuite) delete testSuite;
testSuite = NEW TestSuite(RESPATH"/test/_tests.txt"); testSuite = NEW TestSuite(RESPATH"/test/_tests.txt",mParent->collection);
#endif #endif
@@ -117,9 +117,11 @@ void GameStateDuel::loadPlayer(int playerId, int decknb, int isAI){
sprintf(deckFile, RESPATH"/player/deck%i.txt",decknb); sprintf(deckFile, RESPATH"/player/deck%i.txt",decknb);
char deckFileSmall[255]; char deckFileSmall[255];
sprintf(deckFileSmall, "player_deck%i",decknb); sprintf(deckFileSmall, "player_deck%i",decknb);
int deck_cards_ids[100]; //int deck_cards_ids[100];
int nb_elements = readfile_to_ints(deckFile, deck_cards_ids); //int nb_elements = readfile_to_ints(deckFile, deck_cards_ids);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,deck_cards_ids, nb_elements); MTGDeck * tempDeck = NEW MTGDeck(deckFile, NULL, mParent->collection);
deck[playerId] = NEW MTGPlayerCards(mParent->collection,tempDeck);
delete tempDeck;
mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall); mPlayers[playerId] = NEW HumanPlayer(deck[playerId],deckFileSmall);
}else{ //AI Player, chose deck }else{ //AI Player, chose deck
AIPlayerFactory playerCreator; AIPlayerFactory playerCreator;
@@ -141,7 +143,7 @@ void GameStateDuel::loadTestSuitePlayers(){
if (mPlayers[i]){ if (mPlayers[i]){
delete mPlayers[i]; delete mPlayers[i];
} }
mPlayers[i] = NEW TestSuiteAI(mParent->collection,testSuite, i); mPlayers[i] = NEW TestSuiteAI(testSuite, i);
OutputDebugString ("loading suite 2\n"); OutputDebugString ("loading suite 2\n");
deck[i] = mPlayers[i]->game; deck[i] = mPlayers[i]->game;
} }
+50 -1
View File
@@ -30,6 +30,16 @@ int MtgSets::Add(const char * name){
return nb_items - 1; return nb_items - 1;
} }
int MtgSets::find(string name){
std::transform(name.begin(), name.end(), name.begin(),::tolower );
for (int i = 0; i < nb_items; i++){
string set = values[i];
std::transform(set.begin(), set.end(), set.begin(),::tolower );;
if (set.compare(name) == 0) return i;
}
return -1;
}
int MTGAllCards::processConfLine(string s, MTGCard *card){ int MTGAllCards::processConfLine(string s, MTGCard *card){
unsigned int i = s.find_first_of("="); unsigned int i = s.find_first_of("=");
@@ -279,6 +289,29 @@ MTGCard * MTGAllCards::getCardById(int id){
return 0; return 0;
} }
MTGCard * MTGAllCards::getCardByName(string name){
if (!name.size()) return NULL;
if (name[0] == '#') return NULL;
std::transform(name.begin(), name.end(), name.begin(),::tolower );
int setId = -1;
size_t found = name.find(" (");
if (found != string::npos){
size_t end = name.find(")");
string setName = name.substr(found+2,end-found-2);
name = name.substr(0,found);
setId = MtgSets::SetsList->find(setName);
}
for (int i=0; i<total_cards; i++){
if (setId!=-1 && setId != collection[i]->setId) continue;
string cardName = collection[i]->name;
std::transform(cardName.begin(), cardName.end(), cardName.begin(),::tolower );
if (cardName.compare(name) == 0) return collection[i];
}
return NULL;
}
MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards * _allcards){
@@ -292,7 +325,23 @@ MTGDeck::MTGDeck(const char * config_file, TexturesCache * cache, MTGAllCards *
if(file){ if(file){
while(std::getline(file,s)){ while(std::getline(file,s)){
int cardnb = atoi(s.c_str()); int cardnb = atoi(s.c_str());
if (cardnb) add(cardnb); if (cardnb){
add(cardnb);
}else{
int nb = 1;
size_t found = s.find(" *");
if (found != string::npos){
nb = atoi(s.substr(found+2).c_str());
s=s.substr(0,found);
OutputDebugString(s.c_str());
}
MTGCard * card = allcards->getCardByName(s);
if (card){
for (int i = 0; i < nb; i++){
add(card);
}
}
}
} }
file.close(); file.close();
}else{ }else{
+18
View File
@@ -3,6 +3,7 @@
#include "../include/Player.h" #include "../include/Player.h"
#include "../include/GameOptions.h" #include "../include/GameOptions.h"
#include "../include/WEvent.h" #include "../include/WEvent.h"
#include "../include/MTGDeck.h"
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
#include <time.h> #include <time.h>
@@ -27,6 +28,23 @@ MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection, int * idList, int idLi
}
MTGPlayerCards::MTGPlayerCards(MTGAllCards * _collection,MTGDeck * deck){
init();
collection = _collection;
for (int i=0; i<deck->totalCards(); i++){
MTGCard * card = deck->collection[i];
if (card){
MTGCardInstance * newCard = NEW MTGCardInstance(card, this);
library->addCard(newCard);
}
}
} }
MTGPlayerCards::~MTGPlayerCards(){ MTGPlayerCards::~MTGPlayerCards(){
+23 -14
View File
@@ -5,7 +5,7 @@
#include <string> #include <string>
using std::string; using std::string;
TestSuiteAI::TestSuiteAI(MTGAllCards* collection, TestSuite * _suite, int playerId):AIPlayer(_suite->buildDeck(collection, playerId),"testsuite"){ TestSuiteAI::TestSuiteAI(TestSuite * _suite, int playerId):AIPlayer(_suite->buildDeck(playerId),"testsuite"){
suite = _suite; suite = _suite;
timer= 0; timer= 0;
mAvatarTex = JRenderer::GetInstance()->LoadTexture("ai/baka/avatar.jpg", TEX_TYPE_USE_VRAM); mAvatarTex = JRenderer::GetInstance()->LoadTexture("ai/baka/avatar.jpg", TEX_TYPE_USE_VRAM);
@@ -14,6 +14,14 @@ TestSuiteAI::TestSuiteAI(MTGAllCards* collection, TestSuite * _suite, int player
} }
} }
int TestSuite::getMTGId(string cardName){
int cardnb = atoi(cardName.c_str());
if (cardnb) return cardnb;
MTGCard * card = collection->getCardByName(cardName);
if (card) return card->getMTGId();
return 0;
}
MTGCardInstance * TestSuite::getCardByMTGId(int mtgid){ MTGCardInstance * TestSuite::getCardByMTGId(int mtgid){
GameObserver * g = GameObserver::GetInstance(); GameObserver * g = GameObserver::GetInstance();
for (int i = 0; i < 2; i++){ for (int i = 0; i < 2; i++){
@@ -90,7 +98,7 @@ int TestSuiteAI::Act(float dt){
int choice = atoi(action.substr(action.find("choice ") + 7).c_str()); int choice = atoi(action.substr(action.find("choice ") + 7).c_str());
g->mLayers->actionLayer()->doReactTo(choice); g->mLayers->actionLayer()->doReactTo(choice);
}else{ }else{
int mtgid = atoi(action.c_str()); int mtgid = suite->getMTGId(action);
if (mtgid){ if (mtgid){
Interruptible * toInterrupt = suite->getActionByMTGId(mtgid); Interruptible * toInterrupt = suite->getActionByMTGId(mtgid);
if (toInterrupt){ if (toInterrupt){
@@ -140,7 +148,7 @@ TestSuiteState::TestSuiteState(){
} }
void TestSuiteState::parsePlayerState(int playerId, string s){ void TestSuiteState::parsePlayerState(int playerId, string s, TestSuite * suite){
unsigned int limiter = s.find(":"); unsigned int limiter = s.find(":");
string areaS; string areaS;
int area; int area;
@@ -169,13 +177,13 @@ void TestSuiteState::parsePlayerState(int playerId, string s){
unsigned int value; unsigned int value;
limiter = s.find(","); limiter = s.find(",");
if (limiter != string::npos){ if (limiter != string::npos){
value = atoi(s.substr(0,limiter).c_str()); value = suite->getMTGId(s.substr(0,limiter));
s = s.substr(limiter+1); s = s.substr(limiter+1);
}else{ }else{
value = atoi(s.c_str()); value = suite->getMTGId(s);
s = ""; s = "";
} }
playerData[playerId].zones[area].add(value); if (value) playerData[playerId].zones[area].add(value);
} }
}else{ }else{
//ERROR //ERROR
@@ -192,7 +200,7 @@ string TestSuite::getNextAction(){
} }
MTGPlayerCards * TestSuite::buildDeck(MTGAllCards * collection, int playerId){ MTGPlayerCards * TestSuite::buildDeck( int playerId){
int list[100]; int list[100];
int nbcards = 0; int nbcards = 0;
for (int j = 0; j < 4; j++){ for (int j = 0; j < 4; j++){
@@ -324,7 +332,8 @@ int TestSuite::assertGame(){
return 1; return 1;
} }
TestSuite::TestSuite(const char * filename){ TestSuite::TestSuite(const char * filename,MTGAllCards* _collection){
collection=_collection;
timerLimit = 0; timerLimit = 0;
std::ifstream file(filename); std::ifstream file(filename);
std::string s; std::string s;
@@ -451,14 +460,14 @@ void TestSuite::load(const char * _filename){
if (s.compare("[player2]") == 0){ if (s.compare("[player2]") == 0){
state++; state++;
}else{ }else{
initState.parsePlayerState(0, s); initState.parsePlayerState(0, s,this);
} }
break; break;
case 2: case 2:
if (s.compare("[do]") == 0){ if (s.compare("[do]") == 0){
state++; state++;
}else{ }else{
initState.parsePlayerState(1, s); initState.parsePlayerState(1, s,this);
} }
break; break;
case 3: case 3:
@@ -479,14 +488,14 @@ void TestSuite::load(const char * _filename){
if (s.compare("[player2]") == 0){ if (s.compare("[player2]") == 0){
state++; state++;
}else{ }else{
endState.parsePlayerState(0, s); endState.parsePlayerState(0, s,this);
} }
break; break;
case 6: case 6:
if (s.compare("[end]") == 0){ if (s.compare("[end]") == 0){
state++; state++;
}else{ }else{
endState.parsePlayerState(1, s); endState.parsePlayerState(1, s,this);
} }
break; break;
} }
-27
View File
@@ -2,13 +2,6 @@
#include "../include/utils.h" #include "../include/utils.h"
int lowercase(string sBuffer) {
std::transform( sBuffer.begin(), sBuffer.end(), sBuffer.begin(),
::tolower );
return 1;
}
@@ -35,26 +28,6 @@ int filesize(const char * filename){
} }
int readfile_to_ints(const char * filename, int * out_buffer){
std::ifstream fichier(filename);
std::string s;
unsigned int count = 0;
if(fichier){
while(std::getline(fichier,s)){
int value = atoi(s.c_str());
if (value){
out_buffer[count] = value;
++count;
}
}
}
fichier.close();
return count;
}
int fileExists(const char * filename){ int fileExists(const char * filename){
std::ifstream fichier(filename); std::ifstream fichier(filename);
if(fichier){ if(fichier){