remove hand-object from board

This commit is contained in:
floty
2011-01-06 22:00:52 +00:00
parent 54a183b496
commit f84e629f17
14 changed files with 71 additions and 31 deletions
+3 -1
View File
@@ -31,7 +31,6 @@ public:
virtual ~BoardInterface(); virtual ~BoardInterface();
// //
virtual void setPlayerLists(PlayerList, PlayerList, PlayerList) =0; virtual void setPlayerLists(PlayerList, PlayerList, PlayerList) =0;
virtual void setHand(HandInterface*) =0;
// //
virtual void setMyCards(int* theValue) =0; virtual void setMyCards(int* theValue) =0;
virtual void getMyCards(int* theValue) =0; virtual void getMyCards(int* theValue) =0;
@@ -40,6 +39,9 @@ public:
virtual void setPot(int theValue) =0; virtual void setPot(int theValue) =0;
virtual int getSets() const=0; virtual int getSets() const=0;
virtual void setSets(int theValue) =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 collectSets() =0;
virtual void collectPot() =0; virtual void collectPot() =0;
+1 -1
View File
@@ -32,7 +32,7 @@ public:
virtual ~EngineFactory(); virtual ~EngineFactory();
virtual HandInterface* createHand(boost::shared_ptr<EngineFactory> 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 HandInterface* createHand(boost::shared_ptr<EngineFactory> 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<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) =0; virtual boost::shared_ptr<PlayerInterface> 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<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB) =0; virtual std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB) =0;
}; };
+17 -8
View File
@@ -27,7 +27,7 @@
using namespace std; 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; 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; runningPlayerList = rpl;
} }
void LocalBoard::setHand(HandInterface* br) { currentHand = br; }
void LocalBoard::collectSets() { void LocalBoard::collectSets() {
sets = 0; sets = 0;
@@ -141,7 +139,12 @@ void LocalBoard::distributePot() {
if(mod == 0) { if(mod == 0) {
for(j=2; j<potLevel.size(); j++) { for(j=2; j<potLevel.size(); j++) {
it = currentHand->getSeatIt(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()) { if(it == seatsList->end()) {
throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND);
} }
@@ -158,8 +161,14 @@ void LocalBoard::distributePot() {
else { else {
// winnerPointer = currentHand->getDealerPosition(); // 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); throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND);
} }
@@ -243,7 +252,7 @@ void LocalBoard::determinePlayerNeedToShowCards() {
playerNeedToShowCards.clear(); playerNeedToShowCards.clear();
// in All In Condition everybody have to show the cards // in All In Condition everybody have to show the cards
if(currentHand->getAllInCondition()) { if(allInCondition) {
PlayerListConstIterator it_c; PlayerListConstIterator it_c;
@@ -288,7 +297,7 @@ void LocalBoard::determinePlayerNeedToShowCards() {
// cout << "lAP-Ende: " << currentHand->getLastActionPlayer() << endl; // cout << "lAP-Ende: " << currentHand->getLastActionPlayer() << endl;
// search lastActionPlayer // search lastActionPlayer
for(it_c = activePlayerList->begin(); it_c != activePlayerList->end(); it_c++) { 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; lastActionPlayerIt = it_c;
// cout << (*it_c)->getMyUniqueID() << endl; // cout << (*it_c)->getMyUniqueID() << endl;
break; break;
+8 -5
View File
@@ -32,15 +32,17 @@ class HandInterface;
class LocalBoard : public BoardInterface{ class LocalBoard : public BoardInterface{
public: public:
LocalBoard(); LocalBoard(unsigned dealerPosition);
~LocalBoard(); ~LocalBoard();
void setPlayerLists(PlayerList, PlayerList, PlayerList); 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 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 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;} int getPot() const { return pot;}
void setPot(int theValue) { pot = theValue;} void setPot(int theValue) { pot = theValue;}
int getSets() const { return sets; } int getSets() const { return sets; }
@@ -64,14 +66,15 @@ private:
PlayerList activePlayerList; PlayerList activePlayerList;
PlayerList runningPlayerList; PlayerList runningPlayerList;
HandInterface *currentHand;
std::list<unsigned> winners; std::list<unsigned> winners;
std::list<unsigned> playerNeedToShowCards; std::list<unsigned> playerNeedToShowCards;
int myCards[5]; int myCards[5];
int pot; int pot;
int sets; int sets;
unsigned dealerPosition;
bool allInCondition;
unsigned lastActionPlayer;
}; };
@@ -48,7 +48,7 @@ LocalEngineFactory::createHand(boost::shared_ptr<EngineFactory> f, GuiInterface
return new LocalHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC); 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<PlayerInterface> 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<PlayerInterface> (new LocalPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB)); } boost::shared_ptr<PlayerInterface> 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<PlayerInterface> (new LocalPlayer(myConfig, b, id, uniqueId, type, name, avatar, sC, aS, mB)); }
+1 -1
View File
@@ -38,7 +38,7 @@ public:
~LocalEngineFactory(); ~LocalEngineFactory();
HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); HandInterface* createHand(boost::shared_ptr<EngineFactory> 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<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB); std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB);
+12 -4
View File
@@ -40,8 +40,6 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardI
CardsValue myCardsValue; CardsValue myCardsValue;
myBoard->setHand(this);
for(it=seatsList->begin(); it!=seatsList->end(); it++) { for(it=seatsList->begin(); it!=seatsList->end(); it++) {
(*it)->setHand(this); (*it)->setHand(this);
// set myFlipCards 0 // set myFlipCards 0
@@ -439,6 +437,7 @@ void LocalHand::assignButtons() {
// first player after dealer have to show his cards first (in showdown) // first player after dealer have to show his cards first (in showdown)
lastActionPlayer = (*it)->getMyUniqueID(); lastActionPlayer = (*it)->getMyUniqueID();
myBoard->setLastActionPlayer(lastActionPlayer);
it++; it++;
if(it == activePlayerList->end()) it = activePlayerList->begin(); if(it == activePlayerList->end()) it = activePlayerList->begin();
@@ -551,6 +550,7 @@ void LocalHand::switchRounds() {
// 1) all players all in // 1) all players all in
if(allInPlayersCounter == nonFoldPlayerCounter) { if(allInPlayersCounter == nonFoldPlayerCounter) {
allInCondition = true; allInCondition = true;
myBoard->setAllInCondition(true);
} }
// 2) all players but one all in and he has highest set // 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()) { if((*it_c)->getMySet() >= myBeRo[currentRound]->getHighestSet()) {
allInCondition = true; allInCondition = true;
myBoard->setAllInCondition(true);
} }
} }
@@ -578,14 +579,16 @@ void LocalHand::switchRounds() {
} }
if( (*bigBlindIt_c)->getMySet() <= smallBlind && tempCounter == allInPlayersCounter) { if( (*bigBlindIt_c)->getMySet() <= smallBlind && tempCounter == allInPlayersCounter) {
allInCondition = true; allInCondition = true;
myBoard->setAllInCondition(true);
} }
} }
// no.2: heads up -> detect player who is all in and bb but could set less than sb // 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++) { 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) { 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; allInCondition = true;
myBoard->setAllInCondition(true);
} }
} }
} }
@@ -694,3 +697,8 @@ PlayerListIterator LocalHand::getRunningPlayerIt(unsigned uniqueId) const {
return it; return it;
} }
void LocalHand::setLastActionPlayer(unsigned theValue) {
lastActionPlayer = theValue;
myBoard->setLastActionPlayer(theValue);
}
+1 -1
View File
@@ -81,7 +81,7 @@ public:
void setLastPlayersTurn(int theValue) { lastPlayersTurn = theValue; } void setLastPlayersTurn(int theValue) { lastPlayersTurn = theValue; }
int getLastPlayersTurn() const { return lastPlayersTurn; } int getLastPlayersTurn() const { return lastPlayersTurn; }
void setLastActionPlayer ( unsigned theValue ) { lastActionPlayer = theValue; } void setLastActionPlayer ( unsigned theValue );
unsigned getLastActionPlayer() const { return lastActionPlayer; } unsigned getLastActionPlayer() const { return lastActionPlayer; }
void setCardsShown(bool theValue) { cardsShown = theValue; } void setCardsShown(bool theValue) { cardsShown = theValue; }
+16 -2
View File
@@ -23,8 +23,8 @@
using namespace std; using namespace std;
ClientBoard::ClientBoard() ClientBoard::ClientBoard(unsigned dp)
: currentHand(0), pot(0), sets(0) : currentHand(0), pot(0), sets(0), dealerPosition(dp)
{ {
myCards[0] = myCards[1] = myCards[2] = myCards[3] = myCards[4] = 0; myCards[0] = myCards[1] = myCards[2] = myCards[3] = myCards[4] = 0;
} }
@@ -94,6 +94,20 @@ ClientBoard::setSets(int theValue)
sets = 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 void
ClientBoard::collectSets() ClientBoard::collectSets()
{ {
+7 -1
View File
@@ -31,7 +31,7 @@ class HandInterface;
class ClientBoard : public BoardInterface class ClientBoard : public BoardInterface
{ {
public: public:
ClientBoard(); ClientBoard(unsigned dealerPosition);
~ClientBoard(); ~ClientBoard();
void setPlayerLists(PlayerList, PlayerList, PlayerList); void setPlayerLists(PlayerList, PlayerList, PlayerList);
@@ -45,6 +45,9 @@ public:
int getSets() const; int getSets() const;
void setSets(int theValue); void setSets(int theValue);
void setAllInCondition(bool theValue);
void setLastActionPlayer(unsigned theValue);
void collectSets(); void collectSets();
void collectPot(); void collectPot();
@@ -72,6 +75,9 @@ private:
int myCards[5]; int myCards[5];
int pot; int pot;
int sets; int sets;
unsigned dealerPosition;
bool allInCondition;
unsigned lastActionPlayer;
}; };
#endif #endif
@@ -40,9 +40,9 @@ HandInterface* ClientEngineFactory::createHand(boost::shared_ptr<EngineFactory>
return new ClientHand(f, g, b, l, sl, apl, rpl, id, sP, dP, sB, sC); 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<PlayerInterface> ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) boost::shared_ptr<PlayerInterface> ClientEngineFactory::createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
@@ -39,7 +39,7 @@ public:
~ClientEngineFactory(); ~ClientEngineFactory();
HandInterface* createHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardInterface *b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); HandInterface* createHand(boost::shared_ptr<EngineFactory> 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<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); boost::shared_ptr<PlayerInterface> createPlayer(BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB);
std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB); std::vector<boost::shared_ptr<BeRoInterface> > createBeRo(HandInterface* hi, int id, unsigned dP, int sB);
-2
View File
@@ -28,8 +28,6 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, Boar
{ {
PlayerListIterator it; PlayerListIterator it;
myBoard->setHand(this);
for(it=seatsList->begin(); it!=seatsList->end(); it++) { for(it=seatsList->begin(); it!=seatsList->end(); it++) {
(*it)->setHand(this); (*it)->setHand(this);
// myFlipCards auf 0 setzen // myFlipCards auf 0 setzen
+1 -1
View File
@@ -65,7 +65,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
throw LocalException(__FILE__, __LINE__, ERR_DEALER_NOT_FOUND); throw LocalException(__FILE__, __LINE__, ERR_DEALER_NOT_FOUND);
// create board // create board
currentBoard = myFactory->createBoard(); currentBoard = myFactory->createBoard(dealerPosition);
// create player lists // create player lists
seatsList = PlayerList(new std::list<boost::shared_ptr<PlayerInterface> >); seatsList = PlayerList(new std::list<boost::shared_ptr<PlayerInterface> >);