From 84c857cbffbe2bdf25ed2fc05aea4aa18f6198f1 Mon Sep 17 00:00:00 2001 From: doitux Date: Sun, 23 Sep 2007 21:30:51 +0000 Subject: [PATCH] adds activePlayerList and runningPlayerList --- src/engine/boardinterface.h | 5 ++- src/engine/enginefactory.h | 2 +- src/engine/local_engine/localboard.cpp | 6 +++- src/engine/local_engine/localboard.h | 5 ++- .../local_engine/localenginefactory.cpp | 2 +- src/engine/local_engine/localenginefactory.h | 2 +- src/engine/local_engine/localhand.cpp | 8 ++--- src/engine/local_engine/localhand.h | 6 +++- src/engine/network_engine/clientboard.cpp | 6 ++-- src/engine/network_engine/clientboard.h | 5 ++- .../network_engine/clientenginefactory.cpp | 4 +-- .../network_engine/clientenginefactory.h | 2 +- src/engine/network_engine/clienthand.cpp | 4 +-- src/engine/network_engine/clienthand.h | 6 +++- src/game.cpp | 35 ++++++++++++------- src/game.h | 10 +++++- 16 files changed, 74 insertions(+), 34 deletions(-) diff --git a/src/engine/boardinterface.h b/src/engine/boardinterface.h index 1943b607..4b8ab943 100644 --- a/src/engine/boardinterface.h +++ b/src/engine/boardinterface.h @@ -21,18 +21,21 @@ #define BOARDINTERFACE_H #include +#include #include class PlayerInterface; class HandInterface; +typedef std::list > PlayerList; + class BoardInterface { public: virtual ~BoardInterface(); // - virtual void setPlayer(std::vector >) =0; + virtual void setPlayerLists(std::vector >, PlayerList, PlayerList) =0; virtual void setHand(HandInterface*) =0; // virtual void setMyCards(int* theValue) =0; diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index f6594504..34d00cdf 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -33,7 +33,7 @@ public: virtual ~EngineFactory(); - virtual HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC) =0; + virtual HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC) =0; virtual BoardInterface* createBoard() =0; virtual boost::shared_ptr createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) =0; virtual std::vector > createBeRo(HandInterface* hi, int id, int aP, int dP, int sB) =0; diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index cc861ac3..260462c6 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -33,7 +33,11 @@ LocalBoard::~LocalBoard() { } -void LocalBoard::setPlayer(std::vector > p) { playerArray = p; } +void LocalBoard::setPlayerLists(std::vector > sl, PlayerList apl, PlayerList rpl) { + playerArray = sl; + activePlayerList = apl; + runningPlayerList = rpl; +} void LocalBoard::setHand(HandInterface* br) { currentHand = br; } diff --git a/src/engine/local_engine/localboard.h b/src/engine/local_engine/localboard.h index 7989a314..62d34e3a 100755 --- a/src/engine/local_engine/localboard.h +++ b/src/engine/local_engine/localboard.h @@ -35,7 +35,7 @@ public: LocalBoard(); ~LocalBoard(); - void setPlayer(std::vector >); + void setPlayerLists(std::vector >, PlayerList, PlayerList); void setHand(HandInterface*); void setMyCards(int* theValue) { int i; for(i=0; i<5; i++) myCards[i] = theValue[i]; } @@ -54,6 +54,9 @@ public: private: std::vector > playerArray; + PlayerList activePlayerList; + PlayerList runningPlayerList; + HandInterface *currentHand; int myCards[5]; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index 87690d49..c27de3c8 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -42,7 +42,7 @@ LocalEngineFactory::~LocalEngineFactory() } -HandInterface* LocalEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC) { return new LocalHand(f, g, b, p, id, sP, aP, dP, sB, sC); } +HandInterface* LocalEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC) { return new LocalHand(f, g, b, sl, apl, rpl, id, sP, aP, dP, sB, sC); } BoardInterface* LocalEngineFactory::createBoard() { return new LocalBoard; } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 9cea3f93..0ed0db7d 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -37,7 +37,7 @@ public: LocalEngineFactory(ConfigFile*); ~LocalEngineFactory(); - HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC); + HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC); BoardInterface* createBoard(); boost::shared_ptr createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); std::vector > createBeRo(HandInterface* hi, int id, int aP, int dP, int sB); diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index f681abb9..04e49a76 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -26,8 +26,8 @@ using namespace std; -LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(p), myBeRo(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0), +LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC) +: myFactory(f), myGui(g), myBoard(b), playerArray(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0), cardsShown(false), bettingRoundsPlayed(0) { @@ -50,8 +50,8 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI } // Karten generieren und Board sowie Player zuweisen - int *cardsArray = new int[2*actualQuantityPlayers+5]; - Tools::getRandNumber(0, 51, 2*actualQuantityPlayers+5, cardsArray, 1); + int *cardsArray = new int[2*activePlayerList.size()+5]; + Tools::getRandNumber(0, 51, 2*activePlayerList.size()+5, cardsArray, 1); int tempBoardArray[5]; int tempPlayerArray[2]; int tempPlayerAndBoardArray[7]; diff --git a/src/engine/local_engine/localhand.h b/src/engine/local_engine/localhand.h index 22bdd0bc..521bff2f 100755 --- a/src/engine/local_engine/localhand.h +++ b/src/engine/local_engine/localhand.h @@ -34,7 +34,7 @@ class LocalHand : public HandInterface{ public: - LocalHand(boost::shared_ptr f, GuiInterface*, BoardInterface*, std::vector >, int, int, int, int, int, int); + LocalHand(boost::shared_ptr f, GuiInterface*, BoardInterface*, std::vector >, PlayerList, PlayerList, int, int, int, int, int, int); ~LocalHand(); void start(); @@ -94,7 +94,11 @@ private: boost::shared_ptr myFactory; GuiInterface *myGui; BoardInterface *myBoard; + std::vector > playerArray; + PlayerList activePlayerList; + PlayerList runningPlayerList; + std::vector > myBeRo; int myID; diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index f33015d7..c7001438 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -34,10 +34,12 @@ ClientBoard::~ClientBoard() } void -ClientBoard::setPlayer(std::vector > p) +ClientBoard::setPlayerLists(std::vector > sl, PlayerList apl, PlayerList rpl) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - playerArray = p; + playerArray = sl; + activePlayerList = apl; + runningPlayerList = rpl; } void diff --git a/src/engine/network_engine/clientboard.h b/src/engine/network_engine/clientboard.h index b2c99949..5fa412ff 100644 --- a/src/engine/network_engine/clientboard.h +++ b/src/engine/network_engine/clientboard.h @@ -34,7 +34,7 @@ public: ClientBoard(); ~ClientBoard(); - void setPlayer(std::vector >); + void setPlayerLists(std::vector >, PlayerList, PlayerList); void setHand(HandInterface*); void setMyCards(int* theValue); @@ -54,6 +54,9 @@ private: mutable boost::recursive_mutex m_syncMutex; std::vector > playerArray; + PlayerList activePlayerList; + PlayerList runningPlayerList; + HandInterface *actualHand; int myCards[5]; diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index bcbc57fb..7c3a10c8 100644 --- a/src/engine/network_engine/clientenginefactory.cpp +++ b/src/engine/network_engine/clientenginefactory.cpp @@ -35,9 +35,9 @@ ClientEngineFactory::~ClientEngineFactory() } -HandInterface* ClientEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC) +HandInterface* ClientEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC) { - return new ClientHand(f, g, b, p, id, sP, aP, dP, sB, sC); + return new ClientHand(f, g, b, sl, apl, rpl, id, sP, aP, dP, sB, sC); } BoardInterface* ClientEngineFactory::createBoard() diff --git a/src/engine/network_engine/clientenginefactory.h b/src/engine/network_engine/clientenginefactory.h index 5cc2ecc6..2a2d7885 100644 --- a/src/engine/network_engine/clientenginefactory.h +++ b/src/engine/network_engine/clientenginefactory.h @@ -37,7 +37,7 @@ public: ClientEngineFactory(); ~ClientEngineFactory(); - HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC); + HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC); BoardInterface* createBoard(); boost::shared_ptr createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); std::vector > createBeRo(HandInterface* hi, int id, int aP, int dP, int sB); diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index 15557ae5..44cd85c4 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -21,8 +21,8 @@ using namespace std; -ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > p, int id, int sP, int aP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(p), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), +ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int aP, int dP, int sB,int sC) +: myFactory(f), myGui(g), myBoard(b), playerArray(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), activePlayersCounter(aP), lastPlayersTurn(0), allInCondition(0), cardsShown(false), bettingRoundsPlayed(0) { diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index c7868a2c..7b281bfd 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -32,7 +32,7 @@ class ClientHand : public HandInterface { public: - ClientHand ( boost::shared_ptr f, GuiInterface*, BoardInterface*, std::vector > , int, int, int, int, int, int ); + ClientHand ( boost::shared_ptr f, GuiInterface*, BoardInterface*, std::vector >, PlayerList, PlayerList , int, int, int, int, int, int ); ~ClientHand(); void start(); @@ -91,7 +91,11 @@ class ClientHand : public HandInterface boost::shared_ptr myFactory; GuiInterface *myGui; BoardInterface *myBoard; + std::vector > playerArray; + PlayerList activePlayerList; + PlayerList runningPlayerList; + std::vector > myBeRo; int myID; diff --git a/src/game.cpp b/src/game.cpp index 540c1131..5cf0cebc 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -92,14 +92,23 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, ++player_i; } - //PlayerObjekte erzeugen - playerArray.push_back(myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0)); + // create Player Objects + boost::shared_ptr tmpPlayer = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); + + // fill player lists + playerArray.push_back(tmpPlayer); + if(startQuantityPlayers > i) { + activePlayerList.push_back(tmpPlayer); + runningPlayerList.push_back(tmpPlayer); + } + + // playerArray[i] = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); playerArray[i]->setNetSessionData(myNetSession); } - actualBoard->setPlayer(playerArray); + actualBoard->setPlayerLists(playerArray, activePlayerList, runningPlayerList); } @@ -140,26 +149,26 @@ void Game::initHand() // smallBlind alle x Runden erhöhen if((actualHandID-1)%startHandsBeforeRaiseSmallBlind == 0 && actualHandID > 1) { actualSmallBlind *= 2; } - - // Spieler mit leerem Cash auf inactive setzen - for(i=0; igetMyCash() == 0) playerArray[i]->setMyActiveStatus(0); + PlayerList::iterator it; + + for(it = activePlayerList.begin(); it != activePlayerList.end(); it++) { + if((*it)->getMyCash() == 0) { + (*it)->setMyActiveStatus(0); + it = activePlayerList.erase(it); + } } // Anzahl noch aktiver Spieler ermitteln - actualQuantityPlayers = 0; - for(i=0; igetMyActiveStatus()) actualQuantityPlayers++; - } + actualQuantityPlayers = activePlayerList.size(); // TODO -> delete !!! - //Spieler Action auf 0 setzen + //Spieler Action auf 0 setzen for(i=0; isetMyAction(0); } // Hand erstellen - actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, actualHandID, startQuantityPlayers, actualQuantityPlayers, dealerPosition, actualSmallBlind, startCash); + actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, activePlayerList, runningPlayerList, actualHandID, startQuantityPlayers, actualQuantityPlayers, dealerPosition, actualSmallBlind, startCash); // Dealer-Button weiterschieben --> Achtung inactive diff --git a/src/game.h b/src/game.h index ab912946..2771dc70 100755 --- a/src/game.h +++ b/src/game.h @@ -35,6 +35,8 @@ class EngineFactory; struct GameData; struct StartData; +typedef std::list > PlayerList; + class Game { public: @@ -51,6 +53,8 @@ public: const HandInterface *getCurrentHand() const; std::vector > getPlayerArray() {return playerArray;} + std::list > getActivePlayerList() {return activePlayerList;} + std::list > getRunningPlayerList() {return runningPlayerList;} //Zufgriff Startvariablen void setStartQuantityPlayers(int theValue) { startQuantityPlayers = theValue; } @@ -83,7 +87,11 @@ private: GuiInterface *myGui; HandInterface *actualHand; BoardInterface *actualBoard; - std::vector > playerArray; + + std::vector > playerArray; // available seats --> seatList !!! TODO + std::list > activePlayerList; // used seats + std::list > runningPlayerList; // nonfolded and nonallin active players + // boost::shared_ptr playerArray[MAX_NUMBER_OF_PLAYERS]; //Startvariablen