From e2d394f5767d696bbf1550073340948b45103da7 Mon Sep 17 00:00:00 2001 From: doitux Date: Sun, 13 May 2007 18:17:25 +0000 Subject: [PATCH] one ConfigFile for all --- .../local_engine/localenginefactory.cpp | 6 ++--- src/engine/local_engine/localenginefactory.h | 7 +++++- src/engine/local_engine/localplayer.cpp | 24 +++++++------------ src/engine/local_engine/localplayer.h | 5 ++-- src/game.cpp | 6 ++--- src/game.h | 5 +++- src/session.cpp | 2 +- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index df057ecb..b48fcdb7 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -20,8 +20,8 @@ #include "localenginefactory.h" -LocalEngineFactory::LocalEngineFactory() - : EngineFactory() +LocalEngineFactory::LocalEngineFactory(ConfigFile *c) + : EngineFactory(), myConfig(c) { } @@ -35,7 +35,7 @@ HandInterface* LocalEngineFactory::createHand(EngineFactory *f, GuiInterface *g, BoardInterface* LocalEngineFactory::createBoard() { return new LocalBoard; } -PlayerInterface* LocalEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) { return new LocalPlayer(b, id, uniqueId, type, name, avatar, sC, aS, mB); } +PlayerInterface* LocalEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) { return new LocalPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB); } PreflopInterface* LocalEngineFactory::createPreflop(HandInterface* hi, int id, int aP, int dP, int sB) { return new LocalPreflop(hi, id, aP, dP, sB); } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 8caf13ab..39fe3fe8 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -30,10 +30,12 @@ #include "localturn.h" #include "localriver.h" +#include "configfile.h" + class LocalEngineFactory : public EngineFactory { public: - LocalEngineFactory(); + LocalEngineFactory(ConfigFile*); ~LocalEngineFactory(); @@ -44,6 +46,9 @@ public: FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB); TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB); RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB); +private: + + ConfigFile *myConfig; }; #endif diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 1339593e..fa035657 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -23,8 +23,8 @@ using namespace std; -LocalPlayer::LocalPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) -: PlayerInterface(), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) +LocalPlayer::LocalPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) +: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) { // for statistic development @@ -84,12 +84,10 @@ void LocalPlayer::setHand(HandInterface* br) { actualHand = br; } void LocalPlayer::action() { - ConfigFile myConfig; - switch(actualHand->getActualRound()) { case 0: { - if(myConfig.readConfigInt("EngineVersion")) preflopEngine3(); + if(myConfig->readConfigInt("EngineVersion")) preflopEngine3(); else preflopEngine(); actualBoard->collectSets(); @@ -98,7 +96,7 @@ void LocalPlayer::action() { } break; case 1: { - if(myConfig.readConfigInt("EngineVersion")) flopEngine3(); + if(myConfig->readConfigInt("EngineVersion")) flopEngine3(); else flopEngine(); actualBoard->collectSets(); @@ -107,7 +105,7 @@ void LocalPlayer::action() { } break; case 2: { - if(myConfig.readConfigInt("EngineVersion")) turnEngine3(); + if(myConfig->readConfigInt("EngineVersion")) turnEngine3(); else turnEngine(); actualBoard->collectSets(); @@ -116,7 +114,7 @@ void LocalPlayer::action() { } break; case 3: { - if(myConfig.readConfigInt("EngineVersion")) riverEngine3(); + if(myConfig->readConfigInt("EngineVersion")) riverEngine3(); else riverEngine(); actualBoard->collectSets(); @@ -810,7 +808,6 @@ void LocalPlayer::flopEngine() { void LocalPlayer::turnEngine() { - ConfigFile myConfig; // int tempArray[6]; // int boardCards[5]; @@ -1057,9 +1054,7 @@ void LocalPlayer::turnEngine() { void LocalPlayer::riverEngine() { - ConfigFile myConfig; - -// int tempArray[6]; + // int tempArray[6]; // int boardCards[5]; // int i; @@ -2058,7 +2053,6 @@ int LocalPlayer::flopCardsValue(int* cards) { void LocalPlayer::readFile() { - ConfigFile myConfig; int handCode; switch(actualHand->getActualRound()) { @@ -2067,7 +2061,7 @@ void LocalPlayer::readFile() { handCode = preflopCardsValue(myCards); - std::string fileName = myConfig.readConfigString("DataDir")+"preflopValues"; + std::string fileName = myConfig->readConfigString("DataDir")+"preflopValues"; ifstream fin; @@ -2121,7 +2115,7 @@ void LocalPlayer::readFile() { // cout << "\t" << handCode << endl; - std::string fileName = myConfig.readConfigString("DataDir")+"flopValues"; + std::string fileName = myConfig->readConfigString("DataDir")+"flopValues"; ifstream fin; diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index e5549f7d..2a316387 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -36,8 +36,7 @@ class BoardInterface; class LocalPlayer : public PlayerInterface{ public: - LocalPlayer( - BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); + LocalPlayer(ConfigFile*, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); ~LocalPlayer(); @@ -142,6 +141,8 @@ public: private: + + ConfigFile *myConfig; HandInterface *actualHand; BoardInterface *actualBoard; diff --git a/src/game.cpp b/src/game.cpp index aa5aa997..728d6ad5 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -30,12 +30,12 @@ using namespace std; -Game::Game(GuiInterface* gui, const PlayerDataList &playerDataList, const GameData &gameData, int gameId) +Game::Game(GuiInterface* gui, const PlayerDataList &playerDataList, const GameData &gameData, int gameId, ConfigFile *c) : myGui(gui), actualHand(0), actualBoard(0), startQuantityPlayers(gameData.numberOfPlayers), startCash(gameData.startCash), startSmallBlind(gameData.smallBlind), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers), - actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) + actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0), myConfig(c) { // cout << "Create Game Object" << "\n"; int i; @@ -47,7 +47,7 @@ Game::Game(GuiInterface* gui, const PlayerDataList &playerDataList, const GameDa } //EngineFactory erstellen - myFactory = new LocalEngineFactory; // LocalEngine erstellen + myFactory = new LocalEngineFactory(myConfig); // LocalEngine erstellen // Board erstellen diff --git a/src/game.h b/src/game.h index 82ae0e30..19dbf802 100755 --- a/src/game.h +++ b/src/game.h @@ -26,6 +26,7 @@ #include "game_defs.h" #include "playerdata.h" +#include "configfile.h" class GuiInterface; class HandInterface; @@ -37,7 +38,7 @@ struct GameData; class Game { public: - Game(GuiInterface *gui, const PlayerDataList &playerDataList, const GameData &gameData, int gameId); + Game(GuiInterface *gui, const PlayerDataList &playerDataList, const GameData &gameData, int gameId, ConfigFile*); ~Game(); @@ -95,6 +96,8 @@ private: int actualSmallBlind; int actualHandID; int dealerPosition; + + ConfigFile *myConfig; }; #endif diff --git a/src/session.cpp b/src/session.cpp index 6af72e6c..8ba5d793 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -73,7 +73,7 @@ void Session::startGame(const GameData &gameData) { playerDataList.push_back(playerData); } - currentGame = new Game(myGui, playerDataList, gameData, currentGameID); + currentGame = new Game(myGui, playerDataList, gameData, currentGameID, myConfig); //// SPIEL-SCHLEIFE currentGame->initHand();