diff --git a/src/engine/boardinterface.h b/src/engine/boardinterface.h index 7db82df1..e4acb12d 100644 --- a/src/engine/boardinterface.h +++ b/src/engine/boardinterface.h @@ -31,7 +31,6 @@ public: virtual ~BoardInterface(); // virtual void setPlayerLists(PlayerList, PlayerList, PlayerList) =0; - virtual void setHand(HandInterface*) =0; // virtual void setMyCards(int* theValue) =0; virtual void getMyCards(int* theValue) =0; @@ -40,6 +39,9 @@ public: virtual void setPot(int theValue) =0; virtual int getSets() const=0; virtual void setSets(int theValue) =0; + + virtual void setAllInCondition(bool theValue) =0; + virtual void setLastActionPlayer(unsigned theValue) =0; // virtual void collectSets() =0; virtual void collectPot() =0; diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index 3e1736db..0a7ee866 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -32,7 +32,7 @@ public: virtual ~EngineFactory(); virtual HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0; - virtual BoardInterface* createBoard() =0; + virtual BoardInterface* createBoard(unsigned dp) =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/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 692879ed..ca2647df 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -27,7 +27,7 @@ using namespace std; -LocalBoard::LocalBoard() : BoardInterface(), currentHand(0), pot(0), sets(0) +LocalBoard::LocalBoard(unsigned dp) : BoardInterface(), pot(0), sets(0), dealerPosition(dp), allInCondition(false) { myCards[0] = myCards[1] = myCards[2] = myCards[3] = myCards[4] = 0; } @@ -42,8 +42,6 @@ void LocalBoard::setPlayerLists(PlayerList sl, PlayerList apl, PlayerList rpl) { runningPlayerList = rpl; } -void LocalBoard::setHand(HandInterface* br) { currentHand = br; } - void LocalBoard::collectSets() { sets = 0; @@ -141,7 +139,12 @@ void LocalBoard::distributePot() { if(mod == 0) { for(j=2; jgetSeatIt(potLevel[j]); + // find seat with potLevel[j]-ID + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + if((*it)->getMyUniqueID() == potLevel[j]) { + break; + } + } if(it == seatsList->end()) { throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } @@ -158,8 +161,14 @@ void LocalBoard::distributePot() { else { // winnerPointer = currentHand->getDealerPosition(); - it = currentHand->getSeatIt(currentHand->getDealerPosition()); - if(it == seatsList->end()) { + + // find Seat with dealerPosition + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + if((*it)->getMyUniqueID() == dealerPosition) { + break; + } + } + if(it == seatsList->end()) { throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); } @@ -243,7 +252,7 @@ void LocalBoard::determinePlayerNeedToShowCards() { playerNeedToShowCards.clear(); // in All In Condition everybody have to show the cards - if(currentHand->getAllInCondition()) { + if(allInCondition) { PlayerListConstIterator it_c; @@ -288,7 +297,7 @@ void LocalBoard::determinePlayerNeedToShowCards() { // cout << "lAP-Ende: " << currentHand->getLastActionPlayer() << endl; // search lastActionPlayer for(it_c = activePlayerList->begin(); it_c != activePlayerList->end(); it_c++) { - if((*it_c)->getMyUniqueID() == currentHand->getLastActionPlayer() && (*it_c)->getMyAction() != PLAYER_ACTION_FOLD) { + if((*it_c)->getMyUniqueID() == lastActionPlayer && (*it_c)->getMyAction() != PLAYER_ACTION_FOLD) { lastActionPlayerIt = it_c; // cout << (*it_c)->getMyUniqueID() << endl; break; diff --git a/src/engine/local_engine/localboard.h b/src/engine/local_engine/localboard.h index 750b4f17..1367d35c 100755 --- a/src/engine/local_engine/localboard.h +++ b/src/engine/local_engine/localboard.h @@ -32,15 +32,17 @@ class HandInterface; class LocalBoard : public BoardInterface{ public: - LocalBoard(); + LocalBoard(unsigned dealerPosition); ~LocalBoard(); void setPlayerLists(PlayerList, PlayerList, PlayerList); - void setHand(HandInterface*); void setMyCards(int* theValue) { int i; for(i=0; i<5; i++) myCards[i] = theValue[i]; } void getMyCards(int* theValue) { int i; for(i=0; i<5; i++) theValue[i] = myCards[i]; } + void setAllInCondition(bool theValue) { allInCondition = theValue; } + void setLastActionPlayer(unsigned theValue) { lastActionPlayer = theValue; } + int getPot() const { return pot;} void setPot(int theValue) { pot = theValue;} int getSets() const { return sets; } @@ -64,14 +66,15 @@ private: PlayerList activePlayerList; PlayerList runningPlayerList; - HandInterface *currentHand; - std::list winners; - std::list playerNeedToShowCards; + std::list playerNeedToShowCards; int myCards[5]; int pot; int sets; + unsigned dealerPosition; + bool allInCondition; + unsigned lastActionPlayer; }; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index 5f229fae..e78575fd 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -48,7 +48,7 @@ LocalEngineFactory::createHand(boost::shared_ptr f, GuiInterface return new LocalHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC); } -BoardInterface* LocalEngineFactory::createBoard() { return new LocalBoard; } +BoardInterface* LocalEngineFactory::createBoard(unsigned dp) { return new LocalBoard(dp); } boost::shared_ptr LocalEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) { return boost::shared_ptr (new LocalPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB)); } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 765b3899..fc94194b 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -38,7 +38,7 @@ public: ~LocalEngineFactory(); HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); - BoardInterface* createBoard(); + BoardInterface* createBoard(unsigned dp); 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 e27a0d76..6ad8d215 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -40,8 +40,6 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI CardsValue myCardsValue; - myBoard->setHand(this); - for(it=seatsList->begin(); it!=seatsList->end(); it++) { (*it)->setHand(this); // set myFlipCards 0 @@ -439,6 +437,7 @@ void LocalHand::assignButtons() { // first player after dealer have to show his cards first (in showdown) lastActionPlayer = (*it)->getMyUniqueID(); + myBoard->setLastActionPlayer(lastActionPlayer); it++; if(it == activePlayerList->end()) it = activePlayerList->begin(); @@ -551,6 +550,7 @@ void LocalHand::switchRounds() { // 1) all players all in if(allInPlayersCounter == nonFoldPlayerCounter) { allInCondition = true; + myBoard->setAllInCondition(true); } // 2) all players but one all in and he has highest set @@ -560,6 +560,7 @@ void LocalHand::switchRounds() { if((*it_c)->getMySet() >= myBeRo[currentRound]->getHighestSet()) { allInCondition = true; + myBoard->setAllInCondition(true); } } @@ -578,14 +579,16 @@ void LocalHand::switchRounds() { } if( (*bigBlindIt_c)->getMySet() <= smallBlind && tempCounter == allInPlayersCounter) { allInCondition = true; + myBoard->setAllInCondition(true); } } // no.2: heads up -> detect player who is all in and bb but could set less than sb for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) { - if(activePlayerList->size()==2 && (*it_c)->getMyAction() == PLAYER_ACTION_ALLIN && (*it_c)->getMyButton()==BUTTON_BIG_BLIND && (*it_c)->getMySet()<=smallBlind && currentRound == GAME_STATE_PREFLOP) { - allInCondition = true; + if(activePlayerList->size()==2 && (*it_c)->getMyAction() == PLAYER_ACTION_ALLIN && (*it_c)->getMyButton()==BUTTON_BIG_BLIND && (*it_c)->getMySet()<=smallBlind && currentRound == GAME_STATE_PREFLOP) { + allInCondition = true; + myBoard->setAllInCondition(true); } } } @@ -694,3 +697,8 @@ PlayerListIterator LocalHand::getRunningPlayerIt(unsigned uniqueId) const { return it; } + +void LocalHand::setLastActionPlayer(unsigned theValue) { + lastActionPlayer = theValue; + myBoard->setLastActionPlayer(theValue); +} diff --git a/src/engine/local_engine/localhand.h b/src/engine/local_engine/localhand.h index b5c43a58..4d1fc4b2 100755 --- a/src/engine/local_engine/localhand.h +++ b/src/engine/local_engine/localhand.h @@ -81,7 +81,7 @@ public: void setLastPlayersTurn(int theValue) { lastPlayersTurn = theValue; } int getLastPlayersTurn() const { return lastPlayersTurn; } - void setLastActionPlayer ( unsigned theValue ) { lastActionPlayer = theValue; } + void setLastActionPlayer ( unsigned theValue ); unsigned getLastActionPlayer() const { return lastActionPlayer; } void setCardsShown(bool theValue) { cardsShown = theValue; } diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index 9dc882d2..36a24616 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -23,8 +23,8 @@ using namespace std; -ClientBoard::ClientBoard() -: currentHand(0), pot(0), sets(0) +ClientBoard::ClientBoard(unsigned dp) +: currentHand(0), pot(0), sets(0), dealerPosition(dp) { myCards[0] = myCards[1] = myCards[2] = myCards[3] = myCards[4] = 0; } @@ -94,6 +94,20 @@ ClientBoard::setSets(int theValue) sets = theValue; } +void +ClientBoard::setAllInCondition(bool theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + allInCondition = theValue; +} + +void +ClientBoard::setLastActionPlayer(unsigned theValue) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + lastActionPlayer = theValue; +} + void ClientBoard::collectSets() { diff --git a/src/engine/network_engine/clientboard.h b/src/engine/network_engine/clientboard.h index be80e2c5..c3aec2bd 100644 --- a/src/engine/network_engine/clientboard.h +++ b/src/engine/network_engine/clientboard.h @@ -31,7 +31,7 @@ class HandInterface; class ClientBoard : public BoardInterface { public: - ClientBoard(); + ClientBoard(unsigned dealerPosition); ~ClientBoard(); void setPlayerLists(PlayerList, PlayerList, PlayerList); @@ -45,6 +45,9 @@ public: int getSets() const; void setSets(int theValue); + void setAllInCondition(bool theValue); + void setLastActionPlayer(unsigned theValue); + void collectSets(); void collectPot(); @@ -72,6 +75,9 @@ private: int myCards[5]; int pot; int sets; + unsigned dealerPosition; + bool allInCondition; + unsigned lastActionPlayer; }; #endif diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index e1374cec..2d3dee28 100644 --- a/src/engine/network_engine/clientenginefactory.cpp +++ b/src/engine/network_engine/clientenginefactory.cpp @@ -40,9 +40,9 @@ HandInterface* ClientEngineFactory::createHand(boost::shared_ptr return new ClientHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC); } -BoardInterface* ClientEngineFactory::createBoard() +BoardInterface* ClientEngineFactory::createBoard(unsigned dp) { - return new ClientBoard; + return new ClientBoard(dp); } boost::shared_ptr ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) diff --git a/src/engine/network_engine/clientenginefactory.h b/src/engine/network_engine/clientenginefactory.h index b5e85d1d..82617ff3 100644 --- a/src/engine/network_engine/clientenginefactory.h +++ b/src/engine/network_engine/clientenginefactory.h @@ -39,7 +39,7 @@ public: ~ClientEngineFactory(); HandInterface* createHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); - BoardInterface* createBoard(); + BoardInterface* createBoard(unsigned dp); 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 5f36f497..aff57f87 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -28,8 +28,6 @@ ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, Boar { PlayerListIterator it; - myBoard->setHand(this); - for(it=seatsList->begin(); it!=seatsList->end(); it++) { (*it)->setHand(this); // myFlipCards auf 0 setzen diff --git a/src/game.cpp b/src/game.cpp index f5eb2380..6923c643 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -65,7 +65,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, throw LocalException(__FILE__, __LINE__, ERR_DEALER_NOT_FOUND); // create board - currentBoard = myFactory->createBoard(); + currentBoard = myFactory->createBoard(dealerPosition); // create player lists seatsList = PlayerList(new std::list >);