Changed network code for new player lists.
This commit is contained in:
@@ -33,7 +33,6 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardI
|
||||
|
||||
int i, j, k;
|
||||
PlayerListIterator it;
|
||||
PlayerListConstIterator it_c;
|
||||
|
||||
CardsValue myCardsValue;
|
||||
|
||||
@@ -72,19 +71,19 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> 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<EngineFactory> 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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,32 +26,29 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> 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; i<startQuantityPlayers; i++) {
|
||||
playerArray[i]->setHand(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; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
||||
playerArray[i]->setMyRoundStartCash(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<PlayerInterface> 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<BeRoInterface>
|
||||
ClientHand::getPreflop() const
|
||||
{
|
||||
return myBeRo[actualRound];
|
||||
return myBeRo[GAME_STATE_PREFLOP];
|
||||
}
|
||||
|
||||
boost::shared_ptr<BeRoInterface>
|
||||
ClientHand::getFlop() const
|
||||
{
|
||||
return myBeRo[actualRound];
|
||||
return myBeRo[GAME_STATE_FLOP];
|
||||
}
|
||||
|
||||
boost::shared_ptr<BeRoInterface>
|
||||
ClientHand::getTurn() const
|
||||
{
|
||||
return myBeRo[actualRound];
|
||||
return myBeRo[GAME_STATE_TURN];
|
||||
}
|
||||
|
||||
boost::shared_ptr<BeRoInterface>
|
||||
ClientHand::getRiver() const
|
||||
{
|
||||
return myBeRo[actualRound];
|
||||
return myBeRo[GAME_STATE_RIVER];
|
||||
}
|
||||
|
||||
boost::shared_ptr<BeRoInterface>
|
||||
@@ -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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+11
-16
@@ -50,20 +50,14 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> 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<PlayerInterface> Game::getPlayerByUniqueId(unsigned id)
|
||||
{
|
||||
// TODO playerLists
|
||||
boost::shared_ptr<PlayerInterface> 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<PlayerInterface> Game::getCurrentPlayer()
|
||||
{
|
||||
// TODO playerLists
|
||||
int curPlayerNum = getCurrentHand()->getCurrentBeRo()->getPlayersTurn();
|
||||
assert(curPlayerNum < getStartQuantityPlayers());
|
||||
return getPlayerArray()[curPlayerNum];
|
||||
boost::shared_ptr<PlayerInterface> tmpPlayer = getPlayerByUniqueId(getCurrentHand()->getCurrentBeRo()->getCurrentPlayersTurnId());
|
||||
assert(tmpPlayer.get());
|
||||
return tmpPlayer;
|
||||
}
|
||||
|
||||
|
||||
@@ -267,11 +267,8 @@ protected:
|
||||
|
||||
virtual int InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> 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).
|
||||
|
||||
+28
-109
@@ -694,7 +694,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
int myCards[2];
|
||||
myCards[0] = (int)tmpData.yourCards[0];
|
||||
myCards[1] = (int)tmpData.yourCards[1];
|
||||
client.GetGame()->getPlayerArray()[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_ptr<NetP
|
||||
curGame->getCurrentHand()->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_ptr<NetP
|
||||
}
|
||||
|
||||
// Next player's turn.
|
||||
SetPlayersTurn(*curGame, tmpPlayer->getMyID());
|
||||
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_ptr<NetP
|
||||
{
|
||||
curGame->getCurrentHand()->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_ptr<NetP
|
||||
{
|
||||
curGame->getCurrentHand()->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_ptr<NetP
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ClientStateRunHand::GetHighestSet(Game &curGame)
|
||||
{
|
||||
int highestSet = 0;
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(curGame.getCurrentHand()->getActualRound()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,11 +134,12 @@ ClientThread::SendPlayerAction()
|
||||
// Create a network packet containing the current player action.
|
||||
boost::shared_ptr<NetPacket> action(new NetPacketPlayersAction);
|
||||
NetPacketPlayersAction::Data actionData;
|
||||
boost::shared_ptr<PlayerInterface> myPlayer = GetGame()->getSeatsList()->front();
|
||||
actionData.gameState = static_cast<GameState>(GetGame()->getCurrentHand()->getActualRound());
|
||||
actionData.playerAction = static_cast<PlayerAction>(GetGame()->getPlayerArray()[0]->getMyAction());
|
||||
actionData.playerAction = static_cast<PlayerAction>(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
|
||||
|
||||
@@ -455,61 +455,75 @@ ServerGameStateStartHand::Process(ServerGameThread &server)
|
||||
curGame.getCurrentHand()->getTurn()->resetFirstRun();
|
||||
curGame.getCurrentHand()->getRiver()->resetFirstRun();
|
||||
|
||||
std::vector<boost::shared_ptr<PlayerInterface> >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<PlayerInterface> tmpPlayer = *i;
|
||||
if (tmpPlayer->getNetSessionData().get())
|
||||
{
|
||||
int cards[2];
|
||||
playerArray[i]->getMyCards(cards);
|
||||
tmpPlayer->getMyCards(cards);
|
||||
boost::shared_ptr<NetPacket> notifyCards(new NetPacketHandStart);
|
||||
NetPacketHandStart::Data handStartData;
|
||||
handStartData.yourCards[0] = static_cast<unsigned>(cards[0]);
|
||||
handStartData.yourCards[1] = static_cast<unsigned>(cards[1]);
|
||||
static_cast<NetPacketHandStart *>(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<PlayerInterface> tmpPlayer = *i;
|
||||
if (tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> 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<NetPacketPlayersActionDone *>(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<PlayerInterface> tmpPlayer = *i;
|
||||
if (tmpPlayer->getMyButton() == BUTTON_BIG_BLIND)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> 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<NetPacketPlayersActionDone *>(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<boost::shared_ptr<PlayerInterface> > 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<NetPacket> allIn(new NetPacketAllInShowCards);
|
||||
NetPacketAllInShowCards::Data allInData;
|
||||
|
||||
std::list<boost::shared_ptr<PlayerInterface> >::iterator i = activePlayers.begin();
|
||||
std::list<boost::shared_ptr<PlayerInterface> >::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<boost::shared_ptr<PlayerInterface> > 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<PlayerInterface> player = activePlayers.front();
|
||||
boost::shared_ptr<PlayerInterface> player = runningPlayers->front();
|
||||
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandHideCards);
|
||||
NetPacketEndOfHandHideCards::Data endHandData;
|
||||
endHandData.playerId = player->getMyUniqueID();
|
||||
@@ -648,8 +662,8 @@ ServerGameStateStartRound::Process(ServerGameThread &server)
|
||||
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandShowCards);
|
||||
NetPacketEndOfHandShowCards::Data endHandData;
|
||||
|
||||
std::list<boost::shared_ptr<PlayerInterface> >::iterator i = activePlayers.begin();
|
||||
std::list<boost::shared_ptr<PlayerInterface> >::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<boost::shared_ptr<PlayerInterface> >
|
||||
ServerGameStateStartRound::GetActivePlayers(Game &curGame)
|
||||
{
|
||||
std::list<boost::shared_ptr<PlayerInterface> > 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> ServerGameStateWaitPlayerAction::Ptr;
|
||||
@@ -1045,11 +1049,14 @@ ServerGameStateNextGameDelay::Process(ServerGameThread &server)
|
||||
Game &curGame = server.GetGame();
|
||||
// The game has ended. Notify all clients.
|
||||
boost::shared_ptr<PlayerInterface> 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<NetPacket> endGame(new NetPacketEndOfGame);
|
||||
|
||||
@@ -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<PlayerInterface> tmpPlayer = m_game->getPlayerArray()[i];
|
||||
boost::shared_ptr<PlayerInterface> 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<SessionData>());
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,8 +196,6 @@ protected:
|
||||
// Protected constructor - this is a singleton.
|
||||
ServerGameStateStartRound();
|
||||
|
||||
static std::list<boost::shared_ptr<PlayerInterface> > GetActivePlayers(Game &curGame);
|
||||
|
||||
private:
|
||||
|
||||
static boost::thread_specific_ptr<ServerGameStateStartRound> Ptr;
|
||||
|
||||
Reference in New Issue
Block a user