From aab3ac6b2c1c5ac08eccc866a7d6b0d3befc19ac Mon Sep 17 00:00:00 2001 From: doitux Date: Thu, 27 Sep 2007 00:37:01 +0000 Subject: [PATCH] adds activePlayerList and runningPlayerList (XVII) - !!! network-BROKEN !!! --- src/engine/boardinterface.h | 2 +- src/engine/enginefactory.h | 2 +- src/engine/handinterface.h | 1 + src/engine/local_engine/localboard.cpp | 104 +++++++++++--- 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 | 127 +++++++++++++++--- src/engine/local_engine/localhand.h | 6 +- src/engine/network_engine/clientboard.cpp | 5 +- src/engine/network_engine/clientboard.h | 5 +- .../network_engine/clientenginefactory.cpp | 4 +- .../network_engine/clientenginefactory.h | 2 +- src/engine/network_engine/clienthand.cpp | 18 ++- src/engine/network_engine/clienthand.h | 6 +- src/game.cpp | 55 +++++--- src/game.h | 4 +- 17 files changed, 272 insertions(+), 78 deletions(-) diff --git a/src/engine/boardinterface.h b/src/engine/boardinterface.h index bd6e1b39..813d2ef5 100644 --- a/src/engine/boardinterface.h +++ b/src/engine/boardinterface.h @@ -37,7 +37,7 @@ public: virtual ~BoardInterface(); // - virtual void setPlayerLists(std::vector >, PlayerList, PlayerList) =0; + virtual void setPlayerLists(std::vector >, PlayerList, 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 7f98a3a7..c2766bcf 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 > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0; + virtual HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, 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, unsigned dP, int sB) =0; diff --git a/src/engine/handinterface.h b/src/engine/handinterface.h index 04fb534f..63525152 100644 --- a/src/engine/handinterface.h +++ b/src/engine/handinterface.h @@ -40,6 +40,7 @@ public: virtual PlayerList getActivePlayerList() const =0; virtual PlayerList getRunningPlayerList() const =0; + virtual PlayerListIterator getSeatIt(unsigned) const =0; virtual PlayerListIterator getActivePlayerIt(unsigned) const =0; virtual PlayerListIterator getRunningPlayerIt(unsigned) const =0; diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 260462c6..82ab1e14 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -33,8 +33,9 @@ LocalBoard::~LocalBoard() { } -void LocalBoard::setPlayerLists(std::vector > sl, PlayerList apl, PlayerList rpl) { - playerArray = sl; +void LocalBoard::setPlayerLists(std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl) { + playerArray = sl_old; // delete + seatsList = sl; activePlayerList = apl; runningPlayerList = rpl; } @@ -44,32 +45,57 @@ void LocalBoard::setHand(HandInterface* br) { currentHand = br; } void LocalBoard::collectSets() { sets = 0; - int i; - for(i=0; igetMySet(); +// int i; +// for(i=0; igetMySet(); //delete + + PlayerListConstIterator it_c; + for(it_c=seatsList->begin(); it_c!=seatsList->end(); it_c++) { + sets += (*it_c)->getMySet(); + } + } void LocalBoard::collectPot() { - int i; +// int i; pot += sets; sets = 0; - for(i=0; isetMySetNull(); } +// for(i=0; isetMySetNull(); } + + PlayerListIterator it; + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + (*it)->setMySetNull(); + } + } void LocalBoard::distributePot() { size_t i,j,k,l; + PlayerListIterator it; + PlayerListConstIterator it_c; + + // filling player sets vector +// vector playerSets; +// for(i=0; i<(size_t)MAX_NUMBER_OF_PLAYERS; i++) { +// if(playerArray[i]->getMyActiveStatus()) { +// playerSets.push_back(((playerArray[i]->getMyRoundStartCash())-(playerArray[i]->getMyCash()))); +// } else { +// playerSets.push_back(0); +// } +// } // filling player sets vector vector playerSets; - for(i=0; i<(size_t)MAX_NUMBER_OF_PLAYERS; i++) { - if(playerArray[i]->getMyActiveStatus()) { - playerSets.push_back(((playerArray[i]->getMyRoundStartCash())-(playerArray[i]->getMyCash()))); + for(it_c=seatsList->begin(); it_c!=seatsList->end(); it_c++) { + if((*it_c)->getMyActiveStatus()) { + playerSets.push_back( ( ((*it_c)->getMyRoundStartCash()) - ((*it_c)->getMyCash()) ) ); } else { playerSets.push_back(0); } } + // sort player sets asc vector playerSetsSort = playerSets; sort(playerSetsSort.begin(), playerSetsSort.end()); @@ -100,29 +126,51 @@ void LocalBoard::distributePot() { potLevel.push_back((playerSetsSort.size()-i)*potLevel[0]); // determine level highestCardsValue - for(j=0; jgetMyCardsValueInt() > highestCardsValue && playerArray[j]->getMyActiveStatus() && playerArray[j]->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { +// highestCardsValue = playerArray[j]->getMyCardsValueInt(); +// } +// } - if(playerArray[j]->getMyCardsValueInt() > highestCardsValue && playerArray[j]->getMyActiveStatus() && playerArray[j]->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { - highestCardsValue = playerArray[j]->getMyCardsValueInt(); + // determine level highestCardsValue + j=0; + for(it_c=seatsList->begin(); it_c!=seatsList->end(); it_c++,j++) { + if((*it_c)->getMyActiveStatus() && (*it_c)->getMyCardsValueInt() > highestCardsValue && (*it_c)->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { + highestCardsValue = (*it_c)->getMyCardsValueInt(); } } // level winners - for(j=0; jgetMyCardsValueInt() && playerArray[j]->getMyActiveStatus() && playerArray[j]->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { - potLevel.push_back(playerArray[j]->getMyID()); +// for(j=0; jgetMyCardsValueInt() && playerArray[j]->getMyActiveStatus() && playerArray[j]->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { +// potLevel.push_back(playerArray[j]->getMyID()); +// } +// } + + // level winners + j=0; + for(it_c=seatsList->begin(); it_c!=seatsList->end(); it_c++,j++) { + if((*it_c)->getMyActiveStatus() && highestCardsValue == (*it_c)->getMyCardsValueInt() && (*it_c)->getMyAction() != PLAYER_ACTION_FOLD && playerSets[j] >= potLevel[0]) { + potLevel.push_back((*it_c)->getMyUniqueID()); } } // determine the number of level winners winnerCount = potLevel.size()-2; + assert(winnerCount); // distribute the pot level sum to level winners mod = (potLevel[1])%winnerCount; // pot level sum divisible by winnerCount if(mod == 0) { +// for(j=2; jsetMyCash(playerArray[potLevel[j]]->getMyCash() + ((potLevel[1])/winnerCount)); +// } + for(j=2; jsetMyCash(playerArray[potLevel[j]]->getMyCash() + ((potLevel[1])/winnerCount)); + it = currentHand->getSeatIt(potLevel[j]); + assert(it != seatsList->end()); + (*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount)); } } @@ -148,10 +196,19 @@ void LocalBoard::distributePot() { } +// if(jsetMyCash(playerArray[winnerPointer]->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); +// } else { +// playerArray[winnerPointer]->setMyCash(playerArray[winnerPointer]->getMyCash() + (int)((potLevel[1])/winnerCount)); +// } + + + it = currentHand->getSeatIt(winnerPointer); + assert(it != seatsList->end()); if(jsetMyCash(playerArray[winnerPointer]->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); + (*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); } else { - playerArray[winnerPointer]->setMyCash(playerArray[winnerPointer]->getMyCash() + (int)((potLevel[1])/winnerCount)); + (*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount)); } } } @@ -181,11 +238,16 @@ void LocalBoard::distributePot() { if(pot!=0) cout << "distributePot-ERROR: Pot = " << pot << endl; int sum = 0; - for(i=0; i<(size_t)MAX_NUMBER_OF_PLAYERS; i++) { - if(playerArray[i]->getMyActiveStatus()) - sum += playerArray[i]->getMyCash(); +// for(i=0; i<(size_t)MAX_NUMBER_OF_PLAYERS; i++) { +// if(playerArray[i]->getMyActiveStatus()) +// sum += playerArray[i]->getMyCash(); +// } + + for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) { + sum += (*it_c)->getMyCash(); } + if(sum != (currentHand->getStartQuantityPlayers() * currentHand->getStartCash())) cout << "distributePot-ERROR: PlayersSumCash = " << sum << endl; diff --git a/src/engine/local_engine/localboard.h b/src/engine/local_engine/localboard.h index 62d34e3a..93c1ef7f 100755 --- a/src/engine/local_engine/localboard.h +++ b/src/engine/local_engine/localboard.h @@ -35,7 +35,7 @@ public: LocalBoard(); ~LocalBoard(); - void setPlayerLists(std::vector >, PlayerList, PlayerList); + void setPlayerLists(std::vector >, PlayerList, PlayerList, PlayerList); void setHand(HandInterface*); void setMyCards(int* theValue) { int i; for(i=0; i<5; i++) myCards[i] = theValue[i]; } @@ -53,7 +53,8 @@ public: private: - std::vector > playerArray; + std::vector > playerArray; // delete + PlayerList seatsList; PlayerList activePlayerList; PlayerList runningPlayerList; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index 8916e1f4..5cc52371 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 > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) { return new LocalHand(f, g, b, sl, apl, rpl, id, sP, dP, sB, sC); } +HandInterface* LocalEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) { return new LocalHand(f, g, b, sl_old, sl, apl, rpl, id, sP, 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 74aa07d8..16ac3e91 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 > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); + HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, 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, unsigned dP, int sB); diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 102dea9d..0fe81f2c 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -26,22 +26,29 @@ using namespace std; -LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(false), +LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC) +: myFactory(f), myGui(g), myBoard(b), playerArray(sl_old), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(false), cardsShown(false), bettingRoundsPlayed(0) { int i, j, k; + PlayerListIterator it; PlayerListConstIterator it_c; CardsValue myCardsValue; myBoard->setHand(this); - for(i=0; isetHand(this); +// for(i=0; isetHand(this); +// // myFlipCards auf 0 setzen +// playerArray[i]->setMyCardsFlip(0, 0); +// } + + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + (*it)->setHand(this); // myFlipCards auf 0 setzen - playerArray[i]->setMyCardsFlip(0, 0); + (*it)->setMyCardsFlip(0, 0); } @@ -286,36 +293,98 @@ void LocalHand::start() { void LocalHand::assignButtons() { int i,j; + PlayerListIterator it; PlayerListConstIterator it_c; // alle Buttons loeschen - for (i=0; isetMyButton(0); } +// for (i=0; isetMyButton(0); } + + // alle Buttons loeschen + for (it=seatsList->begin(); it!=seatsList->end(); it++) { + (*it)->setMyButton(BUTTON_NONE); + } // DealerButton zuweisen - playerArray[dealerPosition]->setMyButton(1); +// playerArray[dealerPosition]->setMyButton(1); + + // DealerButton zuweisen + it = getSeatIt(dealerPosition); + assert(it != seatsList->end() ); + (*it)->setMyButton(BUTTON_DEALER); + // assign Small Blind next to dealer. ATTENTION: in heads up it is big blind - i = dealerPosition; +// i = dealerPosition; +// +// for(j=0; (jgetMyActiveStatus())) || j==0; j++) { +// +// i = (i+1)%(MAX_NUMBER_OF_PLAYERS); +// if(playerArray[i]->getMyActiveStatus()) { +// if(activePlayerList->size() > 2) playerArray[i]->setMyButton(2); //small blind normal +// else playerArray[i]->setMyButton(3); //big blind in heads up +// } +// } - for(j=0; (jgetMyActiveStatus())) || j==0; j++) { - - i = (i+1)%(MAX_NUMBER_OF_PLAYERS); - if(playerArray[i]->getMyActiveStatus()) { - if(activePlayerList->size() > 2) playerArray[i]->setMyButton(2); //small blind normal - else playerArray[i]->setMyButton(3); //big blind in heads up - } - } // assign big blind next to small blind. ATTENTION: in heads up it is small blind - for(j=0; (jgetMyActiveStatus())) || j==0; j++) { +// for(j=0; (jgetMyActiveStatus())) || j==0; j++) { +// +// i = (i+1)%(MAX_NUMBER_OF_PLAYERS); +// if(playerArray[i]->getMyActiveStatus()) { +// if(activePlayerList->size() > 2) playerArray[i]->setMyButton(3); //big blind normal +// else playerArray[i]->setMyButton(2); //small blind in heads up +// +// } +// } - i = (i+1)%(MAX_NUMBER_OF_PLAYERS); - if(playerArray[i]->getMyActiveStatus()) { - if(activePlayerList->size() > 2) playerArray[i]->setMyButton(3); //big blind normal - else playerArray[i]->setMyButton(2); //small blind in heads up - + + + // assign Small Blind next to dealer. ATTENTION: in heads up it is big blind + // assign big blind next to small blind. ATTENTION: in heads up it is small blind + bool nextActivePlayerFound = false; + PlayerListIterator dealerPositionIt = getSeatIt(dealerPosition); + assert( dealerPositionIt != seatsList->end() ); + + for(i=0; isize(); i++) { + + dealerPositionIt++; + if(dealerPositionIt == seatsList->end()) dealerPositionIt = seatsList->begin(); + + it = getActivePlayerIt( (*dealerPositionIt)->getMyUniqueID() ); + if(it != activePlayerList->end() ) { + nextActivePlayerFound = true; + if(activePlayerList->size() > 2) (*it)->setMyButton(2); //small blind normal + else (*it)->setMyButton(3); //big blind in heads up + + it++; + if(it == activePlayerList->end()) it = activePlayerList->begin(); + + if(activePlayerList->size() > 2) (*it)->setMyButton(3); //big blind normal + else (*it)->setMyButton(2); //small blind in heads up + + break; } + } + assert(nextActivePlayerFound); + + + + + + + + + + + + + + + + + + //do sets --> TODO switch? for (it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); it_c++) { @@ -504,6 +573,20 @@ void LocalHand::switchRounds() { } +PlayerListIterator LocalHand::getSeatIt(unsigned uniqueId) const { + + PlayerListIterator it; + + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + if((*it)->getMyUniqueID() == uniqueId) { + break; + } + } + + return it; + +} + PlayerListIterator LocalHand::getActivePlayerIt(unsigned uniqueId) const { PlayerListIterator it; diff --git a/src/engine/local_engine/localhand.h b/src/engine/local_engine/localhand.h index cddc6b19..1e53dd0b 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 >, PlayerList, PlayerList, int, int, unsigned, int, int); + LocalHand(boost::shared_ptr f, GuiInterface*, BoardInterface*, std::vector >, PlayerList, PlayerList, PlayerList, int, int, unsigned, int, int); ~LocalHand(); void start(); @@ -43,6 +43,7 @@ public: PlayerList getActivePlayerList() const {return activePlayerList;} PlayerList getRunningPlayerList() const {return runningPlayerList;} + PlayerListIterator getSeatIt(unsigned) const; PlayerListIterator getActivePlayerIt(unsigned) const; PlayerListIterator getRunningPlayerIt(unsigned) const; @@ -95,7 +96,8 @@ private: GuiInterface *myGui; BoardInterface *myBoard; - std::vector > playerArray; + std::vector > playerArray; // delete + PlayerList seatsList; PlayerList activePlayerList; PlayerList runningPlayerList; diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index c7001438..c547ec99 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -34,10 +34,11 @@ ClientBoard::~ClientBoard() } void -ClientBoard::setPlayerLists(std::vector > sl, PlayerList apl, PlayerList rpl) +ClientBoard::setPlayerLists(std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - playerArray = sl; + playerArray = sl_old; // delete + seatsList = sl; activePlayerList = apl; runningPlayerList = rpl; } diff --git a/src/engine/network_engine/clientboard.h b/src/engine/network_engine/clientboard.h index 5fa412ff..e9166254 100644 --- a/src/engine/network_engine/clientboard.h +++ b/src/engine/network_engine/clientboard.h @@ -34,7 +34,7 @@ public: ClientBoard(); ~ClientBoard(); - void setPlayerLists(std::vector >, PlayerList, PlayerList); + void setPlayerLists(std::vector >, PlayerList, PlayerList, PlayerList); void setHand(HandInterface*); void setMyCards(int* theValue); @@ -53,7 +53,8 @@ public: private: mutable boost::recursive_mutex m_syncMutex; - std::vector > playerArray; + std::vector > playerArray; // delete + PlayerList seatsList; PlayerList activePlayerList; PlayerList runningPlayerList; diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index ff0de32e..a28ec48b 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 > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) +HandInterface* ClientEngineFactory::createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) { - return new ClientHand(f, g, b, sl, apl, rpl, id, sP, dP, sB, sC); + return new ClientHand(f, g, b, sl_old, sl, apl, rpl, id, sP, dP, sB, sC); } BoardInterface* ClientEngineFactory::createBoard() diff --git a/src/engine/network_engine/clientenginefactory.h b/src/engine/network_engine/clientenginefactory.h index 8e90fd72..8fdffb53 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 > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); + HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, 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, unsigned dP, int sB); diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index e90037bd..e7d468e2 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 > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), +ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) +: myFactory(f), myGui(g), myBoard(b), playerArray(sl_old), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(0), cardsShown(false), bettingRoundsPlayed(0) { @@ -76,6 +76,20 @@ ClientHand::getPlayerArray() const return playerArray; } +PlayerListIterator +ClientHand::getSeatIt(unsigned uniqueId) const +{ + PlayerListIterator it; + + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + if((*it)->getMyUniqueID() == uniqueId) { + break; + } + } + + return it; +} + PlayerListIterator ClientHand::getActivePlayerIt(unsigned uniqueId) const { diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index ff81f71e..07f69089 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 >, PlayerList, PlayerList , int, int, int, int, int ); + ClientHand ( boost::shared_ptr f, GuiInterface*, BoardInterface*, std::vector >, PlayerList, PlayerList, PlayerList , int, int, int, int, int ); ~ClientHand(); void start(); @@ -41,6 +41,7 @@ class ClientHand : public HandInterface PlayerList getActivePlayerList() const {return activePlayerList;} PlayerList getRunningPlayerList() const {return runningPlayerList;} + PlayerListIterator getSeatIt(unsigned) const; PlayerListIterator getActivePlayerIt(unsigned) const; PlayerListIterator getRunningPlayerIt(unsigned) const; @@ -95,7 +96,8 @@ class ClientHand : public HandInterface GuiInterface *myGui; BoardInterface *myBoard; - std::vector > playerArray; + std::vector > playerArray; // delete + PlayerList seatsList; PlayerList activePlayerList; PlayerList runningPlayerList; diff --git a/src/game.cpp b/src/game.cpp index c45d8ee1..ebffa814 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -68,7 +68,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, // Board erstellen actualBoard = myFactory->createBoard(); - + seatsList = PlayerList(new std::list >); activePlayerList = PlayerList(new std::list >); runningPlayerList = PlayerList(new std::list >); @@ -98,17 +98,21 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, // create Player Objects boost::shared_ptr tmpPlayer = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); + tmpPlayer->setNetSessionData(myNetSession); + // fill player lists - playerArray.push_back(tmpPlayer); + playerArray.push_back(tmpPlayer); // delete + seatsList->push_back(tmpPlayer); if(startQuantityPlayers > i) { activePlayerList->push_back(tmpPlayer); } (*runningPlayerList) = (*activePlayerList); - playerArray[i]->setNetSessionData(myNetSession); + playerArray[i]->setNetSessionData(myNetSession); // delete + } - actualBoard->setPlayerLists(playerArray, activePlayerList, runningPlayerList); + actualBoard->setPlayerLists(playerArray, seatsList, activePlayerList, runningPlayerList); // delete playerArray } Game::~Game() @@ -135,7 +139,7 @@ const HandInterface *Game::getCurrentHand() const void Game::initHand() { - int i; + size_t i; PlayerListConstIterator it_c; // eventuell vorhandene Hand löschen @@ -177,14 +181,36 @@ void Game::initHand() (*runningPlayerList) = (*activePlayerList); // Hand erstellen - actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, activePlayerList, runningPlayerList, actualHandID, startQuantityPlayers, dealerPosition, actualSmallBlind, startCash); + actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, seatsList, activePlayerList, runningPlayerList, actualHandID, startQuantityPlayers, dealerPosition, actualSmallBlind, startCash); // delete playerArray + // Dealer-Button weiterschieben --> Achtung inactive -> TODO exception-rule !!! DELETE +// for(i=0; (igetMyActiveStatus())) || i==0; i++) { +// +// dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS); +// } + // Dealer-Button weiterschieben --> Achtung inactive -> TODO exception-rule !!! - for(i=0; (igetMyActiveStatus())) || i==0; i++) { - - dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS); + bool nextDealerFound = false; + PlayerListConstIterator dealerPositionIt = actualHand->getSeatIt(dealerPosition); + assert( dealerPositionIt != seatsList->end() ); + + for(i=0; isize(); i++) { + + dealerPositionIt++; + if(dealerPositionIt == seatsList->end()) dealerPositionIt = seatsList->begin(); + + it = actualHand->getActivePlayerIt( (*dealerPositionIt)->getMyUniqueID() ); + if(it != activePlayerList->end() ) { + nextDealerFound = true; + dealerPosition = (*it)->getMyUniqueID(); + break; + } + } + assert(nextDealerFound); + + } void Game::startHand() @@ -201,6 +227,7 @@ void Game::startHand() boost::shared_ptr Game::getPlayerByUniqueId(unsigned id) { + // TODO playerLists boost::shared_ptr tmpPlayer; for (int i = 0; i < startQuantityPlayers; i++) { @@ -215,11 +242,9 @@ boost::shared_ptr Game::getPlayerByUniqueId(unsigned id) boost::shared_ptr Game::getCurrentPlayer() { -// int curPlayerNum = getCurrentHand()->getCurrentBeRo()->getPlayersTurn(); -// assert(curPlayerNum < getStartQuantityPlayers()); -// return getPlayerArray()[curPlayerNum]; - - // TODO -> checking - return (*(getCurrentHand()->getCurrentBeRo()->getCurrentPlayersTurnIt())); + // TODO playerLists + int curPlayerNum = getCurrentHand()->getCurrentBeRo()->getPlayersTurn(); + assert(curPlayerNum < getStartQuantityPlayers()); + return getPlayerArray()[curPlayerNum]; } diff --git a/src/game.h b/src/game.h index af1d3d3a..4134829c 100755 --- a/src/game.h +++ b/src/game.h @@ -55,6 +55,7 @@ public: const HandInterface *getCurrentHand() const; std::vector > getPlayerArray() const {return playerArray;} + PlayerList getSeatsList() const {return seatsList;} PlayerList getActivePlayerList() const {return activePlayerList;} PlayerList getRunningPlayerList() const {return runningPlayerList;} @@ -86,7 +87,8 @@ private: HandInterface *actualHand; BoardInterface *actualBoard; - std::vector > playerArray; // available seats --> seatList !!! TODO + std::vector > playerArray; // available seats --> seatList !!! TODO // delete + PlayerList seatsList; PlayerList activePlayerList; // used seats PlayerList runningPlayerList; // nonfolded and nonallin active players