From 78bf4820af4028e0b5a31e37dd3054aee6de03aa Mon Sep 17 00:00:00 2001 From: lotodore Date: Thu, 27 Sep 2007 14:17:07 +0000 Subject: [PATCH] Changed network code for new player lists. --- src/engine/local_engine/localhand.cpp | 20 ++-- src/engine/network_engine/clientbero.cpp | 12 ++ src/engine/network_engine/clienthand.cpp | 59 ++++++---- src/engine/network_engine/clienthand.h | 1 - src/game.cpp | 27 ++--- src/net/clientstate.h | 5 +- src/net/common/clientstate.cpp | 137 +++++------------------ src/net/common/clientthread.cpp | 5 +- src/net/common/servergamestate.cpp | 103 +++++++++-------- src/net/common/servergamethread.cpp | 9 +- src/net/servergamestate.h | 2 - 11 files changed, 160 insertions(+), 220 deletions(-) diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index baff278a..451a7af4 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -33,7 +33,6 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI int i, j, k; PlayerListIterator it; - PlayerListConstIterator it_c; CardsValue myCardsValue; @@ -72,19 +71,19 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI k = 0; myBoard->setMyCards(tempBoardArray); - for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++, k++) { + for(it=activePlayerList->begin(); it!=activePlayerList->end(); it++, k++) { - (*it_c)->getMyBestHandPosition(bestHandPos); + (*it)->getMyBestHandPosition(bestHandPos); for(j=0; j<2; j++) { tempPlayerArray[j] = cardsArray[2*k+j+5]; tempPlayerAndBoardArray[j] = cardsArray[2*k+j+5]; } - (*it_c)->setMyCards(tempPlayerArray); - (*it_c)->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray, bestHandPos)); - (*it_c)->setMyBestHandPosition(bestHandPos); - (*it_c)->setMyRoundStartCash((*it_c)->getMyCash()); + (*it)->setMyCards(tempPlayerArray); + (*it)->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray, bestHandPos)); + (*it)->setMyBestHandPosition(bestHandPos); + (*it)->setMyRoundStartCash((*it)->getMyCash()); // myBestHandPosition auf Fehler ueberpruefen for(j=0; j<5; j++) { @@ -94,10 +93,10 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI } // sBluff für alle aktiver Spieler außer human player setzen --> TODO for ai-player in internet - if((*it_c)->getMyID() != 0) { + if((*it)->getMyID() != 0) { Tools::getRandNumber(1,100,1,&sBluff,0); - (*it_c)->setSBluff(sBluff); - (*it_c)->setSBluffStatus(0); + (*it)->setSBluff(sBluff); + (*it)->setSBluffStatus(0); } } @@ -432,7 +431,6 @@ void LocalHand::switchRounds() { // cout << "playerID begin switchRounds(): " << getCurrentBeRo()->get - int i; PlayerListIterator it, it_1; PlayerListConstIterator it_c; diff --git a/src/engine/network_engine/clientbero.cpp b/src/engine/network_engine/clientbero.cpp index 2b446f29..e3e60608 100644 --- a/src/engine/network_engine/clientbero.cpp +++ b/src/engine/network_engine/clientbero.cpp @@ -44,12 +44,14 @@ ClientBeRo::setHighestCardsValue(int theValue) void ClientBeRo::setLastActionPlayer ( int theValue ) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); lastActionPlayer = theValue; } int ClientBeRo::getLastActionPlayer() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return lastActionPlayer; } @@ -70,48 +72,56 @@ ClientBeRo::getPlayersTurn() const void ClientBeRo::setCurrentPlayersTurnIt(PlayerListIterator theValue) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); currentPlayersTurnIt = theValue; } PlayerListIterator ClientBeRo::getCurrentPlayersTurnIt() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return currentPlayersTurnIt; } void ClientBeRo::setLastPlayersTurnIt(PlayerListIterator theValue) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); lastPlayersTurnIt = theValue; } PlayerListIterator ClientBeRo::getLastPlayersTurnIt() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return lastPlayersTurnIt; } void ClientBeRo::setCurrentPlayersTurnId(unsigned theValue) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); currentPlayersTurnId = theValue; } unsigned ClientBeRo::getCurrentPlayersTurnId() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return currentPlayersTurnId; } void ClientBeRo::setFirstRoundLastPlayersTurnId(unsigned theValue) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); firstRoundLastPlayersTurnId = theValue; } unsigned ClientBeRo::getFirstRoundLastPlayersTurnId() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return firstRoundLastPlayersTurnId; } @@ -174,12 +184,14 @@ ClientBeRo::getSmallBlind() const void ClientBeRo::setMinimumRaise ( int theValue ) { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); minimumRaise = theValue; } int ClientBeRo::getMinimumRaise() const { + boost::recursive_mutex::scoped_lock lock(m_syncMutex); return minimumRaise; } diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index e7d468e2..7f609f3f 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -26,32 +26,29 @@ ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, Boar smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(0), cardsShown(false), bettingRoundsPlayed(0) { - activePlayersCounter = activePlayerList->size(); - - int i; - lastPlayersTurn = 0; + PlayerListIterator it; myBoard->setHand(this); - - for(i=0; isetHand(this); + for(it=seatsList->begin(); it!=seatsList->end(); it++) { + (*it)->setHand(this); // myFlipCards auf 0 setzen - playerArray[i]->setMyCardsFlip(0, 0); + (*it)->setMyCardsFlip(0, 0); } - // roundStartCashArray fuellen // cardsvalue zuruecksetzen // remove all buttons - for(i=0; isetMyRoundStartCash(playerArray[i]->getMyCash()); - playerArray[i]->setMyCardsValueInt(0); - playerArray[i]->setMyButton(0); - } + for(it=activePlayerList->begin(); it!=activePlayerList->end(); it++) { - // assign dealer button - playerArray[dealerPosition]->setMyButton(1); + boost::shared_ptr tmpPlayer = *it; + + tmpPlayer->setMyRoundStartCash(tmpPlayer->getMyCash()); + tmpPlayer->setMyCardsValueInt(0); + tmpPlayer->setMyButton(0); + if (tmpPlayer->getMyUniqueID() == dealerPosition) + tmpPlayer->setMyButton(1); + } // the rest of the buttons are assigned later as received from the server. @@ -127,25 +124,25 @@ ClientHand::getBoard() const boost::shared_ptr ClientHand::getPreflop() const { - return myBeRo[actualRound]; + return myBeRo[GAME_STATE_PREFLOP]; } boost::shared_ptr ClientHand::getFlop() const { - return myBeRo[actualRound]; + return myBeRo[GAME_STATE_FLOP]; } boost::shared_ptr ClientHand::getTurn() const { - return myBeRo[actualRound]; + return myBeRo[GAME_STATE_TURN]; } boost::shared_ptr ClientHand::getRiver() const { - return myBeRo[actualRound]; + return myBeRo[GAME_STATE_RIVER]; } boost::shared_ptr @@ -305,10 +302,24 @@ void ClientHand::switchRounds() { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - // update active players counter. - activePlayersCounter = 0; - for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) { - if (playerArray[i]->getMyAction() != 1 && playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++; + + PlayerListIterator it, it_1; + + // refresh runningPlayerList + for(it=runningPlayerList->begin(); it!=runningPlayerList->end(); ) { + if((*it)->getMyAction() == PLAYER_ACTION_FOLD || (*it)->getMyAction() == PLAYER_ACTION_ALLIN) { + it = runningPlayerList->erase(it); + if(!(runningPlayerList->empty())) { + + it_1 = it; + if(it_1 == runningPlayerList->begin()) it_1 = runningPlayerList->end(); + it_1--; + getCurrentBeRo()->setCurrentPlayersTurnId((*it_1)->getMyUniqueID()); + + } + } else { + it++; + } } } diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index 07f69089..cac0fc61 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -109,7 +109,6 @@ class ClientHand : public HandInterface int actualRound; //0 = preflop, 1 = flop, 2 = turn, 3 = river int smallBlind; int startCash; - int activePlayersCounter; int lastPlayersTurn; diff --git a/src/game.cpp b/src/game.cpp index ebffa814..ec9cf254 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -50,20 +50,14 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, PlayerDataList::const_iterator player_i = playerDataList.begin(); PlayerDataList::const_iterator player_end = playerDataList.end(); - bool dealerFound = false; - i = 0; while (player_i != player_end) { if ((*player_i)->GetUniqueId() == startData.startDealerPlayerId) - { - dealerPosition = i; - dealerFound = true; break; - } ++player_i; - ++i; } - assert(dealerFound); + assert(player_i != player_end); + dealerPosition = startData.startDealerPlayerId; // Board erstellen actualBoard = myFactory->createBoard(); @@ -227,24 +221,25 @@ void Game::startHand() boost::shared_ptr Game::getPlayerByUniqueId(unsigned id) { - // TODO playerLists boost::shared_ptr tmpPlayer; - for (int i = 0; i < startQuantityPlayers; i++) + PlayerListIterator i = getSeatsList()->begin(); + PlayerListIterator end = getSeatsList()->end(); + while (i != end) { - if (playerArray[i]->getMyUniqueID() == id) + if ((*i)->getMyUniqueID() == id) { - tmpPlayer = playerArray[i]; + tmpPlayer = *i; break; } + ++i; } return tmpPlayer; } boost::shared_ptr Game::getCurrentPlayer() { - // TODO playerLists - int curPlayerNum = getCurrentHand()->getCurrentBeRo()->getPlayersTurn(); - assert(curPlayerNum < getStartQuantityPlayers()); - return getPlayerArray()[curPlayerNum]; + boost::shared_ptr tmpPlayer = getPlayerByUniqueId(getCurrentHand()->getCurrentBeRo()->getCurrentPlayersTurnId()); + assert(tmpPlayer.get()); + return tmpPlayer; } diff --git a/src/net/clientstate.h b/src/net/clientstate.h index db2fc276..0a49ba43 100644 --- a/src/net/clientstate.h +++ b/src/net/clientstate.h @@ -267,11 +267,8 @@ protected: virtual int InternalProcess(ClientThread &client, boost::shared_ptr packet); - static int GetHighestSet(Game &curGame); - static void SetHighestSet(Game &curGame, int highestSet); - static int GetPlayersTurn(Game &curGame); - static void SetPlayersTurn(Game &curGame, int playersTurn); static void ResetPlayerActions(Game &curGame); + static void ResetPlayerSets(Game &curGame); }; // State: Final (just for testing, should not be used). diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index cda5fc19..0d599921 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -694,7 +694,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptrgetPlayerArray()[0]->setMyCards(myCards); + client.GetGame()->getSeatsList()->front()->setMyCards(myCards); client.GetGame()->initHand(); client.GetGame()->startHand(); client.GetGui().dealHoleCards(); @@ -780,8 +780,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->switchRounds(); // Update highest set - if (tmpPlayer->getMySet() > GetHighestSet(*curGame)) - SetHighestSet(*curGame, tmpPlayer->getMySet()); + if (tmpPlayer->getMySet() > curGame->getCurrentHand()->getCurrentBeRo()->getHighestSet()) + curGame->getCurrentHand()->getCurrentBeRo()->setHighestSet(tmpPlayer->getMySet()); // Stop the timeout for the player. client.GetGui().stopTimeoutAnimation(tmpPlayer->getMyID()); @@ -817,7 +817,9 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetMyID()); + curGame->getCurrentHand()->getCurrentBeRo()->setCurrentPlayersTurnId(tmpPlayer->getMyID()); + // TODO: remove this + curGame->getCurrentHand()->getCurrentBeRo()->setPlayersTurn(tmpPlayer->getMyID()); // Mark current player in GUI. int guiStatus = 2; @@ -910,8 +912,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->getBoard()->collectPot(); // Reset player sets - for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) - curGame->getPlayerArray()[i]->setMySetNull(); + ResetPlayerSets(*curGame); client.GetGui().refreshPot(); client.GetGui().refreshSet(); // Synchronize with GUI. @@ -939,8 +940,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->getBoard()->collectPot(); // Reset player sets - for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) - curGame->getPlayerArray()[i]->setMySetNull(); + ResetPlayerSets(*curGame); client.GetGui().refreshPot(); client.GetGui().refreshSet(); // Synchronize with GUI. @@ -994,113 +994,32 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetActualRound()) { - case GAME_STATE_PREFLOP: { - highestSet = curGame.getCurrentHand()->getPreflop()->getHighestSet(); - } break; - case GAME_STATE_FLOP: { - highestSet = curGame.getCurrentHand()->getFlop()->getHighestSet(); - } break; - case GAME_STATE_TURN: { - highestSet = curGame.getCurrentHand()->getTurn()->getHighestSet(); - } break; - case GAME_STATE_RIVER: { - highestSet = curGame.getCurrentHand()->getRiver()->getHighestSet(); - } break; - default: { - // - } - } - return highestSet; -} - -void -ClientStateRunHand::SetHighestSet(Game &curGame, int highestSet) -{ - // TODO: no switch needed here if game states are polymorphic - switch(curGame.getCurrentHand()->getActualRound()) { - case GAME_STATE_PREFLOP: { - curGame.getCurrentHand()->getPreflop()->setHighestSet(highestSet); - } break; - case GAME_STATE_FLOP: { - curGame.getCurrentHand()->getFlop()->setHighestSet(highestSet); - } break; - case GAME_STATE_TURN: { - curGame.getCurrentHand()->getTurn()->setHighestSet(highestSet); - } break; - case GAME_STATE_RIVER: { - curGame.getCurrentHand()->getRiver()->setHighestSet(highestSet); - } break; - default: { - // - } - } -} - -int -ClientStateRunHand::GetPlayersTurn(Game &curGame) -{ - int playersTurn = 0; - // TODO: no switch needed here if game states are polymorphic - switch(curGame.getCurrentHand()->getActualRound()) { - case GAME_STATE_PREFLOP: { - playersTurn = curGame.getCurrentHand()->getPreflop()->getPlayersTurn(); - } break; - case GAME_STATE_FLOP: { - playersTurn = curGame.getCurrentHand()->getFlop()->getPlayersTurn(); - } break; - case GAME_STATE_TURN: { - playersTurn = curGame.getCurrentHand()->getTurn()->getPlayersTurn(); - } break; - case GAME_STATE_RIVER: { - playersTurn = curGame.getCurrentHand()->getRiver()->getPlayersTurn(); - } break; - default: { - // - } - } - return playersTurn; -} - -void -ClientStateRunHand::SetPlayersTurn(Game &curGame, int playersTurn) -{ - // TODO: no switch needed here if game states are polymorphic - switch(curGame.getCurrentHand()->getActualRound()) { - case GAME_STATE_PREFLOP: { - curGame.getCurrentHand()->getPreflop()->setPlayersTurn(playersTurn); - } break; - case GAME_STATE_FLOP: { - curGame.getCurrentHand()->getFlop()->setPlayersTurn(playersTurn); - } break; - case GAME_STATE_TURN: { - curGame.getCurrentHand()->getTurn()->setPlayersTurn(playersTurn); - } break; - case GAME_STATE_RIVER: { - curGame.getCurrentHand()->getRiver()->setPlayersTurn(playersTurn); - } break; - default: { - // - } - } -} - void ClientStateRunHand::ResetPlayerActions(Game &curGame) { // Reset player actions - for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) + PlayerListIterator i = curGame.getSeatsList()->begin(); + PlayerListIterator end = curGame.getSeatsList()->end(); + + while (i != end) { - int action = curGame.getPlayerArray()[i]->getMyAction(); + int action = (*i)->getMyAction(); if (action != 1 && action != 6) - curGame.getPlayerArray()[i]->setMyAction(0); - curGame.getPlayerArray()[i]->setMySetNull(); + (*i)->setMyAction(0); + (*i)->setMySetNull(); + ++i; + } +} + +void +ClientStateRunHand::ResetPlayerSets(Game &curGame) +{ + PlayerListIterator i = curGame.getSeatsList()->begin(); + PlayerListIterator end = curGame.getSeatsList()->end(); + while (i != end) + { + (*i)->setMySetNull(); + ++i; } } diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 6597c78f..b06f652c 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -134,11 +134,12 @@ ClientThread::SendPlayerAction() // Create a network packet containing the current player action. boost::shared_ptr action(new NetPacketPlayersAction); NetPacketPlayersAction::Data actionData; + boost::shared_ptr myPlayer = GetGame()->getSeatsList()->front(); actionData.gameState = static_cast(GetGame()->getCurrentHand()->getActualRound()); - actionData.playerAction = static_cast(GetGame()->getPlayerArray()[0]->getMyAction()); + actionData.playerAction = static_cast(myPlayer->getMyAction()); // Only send last bet if not fold/checked. if (actionData.playerAction != PLAYER_ACTION_FOLD && actionData.playerAction != PLAYER_ACTION_CHECK) - actionData.playerBet = GetGame()->getPlayerArray()[0]->getMyLastRelativeSet(); + actionData.playerBet = myPlayer->getMyLastRelativeSet(); else actionData.playerBet = 0; try diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 426cd51b..78e36ba1 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -455,61 +455,75 @@ ServerGameStateStartHand::Process(ServerGameThread &server) curGame.getCurrentHand()->getTurn()->resetFirstRun(); curGame.getCurrentHand()->getRiver()->resetFirstRun(); - std::vector >playerArray = curGame.getPlayerArray(); + // Consider all players, even inactive. + PlayerListIterator i = curGame.getSeatsList()->begin(); + PlayerListIterator end = curGame.getSeatsList()->end(); // Send cards to all players. - for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) + while (i != end) { // also send to inactive players, but not to disconnected players. - if (playerArray[i]->getNetSessionData().get()) + boost::shared_ptr tmpPlayer = *i; + if (tmpPlayer->getNetSessionData().get()) { int cards[2]; - playerArray[i]->getMyCards(cards); + tmpPlayer->getMyCards(cards); boost::shared_ptr notifyCards(new NetPacketHandStart); NetPacketHandStart::Data handStartData; handStartData.yourCards[0] = static_cast(cards[0]); handStartData.yourCards[1] = static_cast(cards[1]); static_cast(notifyCards.get())->SetData(handStartData); - server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards); + server.GetSender().Send(tmpPlayer->getNetSessionData()->GetSocket(), notifyCards); } + ++i; } // Start hand. curGame.startHand(); // Auto small blind / big blind at the beginning of hand. - for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) + i = curGame.getActivePlayerList()->begin(); + end = curGame.getActivePlayerList()->end(); + + while (i != end) { - if(playerArray[i]->getMyButton() == BUTTON_SMALL_BLIND) + boost::shared_ptr tmpPlayer = *i; + if (tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND) { boost::shared_ptr notifySmallBlind(new NetPacketPlayersActionDone); NetPacketPlayersActionDone::Data actionDoneData; actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND; - actionDoneData.playerId = playerArray[i]->getMyUniqueID(); - actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction(); - actionDoneData.totalPlayerBet = playerArray[i]->getMySet(); - actionDoneData.playerMoney = playerArray[i]->getMyCash(); + actionDoneData.playerId = tmpPlayer->getMyUniqueID(); + actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction(); + actionDoneData.totalPlayerBet = tmpPlayer->getMySet(); + actionDoneData.playerMoney = tmpPlayer->getMyCash(); static_cast(notifySmallBlind.get())->SetData(actionDoneData); server.SendToAllPlayers(notifySmallBlind, SessionData::Game); break; } + ++i; } - for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) + + i = curGame.getActivePlayerList()->begin(); + end = curGame.getActivePlayerList()->end(); + while (i != end) { - if(playerArray[i]->getMyButton() == BUTTON_BIG_BLIND) + boost::shared_ptr tmpPlayer = *i; + if (tmpPlayer->getMyButton() == BUTTON_BIG_BLIND) { boost::shared_ptr notifyBigBlind(new NetPacketPlayersActionDone); NetPacketPlayersActionDone::Data actionDoneData; actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND; - actionDoneData.playerId = playerArray[i]->getMyUniqueID(); - actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction(); - actionDoneData.totalPlayerBet = playerArray[i]->getMySet(); - actionDoneData.playerMoney = playerArray[i]->getMyCash(); + actionDoneData.playerId = tmpPlayer->getMyUniqueID(); + actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction(); + actionDoneData.totalPlayerBet = tmpPlayer->getMySet(); + actionDoneData.playerMoney = tmpPlayer->getMyCash(); static_cast(notifyBigBlind.get())->SetData(actionDoneData); server.SendToAllPlayers(notifyBigBlind, SessionData::Game); break; } + ++i; } server.SetState(ServerGameStateStartRound::Instance()); @@ -555,19 +569,19 @@ ServerGameStateStartRound::Process(ServerGameThread &server) if (newRound != curRound && newRound != GAME_STATE_POST_RIVER) { assert(newRound > curRound); - // Retrieve active players. If only one player is left, no cards are shown. - std::list > activePlayers = GetActivePlayers(curGame); + // Retrieve non-fold players. If only one player is left, no cards are shown. + PlayerList runningPlayers = curGame.getRunningPlayerList(); if (curGame.getCurrentHand()->getAllInCondition() && !curGame.getCurrentHand()->getCardsShown() - && activePlayers.size() > 1) + && runningPlayers->size() > 1) { // Send cards of all active players to all players (all in). boost::shared_ptr allIn(new NetPacketAllInShowCards); NetPacketAllInShowCards::Data allInData; - std::list >::iterator i = activePlayers.begin(); - std::list >::iterator end = activePlayers.end(); + PlayerListConstIterator i = runningPlayers->begin(); + PlayerListConstIterator end = runningPlayers->end(); while (i != end) { @@ -625,14 +639,14 @@ ServerGameStateStartRound::Process(ServerGameThread &server) // Engine will find out who won. curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun(); - // Retrieve active players. If only one player is left, no cards are shown. - std::list > activePlayers = GetActivePlayers(curGame); - // if (activePlayers.empty()) TODO throw exception + // Retrieve non-fold players. If only one player is left, no cards are shown. + PlayerList runningPlayers = curGame.getRunningPlayerList(); + // if (runningPlayers.empty()) TODO throw exception - if (activePlayers.size() == 1) + if (runningPlayers->size() == 1) { // End of Hand, but keep cards hidden. - boost::shared_ptr player = activePlayers.front(); + boost::shared_ptr player = runningPlayers->front(); boost::shared_ptr endHand(new NetPacketEndOfHandHideCards); NetPacketEndOfHandHideCards::Data endHandData; endHandData.playerId = player->getMyUniqueID(); @@ -648,8 +662,8 @@ ServerGameStateStartRound::Process(ServerGameThread &server) boost::shared_ptr endHand(new NetPacketEndOfHandShowCards); NetPacketEndOfHandShowCards::Data endHandData; - std::list >::iterator i = activePlayers.begin(); - std::list >::iterator end = activePlayers.end(); + PlayerListConstIterator i = runningPlayers->begin(); + PlayerListConstIterator end = runningPlayers->end(); while (i != end) { @@ -683,10 +697,15 @@ ServerGameStateStartRound::Process(ServerGameThread &server) // Start next hand - if enough players are left. int playersPositiveCashCounter = 0; - for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) + + PlayerListIterator i = curGame.getSeatsList()->begin(); + PlayerListIterator end = curGame.getSeatsList()->end(); + + while (i != end) { - if (curGame.getCurrentHand()->getPlayerArray()[i]->getMyCash() > 0) + if ((*i)->getMyCash() > 0) playersPositiveCashCounter++; + ++i; } if (!playersPositiveCashCounter) { @@ -710,21 +729,6 @@ ServerGameStateStartRound::Process(ServerGameThread &server) return retVal; } -std::list > -ServerGameStateStartRound::GetActivePlayers(Game &curGame) -{ - std::list > activePlayers; - for (int i = 0; i < curGame.getStartQuantityPlayers() ; i++) - { - if (curGame.getPlayerArray()[i]->getMyActiveStatus() - && curGame.getPlayerArray()[i]->getMyAction() != PLAYER_ACTION_FOLD) - { - activePlayers.push_back(curGame.getPlayerArray()[i]); - } - } - return activePlayers; -} - //----------------------------------------------------------------------------- boost::thread_specific_ptr ServerGameStateWaitPlayerAction::Ptr; @@ -1045,11 +1049,14 @@ ServerGameStateNextGameDelay::Process(ServerGameThread &server) Game &curGame = server.GetGame(); // The game has ended. Notify all clients. boost::shared_ptr winnerPlayer; - for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) + PlayerListIterator i = curGame.getActivePlayerList()->begin(); + PlayerListIterator end = curGame.getActivePlayerList()->end(); + while (i != end) { - winnerPlayer = curGame.getCurrentHand()->getPlayerArray()[i]; + winnerPlayer = *i; if (winnerPlayer->getMyCash() > 0) break; + ++i; } boost::shared_ptr endGame(new NetPacketEndOfGame); diff --git a/src/net/common/servergamethread.cpp b/src/net/common/servergamethread.cpp index 64da0ee1..a134cfc0 100644 --- a/src/net/common/servergamethread.cpp +++ b/src/net/common/servergamethread.cpp @@ -302,15 +302,18 @@ ServerGameThread::RemoveDisconnectedPlayers() // This should only be called between hands. if (m_game.get()) { - for (int i = 0; i < m_game->getStartQuantityPlayers(); i++) + PlayerListIterator i = m_game->getSeatsList()->begin(); + PlayerListIterator end = m_game->getSeatsList()->end(); + while (i != end) { - boost::shared_ptr tmpPlayer = m_game->getPlayerArray()[i]; + boost::shared_ptr tmpPlayer = *i; if (!GetSessionManager().IsPlayerConnected(tmpPlayer->getMyUniqueID()) && tmpPlayer->getMyType() == PLAYER_TYPE_HUMAN) { + // Setting player cash to 0 will deactivate the player. tmpPlayer->setMyCash(0); - tmpPlayer->setMyActiveStatus(false); tmpPlayer->setNetSessionData(boost::shared_ptr()); } + ++i; } } } diff --git a/src/net/servergamestate.h b/src/net/servergamestate.h index f66a55a4..43e7f85a 100644 --- a/src/net/servergamestate.h +++ b/src/net/servergamestate.h @@ -196,8 +196,6 @@ protected: // Protected constructor - this is a singleton. ServerGameStateStartRound(); - static std::list > GetActivePlayers(Game &curGame); - private: static boost::thread_specific_ptr Ptr;