Fixed id bug in networking code. Dealer id is now set correctly. Phew.
This commit is contained in:
@@ -24,26 +24,26 @@ using namespace std;
|
|||||||
ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC)
|
ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC)
|
||||||
: myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), allInCondition(0), bettingRoundsPlayed(0)
|
: myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), allInCondition(0), bettingRoundsPlayed(0)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
lastPlayersTurn = 0;
|
lastPlayersTurn = 0;
|
||||||
|
|
||||||
myBoard->setHand(this);
|
|
||||||
|
|
||||||
|
|
||||||
for(i=0; i<startQuantityPlayers; i++) {
|
|
||||||
if(playerArray[i]->getMyActiveStatus() != 0) {
|
|
||||||
playerArray[i]->setHand(this);
|
|
||||||
}
|
|
||||||
playerArray[i]->setMyCardsFlip(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// roundStartCashArray fllen
|
|
||||||
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
|
||||||
playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash());
|
|
||||||
}
|
|
||||||
|
|
||||||
assignButtons();
|
myBoard->setHand(this);
|
||||||
|
|
||||||
|
|
||||||
|
for(i=0; i<startQuantityPlayers; i++) {
|
||||||
|
if(playerArray[i]->getMyActiveStatus() != 0) {
|
||||||
|
playerArray[i]->setHand(this);
|
||||||
|
}
|
||||||
|
playerArray[i]->setMyCardsFlip(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// roundStartCashArray fllen
|
||||||
|
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
||||||
|
playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash());
|
||||||
|
}
|
||||||
|
|
||||||
|
assignButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,42 +60,42 @@ ClientHand::start()
|
|||||||
void
|
void
|
||||||
ClientHand::assignButtons()
|
ClientHand::assignButtons()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
//Aktive Spieler zählen
|
//Aktive Spieler zählen
|
||||||
int activePlayersCounter = 0;
|
int activePlayersCounter = 0;
|
||||||
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
||||||
if (playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++;
|
if (playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// alle Buttons loeschen
|
// alle Buttons loeschen
|
||||||
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { playerArray[i]->setMyButton(0); }
|
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { playerArray[i]->setMyButton(0); }
|
||||||
|
|
||||||
// DealerButton zuweisen
|
// DealerButton zuweisen
|
||||||
playerArray[dealerPosition]->setMyButton(1);
|
playerArray[dealerPosition]->setMyButton(1);
|
||||||
|
|
||||||
// assign Small Blind next to dealer. ATTENTION: in heads up it is big blind
|
// assign Small Blind next to dealer. ATTENTION: in heads up it is big blind
|
||||||
i = dealerPosition;
|
i = dealerPosition;
|
||||||
do {
|
do {
|
||||||
i = (i+1)%(MAX_NUMBER_OF_PLAYERS);
|
i = (i+1)%(MAX_NUMBER_OF_PLAYERS);
|
||||||
if(playerArray[i]->getMyActiveStatus()) {
|
if(playerArray[i]->getMyActiveStatus()) {
|
||||||
if(activePlayersCounter > 2) playerArray[i]->setMyButton(2); //small blind normal
|
if(activePlayersCounter > 2) playerArray[i]->setMyButton(2); //small blind normal
|
||||||
else playerArray[i]->setMyButton(3); //big blind in heads up
|
else playerArray[i]->setMyButton(3); //big blind in heads up
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(!(playerArray[i]->getMyActiveStatus()));
|
} while(!(playerArray[i]->getMyActiveStatus()));
|
||||||
|
|
||||||
// assign big blind next to small blind. ATTENTION: in heads up it is small blind
|
// assign big blind next to small blind. ATTENTION: in heads up it is small blind
|
||||||
do {
|
do {
|
||||||
i = (i+1)%(MAX_NUMBER_OF_PLAYERS);
|
i = (i+1)%(MAX_NUMBER_OF_PLAYERS);
|
||||||
if(playerArray[i]->getMyActiveStatus()) {
|
if(playerArray[i]->getMyActiveStatus()) {
|
||||||
if(activePlayersCounter > 2) playerArray[i]->setMyButton(3); //big blind normal
|
if(activePlayersCounter > 2) playerArray[i]->setMyButton(3); //big blind normal
|
||||||
else playerArray[i]->setMyButton(2); //small blind in heads up
|
else playerArray[i]->setMyButton(2); //small blind in heads up
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(!(playerArray[i]->getMyActiveStatus()));
|
} while(!(playerArray[i]->getMyActiveStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -51,15 +51,18 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
|
|||||||
PlayerDataList::const_iterator player_i = playerDataList.begin();
|
PlayerDataList::const_iterator player_i = playerDataList.begin();
|
||||||
PlayerDataList::const_iterator player_end = playerDataList.end();
|
PlayerDataList::const_iterator player_end = playerDataList.end();
|
||||||
|
|
||||||
|
bool dealerFound = false;
|
||||||
while (player_i != player_end)
|
while (player_i != player_end)
|
||||||
{
|
{
|
||||||
if ((*player_i)->GetUniqueId() == startData.startDealerPlayerId)
|
if ((*player_i)->GetUniqueId() == startData.startDealerPlayerId)
|
||||||
{
|
{
|
||||||
dealerPosition = (*player_i)->GetNumber();
|
dealerPosition = (*player_i)->GetNumber();
|
||||||
|
dealerFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++player_i;
|
++player_i;
|
||||||
}
|
}
|
||||||
|
assert(dealerFound);
|
||||||
|
|
||||||
// Board erstellen
|
// Board erstellen
|
||||||
actualBoard = myFactory->createBoard();
|
actualBoard = myFactory->createBoard();
|
||||||
|
|||||||
@@ -61,8 +61,6 @@ public:
|
|||||||
void setStartCash(const int& theValue) { startCash = theValue; }
|
void setStartCash(const int& theValue) { startCash = theValue; }
|
||||||
int getStartCash() const { return startCash; }
|
int getStartCash() const { return startCash; }
|
||||||
|
|
||||||
int getDealerPosition() const { return dealerPosition; }
|
|
||||||
|
|
||||||
int getMyGameID() const { return myGameID; }
|
int getMyGameID() const { return myGameID; }
|
||||||
|
|
||||||
//Zufgriff Laufvariablen
|
//Zufgriff Laufvariablen
|
||||||
|
|||||||
@@ -527,7 +527,7 @@ ClientStateWaitHand::Process(ClientThread &client)
|
|||||||
{
|
{
|
||||||
if (tmpData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND)
|
if (tmpData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND)
|
||||||
{
|
{
|
||||||
tmpPlayer->setMyButton(BUTTON_SMALL_BLIND);
|
assert(tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND);
|
||||||
tmpPlayer->setMyAction(tmpData.playerAction);
|
tmpPlayer->setMyAction(tmpData.playerAction);
|
||||||
tmpPlayer->setMySet(tmpData.cashValue);
|
tmpPlayer->setMySet(tmpData.cashValue);
|
||||||
client.GetGui().refreshSet();
|
client.GetGui().refreshSet();
|
||||||
@@ -535,7 +535,7 @@ ClientStateWaitHand::Process(ClientThread &client)
|
|||||||
}
|
}
|
||||||
else if (tmpData.gameState == GAME_STATE_PREFLOP_BIG_BLIND)
|
else if (tmpData.gameState == GAME_STATE_PREFLOP_BIG_BLIND)
|
||||||
{
|
{
|
||||||
tmpPlayer->setMyButton(BUTTON_BIG_BLIND);
|
assert(tmpPlayer->getMyButton() == BUTTON_BIG_BLIND);
|
||||||
tmpPlayer->setMyAction(tmpData.playerAction);
|
tmpPlayer->setMyAction(tmpData.playerAction);
|
||||||
tmpPlayer->setMySet(tmpData.cashValue);
|
tmpPlayer->setMySet(tmpData.cashValue);
|
||||||
client.GetGui().refreshSet();
|
client.GetGui().refreshSet();
|
||||||
|
|||||||
@@ -291,33 +291,33 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
|||||||
// Auto small blind / big blind at the beginning of preflop.
|
// Auto small blind / big blind at the beginning of preflop.
|
||||||
for (int i = 0; i < curGame.getActualQuantityPlayers(); i++)
|
for (int i = 0; i < curGame.getActualQuantityPlayers(); i++)
|
||||||
{
|
{
|
||||||
if(playerArray[i]->getMyButton() == BUTTON_SMALL_BLIND)
|
if(playerArray[i]->getMyButton() == BUTTON_SMALL_BLIND)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<NetPacket> notifySmallBlind(new NetPacketPlayersActionDone);
|
boost::shared_ptr<NetPacket> notifySmallBlind(new NetPacketPlayersActionDone);
|
||||||
NetPacketPlayersActionDone::Data actionDoneData;
|
NetPacketPlayersActionDone::Data actionDoneData;
|
||||||
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
|
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
|
||||||
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
||||||
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
||||||
actionDoneData.cashValue = playerArray[i]->getMySet();
|
actionDoneData.cashValue = playerArray[i]->getMySet();
|
||||||
static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
|
static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
|
||||||
server.SendToAllPlayers(notifySmallBlind);
|
server.SendToAllPlayers(notifySmallBlind);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < curGame.getActualQuantityPlayers(); i++)
|
for (int i = 0; i < curGame.getActualQuantityPlayers(); i++)
|
||||||
{
|
{
|
||||||
if(playerArray[i]->getMyButton() == BUTTON_BIG_BLIND)
|
if(playerArray[i]->getMyButton() == BUTTON_BIG_BLIND)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<NetPacket> notifyBigBlind(new NetPacketPlayersActionDone);
|
boost::shared_ptr<NetPacket> notifyBigBlind(new NetPacketPlayersActionDone);
|
||||||
NetPacketPlayersActionDone::Data actionDoneData;
|
NetPacketPlayersActionDone::Data actionDoneData;
|
||||||
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
|
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
|
||||||
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
||||||
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
||||||
actionDoneData.cashValue = playerArray[i]->getMySet();
|
actionDoneData.cashValue = playerArray[i]->getMySet();
|
||||||
static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
|
static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
|
||||||
server.SendToAllPlayers(notifyBigBlind);
|
server.SendToAllPlayers(notifyBigBlind);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server.SetState(ServerRecvStateStartRound::Instance());
|
server.SetState(ServerRecvStateStartRound::Instance());
|
||||||
|
|||||||
@@ -256,7 +256,26 @@ ServerRecvThread::InternalStartGame()
|
|||||||
StartData startData;
|
StartData startData;
|
||||||
int tmpDealerPos = 0;
|
int tmpDealerPos = 0;
|
||||||
Tools::getRandNumber(0, GetGameData().numberOfPlayers-1, 1, &tmpDealerPos, 0);
|
Tools::getRandNumber(0, GetGameData().numberOfPlayers-1, 1, &tmpDealerPos, 0);
|
||||||
startData.startDealerPlayerId = static_cast<unsigned>(tmpDealerPos);
|
// The Player Id is not continuous. Therefore, the start dealer position
|
||||||
|
// needs to be converted to a player Id, and cannot be directly generated
|
||||||
|
// as player Id.
|
||||||
|
PlayerDataList::const_iterator player_i = playerData.begin();
|
||||||
|
PlayerDataList::const_iterator player_end = playerData.end();
|
||||||
|
|
||||||
|
bool randDealerFound = false;
|
||||||
|
while (player_i != player_end)
|
||||||
|
{
|
||||||
|
if ((*player_i)->GetNumber() == tmpDealerPos)
|
||||||
|
{
|
||||||
|
// Get ID of the dealer.
|
||||||
|
startData.startDealerPlayerId = static_cast<unsigned>((*player_i)->GetUniqueId());
|
||||||
|
randDealerFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++player_i;
|
||||||
|
}
|
||||||
|
assert(randDealerFound);
|
||||||
|
|
||||||
SetStartData(startData);
|
SetStartData(startData);
|
||||||
|
|
||||||
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), m_curGameId++));
|
m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), m_curGameId++));
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include <net/clientthread.h>
|
#include <net/clientthread.h>
|
||||||
#include <net/serverthread.h>
|
#include <net/serverthread.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#define NET_CLIENT_TERMINATE_TIMEOUT_MSEC 1000
|
#define NET_CLIENT_TERMINATE_TIMEOUT_MSEC 1000
|
||||||
#define NET_SERVER_TERMINATE_TIMEOUT_MSEC 1000
|
#define NET_SERVER_TERMINATE_TIMEOUT_MSEC 1000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user