diff --git a/src/engine/handinterface.h b/src/engine/handinterface.h index 4183ceda..c21cdb22 100644 --- a/src/engine/handinterface.h +++ b/src/engine/handinterface.h @@ -59,8 +59,8 @@ public: virtual void setStartQuantityPlayers(int theValue) =0; virtual int getStartQuantityPlayers() const =0; - virtual void setActualRound(int theValue) =0; - virtual int getActualRound() const =0; + virtual void setCurrentRound(int theValue) =0; + virtual int getCurrentRound() const =0; virtual void setDealerPosition(int theValue) =0; virtual int getDealerPosition() const =0; diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index 90580cd0..4e1c0095 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -274,7 +274,7 @@ void LocalBeRo::run() { // aktuelle bero nicht dran, weil alle Sets gleich sind //also gehe in naechste bero - myHand->setActualRound(myBeRoID+1); + myHand->setCurrentRound(myBeRoID+1); //Action loeschen und ActionButtons refresh // for(i=0; igetActualQuantityPlayers() < 3 && firstHeadsUpRound == 1) || myHand->getPlayerArray()[playersTurn]->getMyActiveStatus() == 0 ) { +// if( !(myHand->getCurrentQuantityPlayers() < 3 && firstHeadsUpRound == 1) || myHand->getPlayerArray()[playersTurn]->getMyActiveStatus() == 0 ) { // not first round in heads up (for headsup dealer is smallblind so it is dealers turn) // naechsten Spieler ermitteln diff --git a/src/engine/local_engine/localberopreflop.cpp b/src/engine/local_engine/localberopreflop.cpp index e9572409..e973b5c8 100644 --- a/src/engine/local_engine/localberopreflop.cpp +++ b/src/engine/local_engine/localberopreflop.cpp @@ -306,10 +306,10 @@ void LocalBeRoPreflop::run() { // Preflop nicht dran, weil wir nicht mehr in erster PreflopRunde und alle Sets gleich sind //also gehe in Flop - getMyHand()->setActualRound(GAME_STATE_FLOP); + getMyHand()->setCurrentRound(GAME_STATE_FLOP); // exception no.1 - see above -// if(getMyHand()->getAllInCondition()) getMyHand()->setActualRound(GAME_STATE_PREFLOP);; +// if(getMyHand()->getAllInCondition()) getMyHand()->setCurrentRound(GAME_STATE_PREFLOP);; //Action loeschen und ActionButtons refresh for(it_c=getMyHand()->getRunningPlayerList()->begin(); it_c!=getMyHand()->getRunningPlayerList()->end(); it_c++) { diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index a8622641..fb41720e 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -30,7 +30,7 @@ using namespace std; LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, unsigned dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(sl_old), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(false), +: myFactory(f), myGui(g), myBoard(b), playerArray(sl_old), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), currentRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(false), cardsShown(false), bettingRoundsPlayed(0) { @@ -551,7 +551,7 @@ void LocalHand::switchRounds() { myBoard->collectPot(); myGui->refreshPot(); myGui->refreshSet(); - actualRound = 4; + currentRound = 4; } // prfen der All In Kondition // fr All In Prozedur mssen mindestens zwei aktive Player vorhanden sein @@ -568,7 +568,7 @@ void LocalHand::switchRounds() { // TODO -> runningPlayerList s.u. // for(i=0; igetMyAction() != 1 && playerArray[i]->getMyAction() != 6 && playerArray[i]->getMyActiveStatus() == 1 && playerArray[i]->getMySet() >= myBeRo[actualRound]->getHighestSet()) { +// if(playerArray[i]->getMyAction() != 1 && playerArray[i]->getMyAction() != 6 && playerArray[i]->getMyActiveStatus() == 1 && playerArray[i]->getMySet() >= myBeRo[currentRound]->getHighestSet()) { // allInCondition = 1; // } // @@ -577,13 +577,13 @@ void LocalHand::switchRounds() { for(it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); it_c++) { - if((*it_c)->getMySet() >= myBeRo[actualRound]->getHighestSet()) { + if((*it_c)->getMySet() >= myBeRo[currentRound]->getHighestSet()) { allInCondition = true; } } -// if( (*(runningPlayerList.begin()))->getMySet() >= myBeRo[actualRound]->getHighestSet() ) { +// if( (*(runningPlayerList.begin()))->getMySet() >= myBeRo[currentRound]->getHighestSet() ) { // allInCondition = 1; // } @@ -600,9 +600,9 @@ void LocalHand::switchRounds() { // exception // no.1: if in first Preflop Round next player is small blind and only all-in-big-blind with less than smallblind amount and other all-in players with less than small blind are nonfold too -> preflop is over - PlayerListConstIterator smallBlindIt_c = getRunningPlayerIt(myBeRo[actualRound]->getSmallBlindPositionId()); - PlayerListConstIterator bigBlindIt_c = getActivePlayerIt(myBeRo[actualRound]->getBigBlindPositionId()); - if(smallBlindIt_c!=runningPlayerList->end() && bigBlindIt_c!=activePlayerList->end() && actualRound == GAME_STATE_PREFLOP && myBeRo[actualRound]->getFirstRound()) { + PlayerListConstIterator smallBlindIt_c = getRunningPlayerIt(myBeRo[currentRound]->getSmallBlindPositionId()); + PlayerListConstIterator bigBlindIt_c = getActivePlayerIt(myBeRo[currentRound]->getBigBlindPositionId()); + if(smallBlindIt_c!=runningPlayerList->end() && bigBlindIt_c!=activePlayerList->end() && currentRound == GAME_STATE_PREFLOP && myBeRo[currentRound]->getFirstRound()) { // determine player who are all in with less than small blind amount int tempCounter = 0; for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) { @@ -637,15 +637,15 @@ void LocalHand::switchRounds() { myGui->refreshSet(); myGui->flipHolecardsAllIn(); - if (actualRound < 4) // do not increment past 4 - actualRound++; + if (currentRound < 4) // do not increment past 4 + currentRound++; //log board cards for allin - if(actualRound >= 1) { + if(currentRound >= 1) { int tempBoardCardsArray[5]; myBoard->getMyCards(tempBoardCardsArray); - myGui->logDealBoardCardsMsg(actualRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]); + myGui->logDealBoardCardsMsg(currentRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]); } } @@ -664,13 +664,13 @@ void LocalHand::switchRounds() { } - myGui->refreshGameLabels((GameState)getActualRound()); + myGui->refreshGameLabels((GameState)getCurrentRound()); // /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl; // // cout << "NextPlayerSpeed2 start" << endl; - switch(actualRound) { + switch(currentRound) { case 0: { // Preflop starten myGui->preflopAnimation1(); diff --git a/src/engine/local_engine/localhand.h b/src/engine/local_engine/localhand.h index 19dd56e4..64f58729 100755 --- a/src/engine/local_engine/localhand.h +++ b/src/engine/local_engine/localhand.h @@ -54,7 +54,7 @@ public: boost::shared_ptr getTurn() const { return myBeRo[GAME_STATE_TURN]; } boost::shared_ptr getRiver() const { return myBeRo[GAME_STATE_RIVER]; } GuiInterface* getGuiInterface() const { return myGui; } - boost::shared_ptr getCurrentBeRo() const { return myBeRo[actualRound]; } + boost::shared_ptr getCurrentBeRo() const { return myBeRo[currentRound]; } void setMyID(int theValue) { myID = theValue; } int getMyID() const { return myID; } @@ -62,8 +62,8 @@ public: void setStartQuantityPlayers(int theValue) { startQuantityPlayers = theValue; } int getStartQuantityPlayers() const { return startQuantityPlayers; } - void setActualRound(int theValue) { actualRound = theValue; } - int getActualRound() const { return actualRound; } + void setCurrentRound(int theValue) { currentRound = theValue; } + int getCurrentRound() const { return currentRound; } void setDealerPosition(int theValue) { dealerPosition = theValue; } int getDealerPosition() const { return dealerPosition; } @@ -107,7 +107,7 @@ private: int myID; int startQuantityPlayers; unsigned dealerPosition; // -1 -> neutral - int actualRound; //0 = preflop, 1 = flop, 2 = turn, 3 = river + int currentRound; //0 = preflop, 1 = flop, 2 = turn, 3 = river int smallBlind; int startCash; diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 8988edd7..d9a72e9a 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -848,7 +848,7 @@ static const RoundData FlopValues[] = #define NUM_FLOP_VALUES (sizeof(FlopValues)/sizeof(RoundData)) LocalPlayer::LocalPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) -: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) +: PlayerInterface(), myConfig(c), currentHand(0), currentBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) { // !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!! @@ -929,24 +929,24 @@ LocalPlayer::~LocalPlayer() } -void LocalPlayer::setHand(HandInterface* br) { actualHand = br; } +void LocalPlayer::setHand(HandInterface* br) { currentHand = br; } void LocalPlayer::action() { // int myOldCash = myCash; -// int oldHighestSet = actualHand->getCurrentBeRo()->getHighestSet(); -// int oldMinimumRaise = actualHand->getCurrentBeRo()->getMinimumRaise(); +// int oldHighestSet = currentHand->getCurrentBeRo()->getHighestSet(); +// int oldMinimumRaise = currentHand->getCurrentBeRo()->getMinimumRaise(); // int myOldSet = mySet; - switch(actualHand->getActualRound()) { + switch(currentHand->getCurrentRound()) { case 0: { if(myConfig->readConfigInt("EngineVersion")) preflopEngine3(); else preflopEngine(); - actualBoard->collectSets(); - actualHand->getGuiInterface()->refreshPot(); + currentBoard->collectSets(); + currentHand->getGuiInterface()->refreshPot(); } break; case 1: { @@ -954,8 +954,8 @@ void LocalPlayer::action() { if(myConfig->readConfigInt("EngineVersion")) flopEngine3(); else flopEngine(); - actualBoard->collectSets(); - actualHand->getGuiInterface()->refreshPot(); + currentBoard->collectSets(); + currentHand->getGuiInterface()->refreshPot(); } break; case 2: { @@ -963,8 +963,8 @@ void LocalPlayer::action() { if(myConfig->readConfigInt("EngineVersion")) turnEngine3(); else turnEngine(); - actualBoard->collectSets(); - actualHand->getGuiInterface()->refreshPot(); + currentBoard->collectSets(); + currentHand->getGuiInterface()->refreshPot(); } break; case 3: { @@ -972,26 +972,26 @@ void LocalPlayer::action() { if(myConfig->readConfigInt("EngineVersion")) riverEngine3(); else riverEngine(); - actualBoard->collectSets(); - actualHand->getGuiInterface()->refreshPot(); + currentBoard->collectSets(); + currentHand->getGuiInterface()->refreshPot(); } break; default: {} } -// cout << checkMyAction(myAction, mySet - myOldSet, myOldSet, myOldCash, oldHighestSet, oldMinimumRaise, actualHand->getSmallBlind()) << endl; +// cout << checkMyAction(myAction, mySet - myOldSet, myOldSet, myOldCash, oldHighestSet, oldMinimumRaise, currentHand->getSmallBlind()) << endl; myTurn = 0; // cout << "jetzt" << endl; //set that i was the last active player. need this for unhighlighting groupbox - actualHand->setLastPlayersTurn(myID); + currentHand->setLastPlayersTurn(myID); - actualHand->getGuiInterface()->logPlayerActionMsg(myName, myAction, mySet); - actualHand->getGuiInterface()->nextPlayerAnimation(); + currentHand->getGuiInterface()->logPlayerActionMsg(myName, myAction, mySet); + currentHand->getGuiInterface()->nextPlayerAnimation(); -// cout << "playerID in action(): " << (*(actualHand->getCurrentBeRo()->getCurrentPlayersTurnIt()))->getMyID() << endl; +// cout << "playerID in action(): " << (*(currentHand->getCurrentBeRo()->getCurrentPlayersTurnIt()))->getMyID() << endl; } int LocalPlayer::checkMyAction(int targetAction, int targetBet, int highestSet, int minimumRaise, int smallBlind) { @@ -1049,7 +1049,7 @@ void LocalPlayer::preflopEngine() { PlayerListConstIterator it_c; // temporär solange preflopValue und flopValue noch nicht bereinigt für sechs und sieben spieler - int players = actualHand->getActivePlayerList()->size(); + int players = currentHand->getActivePlayerList()->size(); if(players > 5) players = 5; // myOdds auslesen @@ -1062,7 +1062,7 @@ void LocalPlayer::preflopEngine() { myNiveau[2] = 54 + myDude4 - 7*(players - 2); // eigenes mögliches highestSet - int individualHighestSet = actualHand->getCurrentBeRo()->getHighestSet(); + int individualHighestSet = currentHand->getCurrentBeRo()->getHighestSet(); if(individualHighestSet > myCash) individualHighestSet = myCash; // Verhaeltnis Set / Cash für call @@ -1080,9 +1080,9 @@ void LocalPlayer::preflopEngine() { // cout << myID << ": " << myHoleCardsValue << " - " << myNiveau[0] << " " << myNiveau[2] << " - " << myCards[0] << " " << myCards[1] << endl; // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist ! -// int aggValue = (int)(((actualHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); +// int aggValue = (int)(((currentHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); // -// if(actualHand->getPlayerArray()[0]->getMyActiveStatus() && actualHand->getPlayerArray()[0]->getMyAction() != 1) { +// if(currentHand->getPlayerArray()[0]->getMyActiveStatus() && currentHand->getPlayerArray()[0]->getMyAction() != 1) { // myNiveau[0] -= aggValue; // myNiveau[2] -= aggValue; // } @@ -1090,10 +1090,10 @@ void LocalPlayer::preflopEngine() { // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist ! - it_c = actualHand->getActivePlayerIt(0); - if( it_c != actualHand->getActivePlayerList()->end() ) { + it_c = currentHand->getActivePlayerIt(0); + if( it_c != currentHand->getActivePlayerList()->end() ) { if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD ) { - int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); + int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); myNiveau[0] -= aggValue; myNiveau[2] -= aggValue; } @@ -1112,7 +1112,7 @@ void LocalPlayer::preflopEngine() { if(myOdds >= myNiveau[2]) { // raise-loop unterbinden -> d.h. entweder call oder bei superblatt all in - if(actualHand->getCurrentBeRo()->getHighestSet() >= 12*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 12*currentHand->getSmallBlind()) { // all in if(myOdds >= myNiveau[2] + 8) { raise = myCash; @@ -1121,7 +1121,7 @@ void LocalPlayer::preflopEngine() { // nur call else { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { raise = myCash; myAction = 5; } else { @@ -1132,13 +1132,13 @@ void LocalPlayer::preflopEngine() { // Standard-Raise-Routine } else { // raise-Betrag ermitteln - raise = (((int)myOdds-myNiveau[2])/2)*2*actualHand->getSmallBlind(); + raise = (((int)myOdds-myNiveau[2])/2)*2*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { raise = myCash; } myAction = 5; @@ -1148,33 +1148,33 @@ void LocalPlayer::preflopEngine() { if(cBluff > 90) { myAction = 3; // bigBlind --> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; } if(cBluff > 80 && myOdds >= myNiveau[2] + 4) { myAction = 3; // bigBlind --> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; } if(cBluff > 70 && myOdds >= myNiveau[2] + 8) { myAction = 3; // bigBlind --> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; } if(cBluff > 60 && myOdds >= myNiveau[2] + 12) { myAction = 3; // bigBlind --> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; } } else { // call - if(myOdds >= myNiveau[0] || (mySet >= actualHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-8)) { + if(myOdds >= myNiveau[0] || (mySet >= currentHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-8)) { // bigBlind --> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; else { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { raise = myCash; myAction = 5; } @@ -1186,7 +1186,7 @@ void LocalPlayer::preflopEngine() { // fold else { // bigBlind -> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; else myAction = 1; } } @@ -1194,41 +1194,41 @@ void LocalPlayer::preflopEngine() { // cout << sBluff << endl; // auf sBluff testen --> raise statt call oder fold - if((sBluff < 100/((((int)actualHand->getActivePlayerList()->size()-2)*6)+3) && myOdds < myNiveau[2] && actualHand->getCurrentBeRo()->getHighestSet() == 2*actualHand->getSmallBlind() && sBluffStatus == 0) || sBluffStatus == 1) { + if((sBluff < 100/((((int)currentHand->getActivePlayerList()->size()-2)*6)+3) && myOdds < myNiveau[2] && currentHand->getCurrentBeRo()->getHighestSet() == 2*currentHand->getSmallBlind() && sBluffStatus == 0) || sBluffStatus == 1) { // cout << "sBLUFF!" << endl; sBluffStatus = 1; // Gegner raisen ebenfalls -> call - if(actualHand->getCurrentBeRo()->getHighestSet() >= 4*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 4*currentHand->getSmallBlind()) { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/6) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/6) { raise = myCash; myAction = 5; } else { myAction = 3; // bigBlind --> check - if(myButton == 3 && mySet == actualHand->getCurrentBeRo()->getHighestSet()) myAction = 2; + if(myButton == 3 && mySet == currentHand->getCurrentBeRo()->getHighestSet()) myAction = 2; } } // Standard-Raise-Routine else { // raise-Betrag ermitteln - raise = (sBluff/(8-actualHand->getActivePlayerList()->size()))*actualHand->getSmallBlind(); + raise = (sBluff/(8-currentHand->getActivePlayerList()->size()))*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { raise = myCash; } myAction = 5; } // extrem hoher set der gegner -> bluff beenden - if((actualHand->getCurrentBeRo()->getHighestSet() >= 12*actualHand->getSmallBlind() && myOdds < myNiveau[0]) || (actualHand->getCurrentBeRo()->getHighestSet() >= 20*actualHand->getSmallBlind() && myOdds < myNiveau[2])) { + if((currentHand->getCurrentBeRo()->getHighestSet() >= 12*currentHand->getSmallBlind() && myOdds < myNiveau[0]) || (currentHand->getCurrentBeRo()->getHighestSet() >= 20*currentHand->getSmallBlind() && myOdds < myNiveau[2])) { myAction = 1; } @@ -1238,10 +1238,10 @@ void LocalPlayer::preflopEngine() { // minimum raise setting and resetting if(myAction == 5) { - if(raise < actualHand->getCurrentBeRo()->getMinimumRaise()) { - raise = actualHand->getCurrentBeRo()->getMinimumRaise(); + if(raise < currentHand->getCurrentBeRo()->getMinimumRaise()) { + raise = currentHand->getCurrentBeRo()->getMinimumRaise(); } - actualHand->getCurrentBeRo()->setMinimumRaise(raise); + currentHand->getCurrentBeRo()->setMinimumRaise(raise); } @@ -1254,7 +1254,7 @@ void LocalPlayer::preflopEngine() { case 1: { // player 1 - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CALL; // raise = 3000; @@ -1274,7 +1274,7 @@ void LocalPlayer::preflopEngine() { case 2: { // player 2 - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CALL; // raise = 20; @@ -1298,7 +1298,7 @@ void LocalPlayer::preflopEngine() { } break; case 3: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_FOLD; // raise = 20; @@ -1321,7 +1321,7 @@ void LocalPlayer::preflopEngine() { } break; case 4: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CALL; // raise = 20; @@ -1377,7 +1377,7 @@ void LocalPlayer::flopEngine() { PlayerListConstIterator it_c; // übergang solange preflopValue und flopValue noch nicht bereinigt - int players = actualHand->getActivePlayerList()->size(); + int players = currentHand->getActivePlayerList()->size(); if(players > 5) players = 5; calcMyOdds(); @@ -1391,23 +1391,23 @@ void LocalPlayer::flopEngine() { myNiveau[2] = 69 + myDude4 - 7*(players - 2); // eigenes mögliches highestSet - int individualHighestSet = actualHand->getCurrentBeRo()->getHighestSet(); + int individualHighestSet = currentHand->getCurrentBeRo()->getHighestSet(); if(individualHighestSet > myCash) individualHighestSet = myCash; // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist -// int aggValue = (int)(((actualHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); +// int aggValue = (int)(((currentHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); // -// if(actualHand->getPlayerArray()[0]->getMyActiveStatus() && actualHand->getPlayerArray()[0]->getMyAction() != 1) { +// if(currentHand->getPlayerArray()[0]->getMyActiveStatus() && currentHand->getPlayerArray()[0]->getMyAction() != 1) { // for(i=0; i<3; i++) { // myNiveau[i] -= aggValue; // } // } // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist ! - it_c = actualHand->getActivePlayerIt(0); - if( it_c != actualHand->getActivePlayerList()->end() ) { + it_c = currentHand->getActivePlayerIt(0); + if( it_c != currentHand->getActivePlayerList()->end() ) { if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD ) { - int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); + int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); for(i=0; i<3; i++) { myNiveau[i] -= aggValue; } @@ -1420,7 +1420,7 @@ void LocalPlayer::flopEngine() { Tools::getRandNumber(1,100,1,&cBluff,0); // aktiv oder passiv? - if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // Verhaeltnis Set / Cash für call if(myCash/individualHighestSet >= 25) { @@ -1438,7 +1438,7 @@ void LocalPlayer::flopEngine() { if(myOdds >= myNiveau[2]) { // raise-loop unterbinden -> d.h. entweder call oder bei superblatt all in - if(actualHand->getCurrentBeRo()->getHighestSet() >= 12*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 12*currentHand->getSmallBlind()) { // all in if(myOdds >= myNiveau[2] + 15) { raise = myCash; @@ -1447,7 +1447,7 @@ void LocalPlayer::flopEngine() { // nur call else { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { raise = myCash; myAction = 5; } else { @@ -1458,13 +1458,13 @@ void LocalPlayer::flopEngine() { // Standard-Raise-Routine } else { // raise-Betrag ermitteln - raise = (((int)myOdds-myNiveau[2])/5)*2*actualHand->getSmallBlind(); + raise = (((int)myOdds-myNiveau[2])/5)*2*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4.0)/5.0) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4.0)/5.0) { raise = myCash; } myAction = 5; @@ -1479,9 +1479,9 @@ void LocalPlayer::flopEngine() { } else { // call -> über niveau0, schon einiges gesetzt im flop, schon einiges insgesamt gesetzt - if(myOdds >= myNiveau[0] || (mySet >= actualHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-5) || (myRoundStartCash-myCash > individualHighestSet && myNiveau[0]-3)) { + if(myOdds >= myNiveau[0] || (mySet >= currentHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-5) || (myRoundStartCash-myCash > individualHighestSet && myNiveau[0]-3)) { // all in bei knappem call - if(actualHand->getCurrentBeRo()->getHighestSet() > (myCash*3.0)/4.0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > (myCash*3.0)/4.0) { raise = myCash; myAction = 5; } @@ -1496,13 +1496,13 @@ void LocalPlayer::flopEngine() { else { // bet if(myOdds >= myNiveau[1]) { - bet = (((int)myOdds-myNiveau[1])/8)*2*actualHand->getSmallBlind(); + bet = (((int)myOdds-myNiveau[1])/8)*2*currentHand->getSmallBlind(); // bet zu klein if(bet == 0) { - bet = 2*actualHand->getSmallBlind(); + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -1525,13 +1525,13 @@ void LocalPlayer::flopEngine() { // Position-Bluff generieren Tools::getRandNumber(1,100,1,&pBluff,0); if(pBluff <= 16) { - bet = (pBluff/4)*2*actualHand->getSmallBlind(); + bet = (pBluff/4)*2*currentHand->getSmallBlind(); // bet zu klein if(bet == 0) { - bet = 2*actualHand->getSmallBlind(); + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -1548,34 +1548,34 @@ void LocalPlayer::flopEngine() { // auf sBluffStatus testen --> raise statt call und bet statt check // aktiv oder passiv? - if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { if(sBluffStatus && myOdds < myNiveau[2]) { // cout << "sBLUFF!" << endl; // Gegner setzen -> call - if(actualHand->getCurrentBeRo()->getHighestSet() >= 4*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 4*currentHand->getSmallBlind()) { myAction = 3; } // Standard-Raise-Routine else { // raise-Betrag ermitteln Tools::getRandNumber(1,8,1,&rand,0); - raise = rand*actualHand->getSmallBlind(); + raise = rand*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { raise = myCash; } myAction = 5; } // extrem hoher set der gegner -> bluff beenden - if(actualHand->getCurrentBeRo()->getHighestSet() >= 10*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 10*currentHand->getSmallBlind()) { myAction = 1; } } @@ -1586,13 +1586,13 @@ void LocalPlayer::flopEngine() { // cout << "sBLUFF!" << endl; Tools::getRandNumber(1,8,1,&rand,0); - bet = rand*actualHand->getSmallBlind(); + bet = rand*currentHand->getSmallBlind(); // bet zu klein - if(bet < 2*actualHand->getSmallBlind()) { - bet = 2*actualHand->getSmallBlind(); + if(bet < 2*currentHand->getSmallBlind()) { + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -1607,14 +1607,14 @@ void LocalPlayer::flopEngine() { // minimum raise setting and resetting if(myAction == 5) { - if(raise < actualHand->getCurrentBeRo()->getMinimumRaise()) { - raise = actualHand->getCurrentBeRo()->getMinimumRaise(); + if(raise < currentHand->getCurrentBeRo()->getMinimumRaise()) { + raise = currentHand->getCurrentBeRo()->getMinimumRaise(); } - actualHand->getCurrentBeRo()->setMinimumRaise(raise); + currentHand->getCurrentBeRo()->setMinimumRaise(raise); } - if(myAction == 4) { actualHand->getCurrentBeRo()->setMinimumRaise(bet); } + if(myAction == 4) { currentHand->getCurrentBeRo()->setMinimumRaise(bet); } if(DEBUG_MODE) { @@ -1623,10 +1623,10 @@ void LocalPlayer::flopEngine() { } break; case 1: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CHECK; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_CALL; // } } break; @@ -1640,7 +1640,7 @@ void LocalPlayer::flopEngine() { } break; case 2: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CHECK; // bet = 10; @@ -1648,7 +1648,7 @@ void LocalPlayer::flopEngine() { // if(mySet >= 40) { // myAction = PLAYER_ACTION_CALL; // } -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_CALL; // } } @@ -1668,11 +1668,11 @@ void LocalPlayer::flopEngine() { } break; case 3: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { // myAction = PLAYER_ACTION_BET; // bet = 80; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_CALL; // } } @@ -1693,11 +1693,11 @@ void LocalPlayer::flopEngine() { } break; case 4: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CHECK; // bet = 80; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_FOLD; // } } @@ -1718,11 +1718,11 @@ void LocalPlayer::flopEngine() { } break; case 5: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CHECK; // bet = 80; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_FOLD; // } } @@ -1766,7 +1766,7 @@ void LocalPlayer::flopEngine() { // // // for(i=0; i<2; i++) tempArray[i] = myCards[i]; -// actualBoard->getMyCards(boardCards); +// currentBoard->getMyCards(boardCards); // for(i=0; i<3; i++) tempArray[2+i] = boardCards[i]; // // for(i=0; i<4; i++) info[i] = -1; @@ -1779,7 +1779,7 @@ void LocalPlayer::flopEngine() { // flopCardsValue(tempArray); // // // aktive Situation --> check / bet -// if(actualHand->getCurrentBeRo()->getHighestSet() == 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() == 0) { // // switch(info[0]) { // case 9: {} @@ -1793,15 +1793,15 @@ void LocalPlayer::flopEngine() { // myAction = 2; // } // else { -// if(myCash/(2*actualHand->getSmallBlind()) <= 8) { +// if(myCash/(2*currentHand->getSmallBlind()) <= 8) { // myAction = 6; // } else { // if(cBluff < 60) { -// bet = (7-myDude4)*2*actualHand->getSmallBlind(); +// bet = (7-myDude4)*2*currentHand->getSmallBlind(); // } else { -// bet = (((100-cBluff)/20)+2)*actualHand->getSmallBlind(); +// bet = (((100-cBluff)/20)+2)*currentHand->getSmallBlind(); // } -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // } @@ -1815,15 +1815,15 @@ void LocalPlayer::flopEngine() { // myAction = 2; // } // else { -// if(myCash/(2*actualHand->getSmallBlind()) <= 8) { +// if(myCash/(2*currentHand->getSmallBlind()) <= 8) { // myAction = 6; // } else { // if(cBluff < 60) { -// bet = (5-myDude4)*2*actualHand->getSmallBlind(); +// bet = (5-myDude4)*2*currentHand->getSmallBlind(); // } else { -// bet = (((100-cBluff)/20)+2)*actualHand->getSmallBlind(); +// bet = (((100-cBluff)/20)+2)*currentHand->getSmallBlind(); // } -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // } @@ -1835,15 +1835,15 @@ void LocalPlayer::flopEngine() { // myAction = 2; // } // else { -// if(myCash/(2*actualHand->getSmallBlind()) <= 6) { +// if(myCash/(2*currentHand->getSmallBlind()) <= 6) { // myAction = 6; // } else { // if(cBluff < 60) { -// bet = (3-myDude4)*2*actualHand->getSmallBlind(); +// bet = (3-myDude4)*2*currentHand->getSmallBlind(); // } else { -// bet = (((100-cBluff)/20)+2)*actualHand->getSmallBlind(); +// bet = (((100-cBluff)/20)+2)*currentHand->getSmallBlind(); // } -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // } @@ -1852,8 +1852,8 @@ void LocalPlayer::flopEngine() { // default: { // Tools::getRandNumber(0,100,1,&sBluff,0); // if(info[1] >= 10 && sBluff <= 40) { -// bet = (sBluff/10)*2*actualHand->getSmallBlind(); -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// bet = (sBluff/10)*2*currentHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // else { @@ -1871,11 +1871,11 @@ void LocalPlayer::flopEngine() { // myAction = 2; // } // else { -// if(myCash/(2*actualHand->getSmallBlind()) <= 6) { +// if(myCash/(2*currentHand->getSmallBlind()) <= 6) { // myAction = 6; // } else { -// bet = (cBluff/20)*2*actualHand->getSmallBlind(); -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// bet = (cBluff/20)*2*currentHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // } @@ -1887,11 +1887,11 @@ void LocalPlayer::flopEngine() { // myAction = 2; // } // else { -// if(myCash/(2*actualHand->getSmallBlind()) <= 5) { +// if(myCash/(2*currentHand->getSmallBlind()) <= 5) { // myAction = 6; // } else { -// bet = (cBluff/30)*2*actualHand->getSmallBlind(); -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// bet = (cBluff/30)*2*currentHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // } @@ -1905,9 +1905,9 @@ void LocalPlayer::flopEngine() { // switch(info[3]) { // case 2: {} // case 1: { -// if(actualHand->getActivePlayerList().size() == 2) { -// bet = (1-myDude4)*2*actualHand->getSmallBlind(); -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// if(currentHand->getActivePlayerList().size() == 2) { +// bet = (1-myDude4)*2*currentHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // // } @@ -1915,7 +1915,7 @@ void LocalPlayer::flopEngine() { // switch(info[1]) { // case 3: { // if(sBluff <= 10) { -// bet = (sBluff/5 + 2)*actualHand->getSmallBlind(); +// bet = (sBluff/5 + 2)*currentHand->getSmallBlind(); // myAction = 4; // } // else { @@ -1925,7 +1925,7 @@ void LocalPlayer::flopEngine() { // break; // case 2: { // if(sBluff <= 15) { -// bet = (sBluff/5 + 2)*actualHand->getSmallBlind(); +// bet = (sBluff/5 + 2)*currentHand->getSmallBlind(); // myAction = 4; // } // else { @@ -1935,7 +1935,7 @@ void LocalPlayer::flopEngine() { // break; // case 1: { // if(sBluff <= 50) { -// bet = (sBluff/15 + 2)*actualHand->getSmallBlind(); +// bet = (sBluff/15 + 2)*currentHand->getSmallBlind(); // myAction = 4; // } // else { @@ -1944,11 +1944,11 @@ void LocalPlayer::flopEngine() { // } // break; // default: { -// if(myCash/(2*actualHand->getSmallBlind()) <= 5) { +// if(myCash/(2*currentHand->getSmallBlind()) <= 5) { // myAction = 6; // } else { -// bet = (sBluff/15)*2*actualHand->getSmallBlind(); -// if(bet < 2*actualHand->getSmallBlind()) bet = 2*actualHand->getSmallBlind(); +// bet = (sBluff/15)*2*currentHand->getSmallBlind(); +// if(bet < 2*currentHand->getSmallBlind()) bet = 2*currentHand->getSmallBlind(); // myAction = 4; // } // } @@ -2004,7 +2004,7 @@ void LocalPlayer::turnEngine() { // int i; // for(i=0; i<2; i++) tempArray[i] = myCards[i]; -// actualBoard->getMyCards(boardCards); +// currentBoard->getMyCards(boardCards); // for(i=0; i<4; i++) tempArray[2+i] = boardCards[i]; // for(i=0; i<5; i++) cout << tempArray[i] << " "; @@ -2026,16 +2026,16 @@ void LocalPlayer::turnEngine() { // Niveaus setzen + Dude + Anzahl Gegenspieler // 1. Fold -- Call - myNiveau[0] = 53 + myDude4/* - 6*(actualHand->getActivePlayerList().size() - 2)*/; + myNiveau[0] = 53 + myDude4/* - 6*(currentHand->getActivePlayerList().size() - 2)*/; // 2. Check -- Bet - myNiveau[1] = 56 + myDude4/* - 6*(actualHand->getActivePlayerList().size() - 2)*/; + myNiveau[1] = 56 + myDude4/* - 6*(currentHand->getActivePlayerList().size() - 2)*/; // 3. Call -- Raise - myNiveau[2] = 69 + myDude4/* - 6*(actualHand->getActivePlayerList().size() - 2)*/; + myNiveau[2] = 69 + myDude4/* - 6*(currentHand->getActivePlayerList().size() - 2)*/; // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist -// int aggValue = (int)(((actualHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); +// int aggValue = (int)(((currentHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); // -// if(actualHand->getPlayerArray()[0]->getMyActiveStatus() && actualHand->getPlayerArray()[0]->getMyAction() != 1) { +// if(currentHand->getPlayerArray()[0]->getMyActiveStatus() && currentHand->getPlayerArray()[0]->getMyAction() != 1) { // for(i=0; i<3; i++) { // myNiveau[i] -= aggValue; // } @@ -2044,10 +2044,10 @@ void LocalPlayer::turnEngine() { // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist ! - it_c = actualHand->getActivePlayerIt(0); - if( it_c != actualHand->getActivePlayerList()->end() ) { + it_c = currentHand->getActivePlayerIt(0); + if( it_c != currentHand->getActivePlayerList()->end() ) { if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD ) { - int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); + int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); for(i=0; i<3; i++) { myNiveau[i] -= aggValue; } @@ -2061,14 +2061,14 @@ void LocalPlayer::turnEngine() { // eigenes mögliches highestSet - int individualHighestSet = actualHand->getCurrentBeRo()->getHighestSet(); + int individualHighestSet = currentHand->getCurrentBeRo()->getHighestSet(); if(individualHighestSet > myCash) individualHighestSet = myCash; // Check-Bluff generieren Tools::getRandNumber(1,100,1,&cBluff,0); // aktiv oder passiv? - if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // Verhaeltnis Set / Cash if(myCash/individualHighestSet >= 25) { @@ -2086,7 +2086,7 @@ void LocalPlayer::turnEngine() { if(myOdds >= myNiveau[2]) { // raise-loop unterbinden -> d.h. entweder call oder bei superblatt all in - if(actualHand->getCurrentBeRo()->getHighestSet() >= 12*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 12*currentHand->getSmallBlind()) { // all in if(myOdds >= myNiveau[2] + 15) { raise = myCash; @@ -2095,7 +2095,7 @@ void LocalPlayer::turnEngine() { // nur call else { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { raise = myCash; myAction = 5; } else { @@ -2106,13 +2106,13 @@ void LocalPlayer::turnEngine() { // Standard-Raise-Routine } else { // raise-Betrag ermitteln - raise = (((int)myOdds-myNiveau[2])/4)*2*actualHand->getSmallBlind(); + raise = (((int)myOdds-myNiveau[2])/4)*2*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4.0)/5.0) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4.0)/5.0) { raise = myCash; } myAction = 5; @@ -2125,9 +2125,9 @@ void LocalPlayer::turnEngine() { } else { // call -> über niveau0, schon einiges gesetzt im flop, schon einiges insgesamt gesetzt - if(myOdds >= myNiveau[0] || (mySet >= actualHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-5) || (myRoundStartCash-myCash > individualHighestSet && myNiveau[0]-3)) { + if(myOdds >= myNiveau[0] || (mySet >= currentHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-5) || (myRoundStartCash-myCash > individualHighestSet && myNiveau[0]-3)) { // all in bei knappem call - if(actualHand->getCurrentBeRo()->getHighestSet() > (myCash*3.0)/4.0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > (myCash*3.0)/4.0) { raise = myCash; myAction = 5; } @@ -2143,12 +2143,12 @@ void LocalPlayer::turnEngine() { else { // bet if(myOdds >= myNiveau[1]) { - bet = (((int)myOdds-myNiveau[1])/6)*2*actualHand->getSmallBlind(); + bet = (((int)myOdds-myNiveau[1])/6)*2*currentHand->getSmallBlind(); if(bet == 0) { - bet = 2*actualHand->getSmallBlind(); + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -2171,13 +2171,13 @@ void LocalPlayer::turnEngine() { // Position-Bluff generieren Tools::getRandNumber(1,100,1,&pBluff,0); if(pBluff <= 16) { - bet = (pBluff/4)*2*actualHand->getSmallBlind(); + bet = (pBluff/4)*2*currentHand->getSmallBlind(); // bet zu klein if(bet == 0) { - bet = 2*actualHand->getSmallBlind(); + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -2193,34 +2193,34 @@ void LocalPlayer::turnEngine() { // auf sBluffStatus testen --> raise statt call und bet statt check // aktiv oder passiv? - if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { if(sBluffStatus && myOdds < myNiveau[2]) { // cout << "sBLUFF!" << endl; // Gegner setzen -> call - if(actualHand->getCurrentBeRo()->getHighestSet() >= 4*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 4*currentHand->getSmallBlind()) { myAction = 3; } // Standard-Raise-Routine else { // raise-Betrag ermitteln Tools::getRandNumber(1,8,1,&rand,0); - raise = rand*actualHand->getSmallBlind(); + raise = rand*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { raise = myCash; } myAction = 5; } // extrem hoher set der gegner -> bluff beenden - if(actualHand->getCurrentBeRo()->getHighestSet() >= 10*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 10*currentHand->getSmallBlind()) { myAction = 1; } } @@ -2231,13 +2231,13 @@ void LocalPlayer::turnEngine() { // cout << "sBLUFF!" << endl; Tools::getRandNumber(1,8,1,&rand,0); - bet = rand*actualHand->getSmallBlind(); + bet = rand*currentHand->getSmallBlind(); // bet zu klein - if(bet < 2*actualHand->getSmallBlind()) { - bet = 2*actualHand->getSmallBlind(); + if(bet < 2*currentHand->getSmallBlind()) { + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -2252,14 +2252,14 @@ void LocalPlayer::turnEngine() { // minimum raise setting and resetting if(myAction == 5) { - if(raise < actualHand->getCurrentBeRo()->getMinimumRaise()) { - raise = actualHand->getCurrentBeRo()->getMinimumRaise(); + if(raise < currentHand->getCurrentBeRo()->getMinimumRaise()) { + raise = currentHand->getCurrentBeRo()->getMinimumRaise(); } - actualHand->getCurrentBeRo()->setMinimumRaise(raise); + currentHand->getCurrentBeRo()->setMinimumRaise(raise); } - if(myAction == 4) { actualHand->getCurrentBeRo()->setMinimumRaise(bet); } + if(myAction == 4) { currentHand->getCurrentBeRo()->setMinimumRaise(bet); } if(DEBUG_MODE) { @@ -2271,10 +2271,10 @@ void LocalPlayer::turnEngine() { break; case 1: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_FOLD; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 100) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 100) { // myAction = PLAYER_ACTION_FOLD; // } } @@ -2291,12 +2291,12 @@ void LocalPlayer::turnEngine() { break; case 2: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_BET; // raise = 40; bet = 40; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 100) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 100) { // myAction = PLAYER_ACTION_CALL; // } } @@ -2316,11 +2316,11 @@ void LocalPlayer::turnEngine() { } break; case 3: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { // myAction = PLAYER_ACTION_FOLD; // bet = 10; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_CALL; // } } @@ -2341,11 +2341,11 @@ void LocalPlayer::turnEngine() { } break; case 4: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CALL; // bet = 10; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_CALL; // } } @@ -2366,11 +2366,11 @@ void LocalPlayer::turnEngine() { } break; case 5: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_CALL; // bet = 10; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_CALL; // } } @@ -2408,7 +2408,7 @@ void LocalPlayer::riverEngine() { // int i; // for(i=0; i<2; i++) tempArray[i] = myCards[i]; -// actualBoard->getMyCards(boardCards); +// currentBoard->getMyCards(boardCards); // for(i=0; i<4; i++) tempArray[2+i] = boardCards[i]; // for(i=0; i<5; i++) cout << tempArray[i] << " "; @@ -2430,16 +2430,16 @@ void LocalPlayer::riverEngine() { // Niveaus setzen + Dude + Anzahl Gegenspieler // 1. Fold -- Call - myNiveau[0] = 53 + myDude4/* - 6*(actualHand->getActivePlayerList().size() - 2)*/; + myNiveau[0] = 53 + myDude4/* - 6*(currentHand->getActivePlayerList().size() - 2)*/; // 2. Check -- Bet - myNiveau[1] = 56 + myDude4/* - 6*(actualHand->getActivePlayerList().size() - 2)*/; + myNiveau[1] = 56 + myDude4/* - 6*(currentHand->getActivePlayerList().size() - 2)*/; // 3. Call -- Raise - myNiveau[2] = 69 + myDude4/* - 6*(actualHand->getActivePlayerList().size() - 2)*/; + myNiveau[2] = 69 + myDude4/* - 6*(currentHand->getActivePlayerList().size() - 2)*/; // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist -// int aggValue = (int)(((actualHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); +// int aggValue = (int)(((currentHand->getPlayerArray()[0]->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); // -// if(actualHand->getPlayerArray()[0]->getMyActiveStatus() && actualHand->getPlayerArray()[0]->getMyAction() != 1) { +// if(currentHand->getPlayerArray()[0]->getMyActiveStatus() && currentHand->getPlayerArray()[0]->getMyAction() != 1) { // for(i=0; i<3; i++) { // myNiveau[i] -= aggValue; // } @@ -2447,10 +2447,10 @@ void LocalPlayer::riverEngine() { // Aggresivität des humanPlayers auslesen -> nur wenn er aktiv ist ! - it_c = actualHand->getActivePlayerIt(0); - if( it_c != actualHand->getActivePlayerList()->end() ) { + it_c = currentHand->getActivePlayerIt(0); + if( it_c != currentHand->getActivePlayerList()->end() ) { if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD ) { - int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/actualHand->getActivePlayerList()->size())*21.0); + int aggValue = (int)((( (*it_c)->getMyAggressive()*1.0)/7.0 - 1.0/currentHand->getActivePlayerList()->size())*21.0); for(i=0; i<3; i++) { myNiveau[i] -= aggValue; } @@ -2463,11 +2463,11 @@ void LocalPlayer::riverEngine() { // cout << "Spieler " << myID << ": Dude " << myDude4 << "\t Wert " << myHoleCardsValue << "\t Niveau " << myNiveau[0] << " " << myNiveau[1] << " " << myNiveau[2] << "\t Agg " << aggValue << " " << endl; // eigenes mögliches highestSet - int individualHighestSet = actualHand->getCurrentBeRo()->getHighestSet(); + int individualHighestSet = currentHand->getCurrentBeRo()->getHighestSet(); if(individualHighestSet > myCash) individualHighestSet = myCash; // aktiv oder passiv? - if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // Verhaeltnis Set / Cash if(myCash/individualHighestSet >= 25) { @@ -2484,7 +2484,7 @@ void LocalPlayer::riverEngine() { // raise (bei hohem Niveau) if(myOdds >= myNiveau[2]) { // raise-loop unterbinden -> d.h. entweder call oder bei superblatt all in - if(actualHand->getCurrentBeRo()->getHighestSet() >= 12*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 12*currentHand->getSmallBlind()) { // all in if(myOdds >= myNiveau[2] + 15) { raise = myCash; @@ -2493,7 +2493,7 @@ void LocalPlayer::riverEngine() { // nur call else { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/5) { raise = myCash; myAction = 5; } else { @@ -2504,13 +2504,13 @@ void LocalPlayer::riverEngine() { // Standard-Raise-Routine else { // raise-Betrag ermitteln - raise = (((int)myOdds-myNiveau[2])/2)*2*actualHand->getSmallBlind(); + raise = (((int)myOdds-myNiveau[2])/2)*2*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 8) { + if(myCash/(2*currentHand->getSmallBlind()) <= 8) { raise = myCash; } myAction = 5; @@ -2518,9 +2518,9 @@ void LocalPlayer::riverEngine() { } else { // call -> über niveau0, schon einiges gesetzt im flop, schon einiges insgesamt gesetzt - if(myOdds >= myNiveau[0] || (mySet >= actualHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-5) || (myRoundStartCash-myCash > individualHighestSet && myNiveau[0]-3)) { + if(myOdds >= myNiveau[0] || (mySet >= currentHand->getCurrentBeRo()->getHighestSet()/2 && myOdds >= myNiveau[0]-5) || (myRoundStartCash-myCash > individualHighestSet && myNiveau[0]-3)) { // all in bei knappem call - if(myCash-actualHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/4) { + if(myCash-currentHand->getCurrentBeRo()->getHighestSet() <= (myCash*1)/4) { raise = myCash; myAction = 5; } @@ -2535,12 +2535,12 @@ void LocalPlayer::riverEngine() { else { // bet if(myOdds >= myNiveau[1]) { - bet = (((int)myOdds-myNiveau[1])/3)*2*actualHand->getSmallBlind(); + bet = (((int)myOdds-myNiveau[1])/3)*2*currentHand->getSmallBlind(); if(bet == 0) { - bet = 2*actualHand->getSmallBlind(); + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { raise = myCash; } // all in bei knappem bet @@ -2557,13 +2557,13 @@ void LocalPlayer::riverEngine() { // Position-Bluff generieren Tools::getRandNumber(1,100,1,&pBluff,0); if(pBluff <= 20) { - bet = (pBluff/4)*2*actualHand->getSmallBlind(); + bet = (pBluff/4)*2*currentHand->getSmallBlind(); // bet zu klein if(bet == 0) { - bet = 2*actualHand->getSmallBlind(); + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -2576,41 +2576,41 @@ void LocalPlayer::riverEngine() { } // lastPlayerAction für Karten umblättern reihenfolge setzrn - actualHand->getCurrentBeRo()->setLastActionPlayer(myID); + currentHand->getCurrentBeRo()->setLastActionPlayer(myID); } // auf sBluffStatus testen --> raise statt call und bet statt check // aktiv oder passiv? - if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { if(sBluffStatus && myOdds < myNiveau[2]) { // cout << "sBLUFF!" << endl; // Gegner setzen -> call - if(actualHand->getCurrentBeRo()->getHighestSet() >= 4*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 4*currentHand->getSmallBlind()) { myAction = 3; } // Standard-Raise-Routine else { // raise-Betrag ermitteln Tools::getRandNumber(1,8,1,&rand,0); - raise = rand*actualHand->getSmallBlind(); + raise = rand*currentHand->getSmallBlind(); // raise-Betrag zu klein -> mindestens Standard-raise -// if(raise < actualHand->getCurrentBeRo()->getHighestSet()) { -// raise = actualHand->getCurrentBeRo()->getHighestSet(); +// if(raise < currentHand->getCurrentBeRo()->getHighestSet()) { +// raise = currentHand->getCurrentBeRo()->getHighestSet(); // } // all in bei nur wenigen Chips oder knappem raise - if(myCash/(2*actualHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6 || raise >= (myCash*4)/5) { raise = myCash; } myAction = 5; } // extrem hoher set der gegner -> bluff beenden - if(actualHand->getCurrentBeRo()->getHighestSet() >= 10*actualHand->getSmallBlind()) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= 10*currentHand->getSmallBlind()) { myAction = 1; } } @@ -2621,13 +2621,13 @@ void LocalPlayer::riverEngine() { // cout << "sBLUFF!" << endl; Tools::getRandNumber(1,8,1,&rand,0); - bet = rand*actualHand->getSmallBlind(); + bet = rand*currentHand->getSmallBlind(); // bet zu klein - if(bet < 2*actualHand->getSmallBlind()) { - bet = 2*actualHand->getSmallBlind(); + if(bet < 2*currentHand->getSmallBlind()) { + bet = 2*currentHand->getSmallBlind(); } // all in bei nur wenigen Chips - if(myCash/(2*actualHand->getSmallBlind()) <= 6) { + if(myCash/(2*currentHand->getSmallBlind()) <= 6) { bet = myCash; } // all in bei knappem bet @@ -2642,14 +2642,14 @@ void LocalPlayer::riverEngine() { // minimum raise setting and resetting if(myAction == 5) { - if(raise < actualHand->getCurrentBeRo()->getMinimumRaise()) { - raise = actualHand->getCurrentBeRo()->getMinimumRaise(); + if(raise < currentHand->getCurrentBeRo()->getMinimumRaise()) { + raise = currentHand->getCurrentBeRo()->getMinimumRaise(); } - actualHand->getCurrentBeRo()->setMinimumRaise(raise); + currentHand->getCurrentBeRo()->setMinimumRaise(raise); } - if(myAction == 4) { actualHand->getCurrentBeRo()->setMinimumRaise(bet); } + if(myAction == 4) { currentHand->getCurrentBeRo()->setMinimumRaise(bet); } if(DEBUG_MODE) { @@ -2658,10 +2658,10 @@ void LocalPlayer::riverEngine() { } break; case 1: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { // myAction = PLAYER_ACTION_CALL; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 100) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 100) { // myAction = PLAYER_ACTION_FOLD; // } } break; @@ -2675,12 +2675,12 @@ void LocalPlayer::riverEngine() { } break; case 2: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_BET; bet = 100; // raise = 40; - if(actualHand->getCurrentBeRo()->getHighestSet() > 100) { + if(currentHand->getCurrentBeRo()->getHighestSet() > 100) { myAction = PLAYER_ACTION_CALL; } } @@ -2700,11 +2700,11 @@ void LocalPlayer::riverEngine() { } break; case 3: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { // myAction = PLAYER_ACTION_BET; // bet = 120; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_RAISE; // raise = 10000; // } @@ -2726,12 +2726,12 @@ void LocalPlayer::riverEngine() { } break; case 4: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_RAISE; raise = 300; // bet = 120; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_RAISE; // raise = 10000; // } @@ -2753,11 +2753,11 @@ void LocalPlayer::riverEngine() { } break; case 5: { - switch(actualHand->getMyID()) { + switch(currentHand->getMyID()) { case 1: { myAction = PLAYER_ACTION_FOLD; // bet = 120; -// if(actualHand->getCurrentBeRo()->getHighestSet() > 0) { +// if(currentHand->getCurrentBeRo()->getHighestSet() > 0) { // myAction = PLAYER_ACTION_RAISE; // raise = 10000; // } @@ -2796,7 +2796,7 @@ void LocalPlayer::evaluation(int bet, int raise) { int highestSet = 0; - highestSet = actualHand->getCurrentBeRo()->getHighestSet(); + highestSet = currentHand->getCurrentBeRo()->getHighestSet(); // cout << "myAction(evaluation): " << myAction << endl; @@ -2871,7 +2871,7 @@ void LocalPlayer::evaluation(int bet, int raise) { // cout << "highestSet(ende evaluation): " << highestSet << endl; - actualHand->getCurrentBeRo()->setHighestSet(highestSet); + currentHand->getCurrentBeRo()->setHighestSet(highestSet); } @@ -3546,14 +3546,14 @@ void LocalPlayer::calcMyOdds() { int handCode; - switch(actualHand->getActualRound()) { + switch(currentHand->getCurrentRound()) { case 0: { handCode = preflopCardsValue(myCards); // übergang solange preflopValue und flopValue noch nicht bereinigt - int players = actualHand->getActivePlayerList()->size(); + int players = currentHand->getActivePlayerList()->size(); if(players > 5) players = 5; // paranoia if(players < 2) players = 2; @@ -3576,7 +3576,7 @@ void LocalPlayer::calcMyOdds() { int i; for(i=0; i<2; i++) tempArray[i] = myCards[i]; - actualBoard->getMyCards(boardCards); + currentBoard->getMyCards(boardCards); for(i=0; i<3; i++) tempArray[2+i] = boardCards[i]; // cout << myID << ": "; @@ -3586,7 +3586,7 @@ void LocalPlayer::calcMyOdds() { // cout << "\t" << handCode << endl; // übergang solange preflopValue und flopValue noch nicht bereinigt - int players = actualHand->getActivePlayerList()->size(); + int players = currentHand->getActivePlayerList()->size(); if(players > 5) players = 5; // paranoia if(players < 2) players = 2; @@ -3619,7 +3619,7 @@ void LocalPlayer::calcMyOdds() { int tempBoardCardsArray[5]; int tempMyCardsArray[7]; int tempOpponentCardsArray[7]; - actualBoard->getMyCards(tempBoardCardsArray); + currentBoard->getMyCards(tempBoardCardsArray); tempMyCardsArray[0] = myCards[0]; tempMyCardsArray[1] = myCards[1]; @@ -3675,7 +3675,7 @@ void LocalPlayer::calcMyOdds() { int tempBoardCardsArray[5]; int tempMyCardsArray[7]; int tempOpponentCardsArray[7]; - actualBoard->getMyCards(tempBoardCardsArray); + currentBoard->getMyCards(tempBoardCardsArray); tempMyCardsArray[0] = myCards[0]; tempMyCardsArray[1] = myCards[1]; @@ -3719,7 +3719,7 @@ void LocalPlayer::calcMyOdds() { } break; - default: cout <<"ERROR - wrong init of actualRound" << endl; + default: cout <<"ERROR - wrong init of currentRound" << endl; } @@ -3990,7 +3990,7 @@ int LocalPlayer::turnCardsValue(int* cards) { void LocalPlayer::preflopEngine3() { - // cout << "nextID " << actualHand->getPlayerArray()[(myID+1)%5]->getMyID() << endl; + // cout << "nextID " << currentHand->getPlayerArray()[(myID+1)%5]->getMyID() << endl; int raise = 0; @@ -4007,32 +4007,32 @@ void LocalPlayer::preflopEngine3() { // Potential int potential = 10*(4*(myCardsValue->holeCardsClass(myCards[0], myCards[1]))+1*tempRand)/50-myDude; - int setToHighest = actualHand->getCurrentBeRo()->getHighestSet() - mySet; + int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet; // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; - // tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(8*actualHand->getSmallBlind()); + // tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(8*currentHand->getSmallBlind()); Tools::getRandNumber(2,3,1,&tempFold,0); // FOLD --> wenn Potential negativ oder HighestSet zu hoch - if( (potential*setToHighest<0 || (setToHighest > tempFold * actualHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * actualHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * actualHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * actualHand->getSmallBlind() && potential<4)) && myCardsValue->holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) { + if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 2 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 4 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 10 * tempFold * currentHand->getSmallBlind() && potential<4)) && myCardsValue->holeCardsClass(myCards[0], myCards[1]) < 9 && bluff > 15) { myAction=1; } else { // RAISE --> wenn hohes Potential - if(potential >= 4 && 6 * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet() || bluff <= 6) { + if(potential >= 4 && 6 * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet() || bluff <= 6) { // extrem hohes Potential --> groᅵr Raise if(potential>=6 || bluff <= 2) { // bluff - raise - if(bluff <=2 && 4 * actualHand->getSmallBlind() > actualHand->getCurrentBeRo()->getHighestSet()) { - raise = 3 * actualHand->getCurrentBeRo()->getHighestSet(); + if(bluff <=2 && 4 * currentHand->getSmallBlind() > currentHand->getCurrentBeRo()->getHighestSet()) { + raise = 3 * currentHand->getCurrentBeRo()->getHighestSet(); } else { // bluff - call if(bluff >= 98) { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4041,16 +4041,16 @@ void LocalPlayer::preflopEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } else { // doch nich raisen, sondern nur checken, weil highestSets bereits sehr hoch !!! - if(! (4 * actualHand->getSmallBlind() > actualHand->getCurrentBeRo()->getHighestSet())) { + if(! (4 * currentHand->getSmallBlind() > currentHand->getCurrentBeRo()->getHighestSet())) { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4059,28 +4059,28 @@ void LocalPlayer::preflopEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } - else raise = (potential - 4 ) * 2 * actualHand->getCurrentBeRo()->getHighestSet(); + else raise = (potential - 4 ) * 2 * currentHand->getCurrentBeRo()->getHighestSet(); } } } // hohes Potential --> gemäßigter Raise else { // bluff - raise - if(bluff <= 6 && 4 * actualHand->getSmallBlind() > actualHand->getCurrentBeRo()->getHighestSet()) { - raise = 2*actualHand->getCurrentBeRo()->getHighestSet(); + if(bluff <= 6 && 4 * currentHand->getSmallBlind() > currentHand->getCurrentBeRo()->getHighestSet()) { + raise = 2*currentHand->getCurrentBeRo()->getHighestSet(); } else { // bluff - call if(bluff >= 93) { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4089,17 +4089,17 @@ void LocalPlayer::preflopEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } else { // doch nich raisen, sondern nur checken, weil highestSets bereits sehr hoch !!! - if(! (4 * actualHand->getSmallBlind() > actualHand->getCurrentBeRo()->getHighestSet())) { + if(! (4 * currentHand->getSmallBlind() > currentHand->getCurrentBeRo()->getHighestSet())) { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4108,32 +4108,32 @@ void LocalPlayer::preflopEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } - else raise = (potential - 3 ) * actualHand->getCurrentBeRo()->getHighestSet(); + else raise = (potential - 3 ) * currentHand->getCurrentBeRo()->getHighestSet(); } } } if (raise > 0) { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { mySet += myCash; myCash = 0; myAction = 6; - if(mySet > actualHand->getCurrentBeRo()->getHighestSet()) actualHand->getCurrentBeRo()->setHighestSet(mySet); + if(mySet > currentHand->getCurrentBeRo()->getHighestSet()) currentHand->getCurrentBeRo()->setHighestSet(mySet); } // sonst else { - myCash = myCash + mySet - actualHand->getCurrentBeRo()->getHighestSet() - raise; - mySet = actualHand->getCurrentBeRo()->getHighestSet() + raise; - actualHand->getCurrentBeRo()->setHighestSet(mySet); + myCash = myCash + mySet - currentHand->getCurrentBeRo()->getHighestSet() - raise; + mySet = currentHand->getCurrentBeRo()->getHighestSet() + raise; + currentHand->getCurrentBeRo()->setHighestSet(mySet); myAction = 5; } } @@ -4141,13 +4141,13 @@ void LocalPlayer::preflopEngine3() { //CHECK und CALL else { // CHECK --> wenn alle Sets glieich bei BigBlind und nich zu hohem Potential - if(mySet == actualHand->getCurrentBeRo()->getHighestSet()) { + if(mySet == currentHand->getCurrentBeRo()->getHighestSet()) { myAction = 2; } // CALL --> bei normalen Potential else { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4156,8 +4156,8 @@ void LocalPlayer::preflopEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } @@ -4173,7 +4173,7 @@ void LocalPlayer::flopEngine3() { int tempBoardCardsArray[5]; int tempMyCardsArray[7]; int tempOpponentCardsArray[7]; - actualBoard->getMyCards(tempBoardCardsArray); + currentBoard->getMyCards(tempBoardCardsArray); tempMyCardsArray[0] = myCards[0]; tempMyCardsArray[1] = myCards[1]; @@ -4240,20 +4240,20 @@ void LocalPlayer::flopEngine3() { // Potential int potential = (10*(5*(int)(percent*100.)+10*tempRand*2))/700-myDude; - int setToHighest = actualHand->getCurrentBeRo()->getHighestSet() - mySet; + int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet; // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; - // tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(8*actualHand->getSmallBlind()); + // tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(8*currentHand->getSmallBlind()); Tools::getRandNumber(2,3,1,&tempFold,0); // FOLD --> wenn potential negativ oder HighestSet zu hoch - if(( potential*setToHighest<0 || (setToHighest > tempFold * actualHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * actualHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * actualHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * actualHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * actualHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 18) { + if(( potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * currentHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * currentHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 18) { myAction=1; } else { // CHECK und BET --> wenn noch keiner was gesetzt hat - if(actualHand->getCurrentBeRo()->getHighestSet() == 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() == 0) { // CHECK --> wenn Potential klein oder check-bluff sonst bet oder bet-bluff if((potential<3 || bluff >= 80) && bluff > 15) { // check @@ -4261,11 +4261,11 @@ void LocalPlayer::flopEngine3() { } // BET --> wenn Potential hoch else { - if(bluff <= 5) mySet = (bluff+1) * actualHand->getSmallBlind(); + if(bluff <= 5) mySet = (bluff+1) * currentHand->getSmallBlind(); else { - if(bluff <=15 ) mySet = 4 * actualHand->getSmallBlind(); + if(bluff <=15 ) mySet = 4 * currentHand->getSmallBlind(); // je höher das Potential, desto höher der Einsatz (zur Basis SmallBlind) - else mySet = (potential-1) * 2 * actualHand->getSmallBlind(); + else mySet = (potential-1) * 2 * currentHand->getSmallBlind(); } // All In @@ -4280,35 +4280,35 @@ void LocalPlayer::flopEngine3() { myCash -= mySet; myAction = 4; } - actualHand->getCurrentBeRo()->setHighestSet(mySet); + currentHand->getCurrentBeRo()->setHighestSet(mySet); } } // CALL und RAISE --> wenn bereits gesetzt wurde else { // RAISE --> wenn Potential besonders gut - if((potential >=4 && 2 * tempFold * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet()) || (bluff <= 5 && 4 * tempFold * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet())) { + if((potential >=4 && 2 * tempFold * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet()) || (bluff <= 5 && 4 * tempFold * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet())) { // bluff - raise - if(bluff <=5) raise = ((bluff+1)/2) * actualHand->getCurrentBeRo()->getHighestSet(); + if(bluff <=5) raise = ((bluff+1)/2) * currentHand->getCurrentBeRo()->getHighestSet(); // Betrag, der ber dem aktuell HighestSet gesetzt werden soll - else raise = ((potential - 2 ) / 2) * actualHand->getCurrentBeRo()->getHighestSet(); + else raise = ((potential - 2 ) / 2) * currentHand->getCurrentBeRo()->getHighestSet(); // All In - if(actualHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { mySet += myCash; myCash = 0; myAction = 6; - if(mySet > actualHand->getCurrentBeRo()->getHighestSet()) actualHand->getCurrentBeRo()->setHighestSet(mySet); + if(mySet > currentHand->getCurrentBeRo()->getHighestSet()) currentHand->getCurrentBeRo()->setHighestSet(mySet); } // sonst else { - myCash = myCash + mySet - actualHand->getCurrentBeRo()->getHighestSet() - raise; - mySet = actualHand->getCurrentBeRo()->getHighestSet() + raise; - actualHand->getCurrentBeRo()->setHighestSet(mySet); + myCash = myCash + mySet - currentHand->getCurrentBeRo()->getHighestSet() - raise; + mySet = currentHand->getCurrentBeRo()->getHighestSet() + raise; + currentHand->getCurrentBeRo()->setHighestSet(mySet); myAction = 5; } } @@ -4316,7 +4316,7 @@ void LocalPlayer::flopEngine3() { else { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4325,8 +4325,8 @@ void LocalPlayer::flopEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } @@ -4344,7 +4344,7 @@ void LocalPlayer::turnEngine3() { int tempBoardCardsArray[5]; int tempMyCardsArray[7]; int tempOpponentCardsArray[7]; - actualBoard->getMyCards(tempBoardCardsArray); + currentBoard->getMyCards(tempBoardCardsArray); tempMyCardsArray[0] = myCards[0]; tempMyCardsArray[1] = myCards[1]; @@ -4406,21 +4406,21 @@ void LocalPlayer::turnEngine3() { // Potential int potential = (10*(5*(int)(percent*100.)+10*tempRand*2))/700-myDude; - int setToHighest = actualHand->getCurrentBeRo()->getHighestSet() - mySet; + int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet; // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; - // tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(7*actualHand->getSmallBlind()); + // tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(7*currentHand->getSmallBlind()); Tools::getRandNumber(3,4,1,&tempFold,0); // FOLD // --> wenn potential negativ oder HighestSet zu hoch - if( (potential*setToHighest<0 || (setToHighest > tempFold * actualHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * actualHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * actualHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * actualHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * actualHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 15) { + if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * currentHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * currentHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 15) { myAction=1; } else { // CHECK und BET --> wenn noch keiner was gesetzt hat - if(actualHand->getCurrentBeRo()->getHighestSet() == 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() == 0) { // CHECK --> wenn Potential klein if((potential<2 || bluff >= 80) && bluff > 10) { // check @@ -4429,11 +4429,11 @@ void LocalPlayer::turnEngine3() { // BET --> wenn Potential hoch else { - if(bluff <= 3) mySet = bluff * 2 * actualHand->getSmallBlind(); + if(bluff <= 3) mySet = bluff * 2 * currentHand->getSmallBlind(); else { - if(bluff <=10 ) mySet = ((bluff+2)/3) * actualHand->getSmallBlind(); + if(bluff <=10 ) mySet = ((bluff+2)/3) * currentHand->getSmallBlind(); // je hᅵer das Potential, desto hᅵher der Einsatz (zur Basis SmallBlind) - else mySet = (potential-1) * 3 * actualHand->getSmallBlind(); + else mySet = (potential-1) * 3 * currentHand->getSmallBlind(); } // All In @@ -4448,42 +4448,42 @@ void LocalPlayer::turnEngine3() { myCash -= mySet; myAction = 4; } - actualHand->getCurrentBeRo()->setHighestSet(mySet); + currentHand->getCurrentBeRo()->setHighestSet(mySet); } } // CALL und RAISE --> wenn bereits gesetzt wurde else { // RAISE --> wenn Potential besonders gut - if(potential >=4 && 2 * tempFold * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet() || (bluff <= 4 && 3 * tempFold * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet())) { + if(potential >=4 && 2 * tempFold * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet() || (bluff <= 4 && 3 * tempFold * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet())) { // bluff - raise - if(bluff <= 4) raise = ((bluff+1)/2) * actualHand->getCurrentBeRo()->getHighestSet(); + if(bluff <= 4) raise = ((bluff+1)/2) * currentHand->getCurrentBeRo()->getHighestSet(); // Betrag, der ber dem aktuell HighestSet gesetzt werden soll - else raise = ( potential - 3 ) * actualHand->getCurrentBeRo()->getHighestSet(); + else raise = ( potential - 3 ) * currentHand->getCurrentBeRo()->getHighestSet(); // All In - if(actualHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { mySet += myCash; myCash = 0; myAction = 6; - if(mySet > actualHand->getCurrentBeRo()->getHighestSet()) actualHand->getCurrentBeRo()->setHighestSet(mySet); + if(mySet > currentHand->getCurrentBeRo()->getHighestSet()) currentHand->getCurrentBeRo()->setHighestSet(mySet); } // sonst else { - myCash = myCash + mySet - actualHand->getCurrentBeRo()->getHighestSet() - raise; - mySet = actualHand->getCurrentBeRo()->getHighestSet() + raise; - actualHand->getCurrentBeRo()->setHighestSet(mySet); + myCash = myCash + mySet - currentHand->getCurrentBeRo()->getHighestSet() - raise; + mySet = currentHand->getCurrentBeRo()->getHighestSet() + raise; + currentHand->getCurrentBeRo()->setHighestSet(mySet); myAction = 5; } } // CALL --> bei normalen Potential else { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4492,8 +4492,8 @@ void LocalPlayer::turnEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } @@ -4510,7 +4510,7 @@ void LocalPlayer::riverEngine3() { int tempBoardCardsArray[5]; int tempMyCardsArray[7]; int tempOpponentCardsArray[7]; - actualBoard->getMyCards(tempBoardCardsArray); + currentBoard->getMyCards(tempBoardCardsArray); tempMyCardsArray[0] = myCards[0]; tempMyCardsArray[1] = myCards[1]; @@ -4568,21 +4568,21 @@ void LocalPlayer::riverEngine3() { // Potential int potential = (10*(5*(int)(percent*100.)+10*tempRand*1))/600-myDude; - int setToHighest = actualHand->getCurrentBeRo()->getHighestSet() - mySet; + int setToHighest = currentHand->getCurrentBeRo()->getHighestSet() - mySet; // temp fr das Vielfache des Small Blind, sodass HighestSet zu hoch ist int tempFold; -// tempFold = (actualHand->getPlayerArray()[0]->getMyAverageSets())/(6*actualHand->getSmallBlind()); +// tempFold = (currentHand->getPlayerArray()[0]->getMyAverageSets())/(6*currentHand->getSmallBlind()); Tools::getRandNumber(4,6,1,&tempFold,0); // FOLD // --> wenn potential negativ oder HighestSet zu hoch - if( (potential*setToHighest<0 || (setToHighest > tempFold * actualHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * actualHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * actualHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * actualHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * actualHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 15) { + if( (potential*setToHighest<0 || (setToHighest > tempFold * currentHand->getSmallBlind() && potential<1) || (setToHighest > 3 * tempFold * currentHand->getSmallBlind() && potential<2) || (setToHighest > 9 * tempFold * currentHand->getSmallBlind() && potential<3) || (setToHighest > 20*tempFold * currentHand->getSmallBlind() && potential<4) || (setToHighest > 40 *tempFold * currentHand->getSmallBlind() && potential<5)) && percent < 0.90 && bluff > 15) { myAction=1; } else { // CHECK und BET --> wenn noch keiner was gesetzt hat - if(actualHand->getCurrentBeRo()->getHighestSet() == 0) { + if(currentHand->getCurrentBeRo()->getHighestSet() == 0) { // CHECK --> wenn Potential klein if((potential<2 || bluff >= 92) && bluff > 15) { // check @@ -4591,11 +4591,11 @@ void LocalPlayer::riverEngine3() { // BET --> wenn Potential hoch else { - if(bluff <= 5) mySet = (bluff+3) * actualHand->getSmallBlind(); + if(bluff <= 5) mySet = (bluff+3) * currentHand->getSmallBlind(); else { - if(bluff <= 15 ) mySet = ((bluff-1)/5) * 2 * actualHand->getSmallBlind(); + if(bluff <= 15 ) mySet = ((bluff-1)/5) * 2 * currentHand->getSmallBlind(); // je hᅵer das Potential, desto hᅵher der Einsatz (zur Basis SmallBlind) - else mySet = (potential-1) * 4 * actualHand->getSmallBlind(); + else mySet = (potential-1) * 4 * currentHand->getSmallBlind(); } // All In @@ -4610,42 +4610,42 @@ void LocalPlayer::riverEngine3() { myCash -= mySet; myAction = 4; } - actualHand->getCurrentBeRo()->setHighestSet(mySet); + currentHand->getCurrentBeRo()->setHighestSet(mySet); } } // CALL und RAISE --> wenn bereits gesetzt wurde else { // RAISE --> wenn Potential besonders gut - if(potential >=4 && 2 * tempFold * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet() || (bluff <= 2 && 4 * tempFold * actualHand->getSmallBlind() >= actualHand->getCurrentBeRo()->getHighestSet())) { + if(potential >=4 && 2 * tempFold * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet() || (bluff <= 2 && 4 * tempFold * currentHand->getSmallBlind() >= currentHand->getCurrentBeRo()->getHighestSet())) { // bluff - raise - if(bluff <= 2 ) raise = bluff * actualHand->getCurrentBeRo()->getHighestSet(); + if(bluff <= 2 ) raise = bluff * currentHand->getCurrentBeRo()->getHighestSet(); // Betrag, der ber dem aktuell HighestSet gesetzt werden soll - else raise = ( potential - 3 ) * actualHand->getCurrentBeRo()->getHighestSet(); + else raise = ( potential - 3 ) * currentHand->getCurrentBeRo()->getHighestSet(); // All In - if(actualHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() + raise >= myCash) { mySet += myCash; myCash = 0; myAction = 6; - if(mySet > actualHand->getCurrentBeRo()->getHighestSet()) actualHand->getCurrentBeRo()->setHighestSet(mySet); + if(mySet > currentHand->getCurrentBeRo()->getHighestSet()) currentHand->getCurrentBeRo()->setHighestSet(mySet); } // sonst else { - myCash = myCash + mySet - actualHand->getCurrentBeRo()->getHighestSet() - raise; - mySet = actualHand->getCurrentBeRo()->getHighestSet() + raise; - actualHand->getCurrentBeRo()->setHighestSet(mySet); + myCash = myCash + mySet - currentHand->getCurrentBeRo()->getHighestSet() - raise; + mySet = currentHand->getCurrentBeRo()->getHighestSet() + raise; + currentHand->getCurrentBeRo()->setHighestSet(mySet); myAction = 5; } } // CALL --> bei normalen Potential else { // All In - if(actualHand->getCurrentBeRo()->getHighestSet() >= myCash) { + if(currentHand->getCurrentBeRo()->getHighestSet() >= myCash) { mySet += myCash; myCash = 0; @@ -4654,8 +4654,8 @@ void LocalPlayer::riverEngine3() { } // sonst else { - myCash = myCash - actualHand->getCurrentBeRo()->getHighestSet() + mySet; - mySet = actualHand->getCurrentBeRo()->getHighestSet(); + myCash = myCash - currentHand->getCurrentBeRo()->getHighestSet() + mySet; + mySet = currentHand->getCurrentBeRo()->getHighestSet(); myAction = 3; } } diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 81574258..34d935e7 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -67,7 +67,7 @@ public: void setMyAction(int theValue, bool blind = 0) { myAction = theValue; // logging for human player - if(myAction && !blind) actualHand->getGuiInterface()->logPlayerActionMsg(myName, myAction, mySet); + if(myAction && !blind) currentHand->getGuiInterface()->logPlayerActionMsg(myName, myAction, mySet); } int getMyAction() const { return myAction; } @@ -88,11 +88,11 @@ public: // log flipping cards if(myCardsFlip) { switch(state) { - case 1: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); + case 1: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); break; - case 2: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); + case 2: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); break; - case 3: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); + case 3: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); break; default: ; } @@ -143,7 +143,7 @@ public: void setMyWinnerState ( bool theValue, int pot ) { if(theValue) myWinnerState = theValue; - actualHand->getGuiInterface()->logPlayerWinsMsg(myName, pot, theValue); + currentHand->getGuiInterface()->logPlayerWinsMsg(myName, pot, theValue); } bool getMyWinnerState() const { return myWinnerState;} @@ -179,8 +179,8 @@ public: private: ConfigFile *myConfig; - HandInterface *actualHand; - BoardInterface *actualBoard; + HandInterface *currentHand; + BoardInterface *currentBoard; CardsValue *myCardsValue; diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index aec19e00..aaf90d92 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -24,7 +24,7 @@ using namespace std; ClientBoard::ClientBoard() -: playerArray(0), actualHand(0), pot(0), sets(0) +: playerArray(0), currentHand(0), pot(0), sets(0) { } @@ -47,7 +47,7 @@ void ClientBoard::setHand(HandInterface* br) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - actualHand = br; + currentHand = br; } void diff --git a/src/engine/network_engine/clientboard.h b/src/engine/network_engine/clientboard.h index 94a8cd43..2c0997ff 100644 --- a/src/engine/network_engine/clientboard.h +++ b/src/engine/network_engine/clientboard.h @@ -60,7 +60,7 @@ private: PlayerList activePlayerList; PlayerList runningPlayerList; - HandInterface *actualHand; + HandInterface *currentHand; std::list winners; diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index 6f5bbd20..5a507471 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -22,7 +22,7 @@ using namespace std; ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl_old, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(sl_old), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), +: myFactory(f), myGui(g), myBoard(b), playerArray(sl_old), seatsList(sl), activePlayerList(apl), runningPlayerList(rpl), myID(id), startQuantityPlayers(sP), dealerPosition(dP), currentRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(0), cardsShown(false), bettingRoundsPlayed(0) { @@ -166,7 +166,7 @@ ClientHand::getRiver() const boost::shared_ptr ClientHand::getCurrentBeRo() const { - return myBeRo[actualRound]; + return myBeRo[currentRound]; } @@ -205,17 +205,17 @@ ClientHand::getStartQuantityPlayers() const } void -ClientHand::setActualRound(int theValue) +ClientHand::setCurrentRound(int theValue) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - actualRound = theValue; + currentRound = theValue; } int -ClientHand::getActualRound() const +ClientHand::getCurrentRound() const { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - return actualRound; + return currentRound; } void diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index b8037eab..f0d9c895 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -57,14 +57,14 @@ class ClientHand : public HandInterface void setMyID ( int theValue ); int getMyID() const; - void setActualQuantityPlayers ( int theValue ); - int getActualQuantityPlayers() const; + void setCurrentQuantityPlayers ( int theValue ); + int getCurrentQuantityPlayers() const; void setStartQuantityPlayers ( int theValue ); int getStartQuantityPlayers() const; - void setActualRound ( int theValue ); - int getActualRound() const; + void setCurrentRound ( int theValue ); + int getCurrentRound() const; void setDealerPosition ( int theValue ); int getDealerPosition() const; @@ -106,8 +106,8 @@ class ClientHand : public HandInterface int myID; int startQuantityPlayers; - int dealerPosition; // -1 -> neutral - int actualRound; //0 = preflop, 1 = flop, 2 = turn, 3 = river + unsigned dealerPosition; + int currentRound; //0 = preflop, 1 = flop, 2 = turn, 3 = river int smallBlind; int startCash; diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index 520e6025..ef1b81d1 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -23,7 +23,7 @@ using namespace std; ClientPlayer::ClientPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) -: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) +: PlayerInterface(), myConfig(c), currentHand(0), currentBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0) { } @@ -37,7 +37,7 @@ void ClientPlayer::setHand(HandInterface* br) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); - actualHand = br; + currentHand = br; } int @@ -244,11 +244,11 @@ ClientPlayer::setMyCardsFlip(bool theValue, int state) // log flipping cards if (myCardsFlip) { switch(state) { - case 1: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); + case 1: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); break; - case 2: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); + case 2: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); break; - case 3: actualHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); + case 3: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); break; default: ; } @@ -379,7 +379,7 @@ ClientPlayer::setMyWinnerState(bool theValue, int pot) { boost::recursive_mutex::scoped_lock lock(m_syncMutex); if(theValue) myWinnerState = theValue; - actualHand->getGuiInterface()->logPlayerWinsMsg(myName, pot, theValue); + currentHand->getGuiInterface()->logPlayerWinsMsg(myName, pot, theValue); } bool diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index 6b886e0f..6c2d4e29 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -132,8 +132,8 @@ private: mutable boost::recursive_mutex m_syncMutex; ConfigFile *myConfig; - HandInterface *actualHand; - BoardInterface *actualBoard; + HandInterface *currentHand; + BoardInterface *currentBoard; CardsValue *myCardsValue; diff --git a/src/game.cpp b/src/game.cpp index 955bbcc0..11b36d4d 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -33,10 +33,10 @@ using namespace std; Game::Game(GuiInterface* gui, boost::shared_ptr factory, const PlayerDataList &playerDataList, const GameData &gameData, const StartData &startData, int gameId) -: myFactory(factory), myGui(gui), actualHand(0), actualBoard(0), +: myFactory(factory), myGui(gui), currentHand(0), currentBoard(0), startQuantityPlayers(startData.numberOfPlayers), startCash(gameData.startMoney), startSmallBlind(gameData.firstSmallBlind), - myGameID(gameId), actualSmallBlind(gameData.firstSmallBlind), actualHandID(0), dealerPosition(0), lastHandBlindsRaised(1), lastTimeBlindsRaised(0), myGameData(gameData) + myGameID(gameId), currentSmallBlind(gameData.firstSmallBlind), currentHandID(0), dealerPosition(0), lastHandBlindsRaised(1), lastTimeBlindsRaised(0), myGameData(gameData) { blindsList = myGameData.manualBlindsList; @@ -44,13 +44,13 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, if(DEBUG_MODE) { startSmallBlind = 10; - actualSmallBlind = startSmallBlind; + currentSmallBlind = startSmallBlind; } // cout << "Create Game Object" << "\n"; int i; - actualHandID = 0; + currentHandID = 0; // for(i=0; i factory, dealerPosition = startData.startDealerPlayerId; // Board erstellen - actualBoard = myFactory->createBoard(); + currentBoard = myFactory->createBoard(); seatsList = PlayerList(new std::list >); activePlayerList = PlayerList(new std::list >); @@ -101,7 +101,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, } // create Player Objects - boost::shared_ptr tmpPlayer = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); + boost::shared_ptr tmpPlayer = myFactory->createPlayer(currentBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0); tmpPlayer->setNetSessionData(myNetSession); @@ -117,7 +117,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, playerArray[i]->setNetSessionData(myNetSession); // delete } - actualBoard->setPlayerLists(playerArray, seatsList, activePlayerList, runningPlayerList); // delete playerArray + currentBoard->setPlayerLists(playerArray, seatsList, activePlayerList, runningPlayerList); // delete playerArray //start timer blindsTimer.reset(); @@ -128,21 +128,21 @@ Game::~Game() { // cout << "Delete Game Object" << "\n"; - delete actualBoard; - actualBoard = 0; - delete actualHand; - actualHand = 0; + delete currentBoard; + currentBoard = 0; + delete currentHand; + currentHand = 0; } HandInterface *Game::getCurrentHand() { - return actualHand; + return currentHand; } const HandInterface *Game::getCurrentHand() const { - return actualHand; + return currentHand; } void Game::initHand() @@ -152,7 +152,7 @@ void Game::initHand() PlayerListConstIterator it_c; PlayerListIterator it, it_2; - actualHandID++; + currentHandID++; // calculate smallBlind raiseBlinds(); @@ -182,16 +182,16 @@ void Game::initHand() } // eventuell vorhandene Hand löschen - if(actualHand) { - delete actualHand; - actualHand = 0; + if(currentHand) { + delete currentHand; + currentHand = 0; } runningPlayerList->clear(); (*runningPlayerList) = (*activePlayerList); // Hand erstellen - actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, seatsList, activePlayerList, runningPlayerList, actualHandID, startQuantityPlayers, dealerPosition, actualSmallBlind, startCash); // delete playerArray + currentHand = myFactory->createHand(myFactory, myGui, currentBoard, playerArray, seatsList, activePlayerList, runningPlayerList, currentHandID, startQuantityPlayers, dealerPosition, currentSmallBlind, startCash); // delete playerArray // Dealer-Button weiterschieben --> Achtung inactive -> TODO exception-rule !!! DELETE @@ -202,7 +202,7 @@ void Game::initHand() // Dealer-Button weiterschieben --> Achtung inactive -> TODO exception-rule !!! bool nextDealerFound = false; - PlayerListConstIterator dealerPositionIt = actualHand->getSeatIt(dealerPosition); + PlayerListConstIterator dealerPositionIt = currentHand->getSeatIt(dealerPosition); if(dealerPositionIt == seatsList->end()) { throw LocalException(ERR_SEAT_NOT_FOUND); } @@ -212,7 +212,7 @@ void Game::initHand() dealerPositionIt++; if(dealerPositionIt == seatsList->end()) dealerPositionIt = seatsList->begin(); - it = actualHand->getActivePlayerIt( (*dealerPositionIt)->getMyUniqueID() ); + it = currentHand->getActivePlayerIt( (*dealerPositionIt)->getMyUniqueID() ); if(it != activePlayerList->end() ) { nextDealerFound = true; dealerPosition = (*it)->getMyUniqueID(); @@ -233,10 +233,10 @@ void Game::startHand() myGui->nextRoundCleanGui(); //Log new Hand - myGui->logNewGameHandMsg(myGameID, actualHandID); + myGui->logNewGameHandMsg(myGameID, currentHandID); myGui->flushLogAtGame(myGameID); - actualHand->start(); + currentHand->start(); } boost::shared_ptr Game::getPlayerByUniqueId(unsigned id) @@ -275,9 +275,9 @@ void Game::raiseBlinds() { if (myGameData.raiseIntervalMode == RAISE_ON_HANDNUMBER) { - if (lastHandBlindsRaised + myGameData.raiseSmallBlindEveryHandsValue <= actualHandID) { + if (lastHandBlindsRaised + myGameData.raiseSmallBlindEveryHandsValue <= currentHandID) { raiseBlinds = true; - lastHandBlindsRaised = actualHandID; + lastHandBlindsRaised = currentHandID; // cout << "raise now on hands \n"; } @@ -297,7 +297,7 @@ void Game::raiseBlinds() { // Now we check how the blinds should be raised if (myGameData.raiseMode == DOUBLE_BLINDS) { - actualSmallBlind *= 2; + currentSmallBlind *= 2; // cout << "double small blind \n"; } else { @@ -307,17 +307,17 @@ void Game::raiseBlinds() { if(!blindsList.empty()) { - actualSmallBlind = blindsList.front(); + currentSmallBlind = blindsList.front(); blindsList.pop_front(); -// it = find(blindsList.begin(), blindsList.end(), actualSmallBlind); +// it = find(blindsList.begin(), blindsList.end(), currentSmallBlind); // if(it != blindsList.end()) { // it++; // cout << "increase position in blindslist \n"; // } // else { // cout << "blindslist exceeds\n"; -// if(actualSmallBlind == myGameData.firstSmallBlind) { +// if(currentSmallBlind == myGameData.firstSmallBlind) { // it = blindsList.begin(); // } // } @@ -330,19 +330,19 @@ void Game::raiseBlinds() { // The position exceeds the list if (myGameData.afterManualBlindsMode == AFTERMB_DOUBLE_BLINDS) { - actualSmallBlind *= 2; + currentSmallBlind *= 2; // cout << "after blindslist double blind\n"; } else { if(myGameData.afterManualBlindsMode == AFTERMB_RAISE_ABOUT) { - actualSmallBlind += myGameData.afterMBAlwaysRaiseValue; + currentSmallBlind += myGameData.afterMBAlwaysRaiseValue; // cout << "after blindslist increase about x \n"; } // else { /* Stay at last blind */ cout << "after blindslist stay at last blind \n"; } } // } else { // Grab the blinds amount from the list -// actualSmallBlind = *it; +// currentSmallBlind = *it; // cout << "set new small blind from blindslist \n"; } } diff --git a/src/game.h b/src/game.h index b0190521..977a57a7 100755 --- a/src/game.h +++ b/src/game.h @@ -73,11 +73,11 @@ public: int getMyGameID() const { return myGameID; } - void setActualSmallBlind(int theValue) { actualSmallBlind = theValue; } - int getActualSmallBlind() const { return actualSmallBlind; } + void setCurrentSmallBlind(int theValue) { currentSmallBlind = theValue; } + int getCurrentSmallBlind() const { return currentSmallBlind; } - void setActualHandID(int theValue) { actualHandID = theValue; } - int getActualHandID() const { return actualHandID; } + void setCurrentHandID(int theValue) { currentHandID = theValue; } + int getCurrentHandID() const { return currentHandID; } boost::shared_ptr getPlayerByUniqueId(unsigned id); boost::shared_ptr getCurrentPlayer(); @@ -88,8 +88,8 @@ private: boost::shared_ptr myFactory; GuiInterface *myGui; - HandInterface *actualHand; - BoardInterface *actualBoard; + HandInterface *currentHand; + BoardInterface *currentBoard; std::vector > playerArray; // available seats --> seatList !!! TODO // delete PlayerList seatsList; @@ -106,8 +106,8 @@ private: int guiPlayerNum; //Laufvariablen - int actualSmallBlind; - int actualHandID; + int currentSmallBlind; + int currentHandID; unsigned dealerPosition; int lastHandBlindsRaised; int lastTimeBlindsRaised; diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 7232fb65..035a2d9e 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -59,7 +59,7 @@ using namespace std; mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) - : QMainWindow(parent), myChat(NULL), myConfig(c), gameSpeed(0), myActionIsBet(0), myActionIsRaise(0), pushButtonBetRaiseIsChecked(FALSE), pushButtonCallCheckIsChecked(FALSE), pushButtonFoldIsChecked(FALSE), pushButtonAllInIsChecked(FALSE), myButtonsAreCheckable(FALSE), breakAfterActualHand(FALSE) + : QMainWindow(parent), myChat(NULL), myConfig(c), gameSpeed(0), myActionIsBet(0), myActionIsRaise(0), pushButtonBetRaiseIsChecked(FALSE), pushButtonCallCheckIsChecked(FALSE), pushButtonFoldIsChecked(FALSE), pushButtonAllInIsChecked(FALSE), myButtonsAreCheckable(FALSE), breakAfterCurrentHand(FALSE) { int i; @@ -2120,7 +2120,7 @@ void mainWindowImpl::provideMyActions() { horizontalSlider_bet->setEnabled(TRUE); spinBox_set->setEnabled(TRUE); - switch (currentHand->getActualRound()) { + switch (currentHand->getCurrentRound()) { case 0: { if (currentGame->getSeatsList()->front()->getMyCash()+currentGame->getSeatsList()->front()->getMySet() > currentHand->getCurrentBeRo()->getHighestSet()) { @@ -3432,7 +3432,7 @@ void mainWindowImpl::showMyCards() { HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand(); currentHand->getSeatsList()->front()->getMyCards(tempCardsIntArray); - if( currentHand->getSeatsList()->front()->getMyCardsFlip() == 0 && currentHand->getActualRound() == 4 && currentHand->getSeatsList()->front()->getMyActiveStatus() && currentHand->getSeatsList()->front()->getMyAction() != PLAYER_ACTION_FOLD) { + if( currentHand->getSeatsList()->front()->getMyCardsFlip() == 0 && currentHand->getCurrentRound() == 4 && currentHand->getSeatsList()->front()->getMyActiveStatus() && currentHand->getSeatsList()->front()->getMyAction() != PLAYER_ACTION_FOLD) { //set Player value (logging) currentHand->getSeatsList()->front()->setMyCardsFlip(1,1); @@ -3442,7 +3442,7 @@ void mainWindowImpl::showMyCards() { void mainWindowImpl::startNewHand() { - if( !breakAfterActualHand){ + if( !breakAfterCurrentHand){ mySession->getCurrentGame()->initHand(); mySession->getCurrentGame()->startHand(); } @@ -3454,7 +3454,7 @@ void mainWindowImpl::startNewHand() { pushButton_break->setMinimumSize(width+10,20); pushButton_break->setText(tr("Start")); - breakAfterActualHand=FALSE; + breakAfterCurrentHand=FALSE; blinkingStartButtonAnimationTimer->start(500); } @@ -3508,7 +3508,7 @@ void mainWindowImpl::nextRoundCleanGui() { else { //FIX STRG+N Bug pushButton_break->setEnabled(TRUE); - breakAfterActualHand=FALSE; + breakAfterCurrentHand=FALSE; } //Clean breakbutton @@ -3582,7 +3582,7 @@ void mainWindowImpl::breakButtonClicked() { if (pushButton_break->text() == tr("Stop")) { pushButton_break->setDisabled(TRUE); - breakAfterActualHand=TRUE; + breakAfterCurrentHand=TRUE; } else { blinkingStartButtonAnimationTimer->stop(); diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index ba8e47cd..10224068 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -454,7 +454,7 @@ private: bool pushButtonAllInIsChecked; bool myButtonsAreCheckable; - bool breakAfterActualHand; + bool breakAfterCurrentHand; bool flipHolecardsAllInAlreadyDone; diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index eb39a7aa..1a3dc011 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -967,10 +967,10 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->getActualRound() != turnData.gameState) + if (curGame->getCurrentHand()->getCurrentRound() != turnData.gameState) { ResetPlayerActions(*curGame); - curGame->getCurrentHand()->setActualRound(turnData.gameState); + curGame->getCurrentHand()->setCurrentRound(turnData.gameState); // Refresh actions. client.GetGui().refreshSet(); client.GetGui().refreshAction(); diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 4d3ca4fa..55c4ce9c 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -135,7 +135,7 @@ ClientThread::SendPlayerAction() boost::shared_ptr action(new NetPacketPlayersAction); NetPacketPlayersAction::Data actionData; boost::shared_ptr myPlayer = GetGame()->getSeatsList()->front(); - actionData.gameState = static_cast(GetGame()->getCurrentHand()->getActualRound()); + actionData.gameState = static_cast(GetGame()->getCurrentHand()->getCurrentRound()); 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) diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 38121861..92b86039 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -1,1229 +1,1229 @@ -/*************************************************************************** - * Copyright (C) 2007 by Lothar May * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -using namespace std; - -#define SERVER_WAIT_TIMEOUT_MSEC 50 -#define SERVER_DELAY_NEXT_HAND_SEC 10 -#define SERVER_DELAY_NEXT_GAME_SEC 10 -#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5 -#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2 -#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2 -#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 2 -#define SERVER_SHOW_CARDS_DELAY_SEC 2 -#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2 -#define SERVER_COMPUTER_ACTION_DELAY_SEC 2 -#define SERVER_START_GAME_TIMEOUT_SEC 10 - -#define SERVER_COMPUTER_PLAYER_NAME "Computer" - -// Helper functions -// TODO: these are hacks. - -static void SendPlayerAction(ServerGameThread &server, boost::shared_ptr player) -{ - assert(player); - - boost::shared_ptr notifyActionDone(new NetPacketPlayersActionDone); - NetPacketPlayersActionDone::Data actionDoneData; - actionDoneData.gameState = server.GetCurRound(); - actionDoneData.playerId = player->getMyUniqueID(); - actionDoneData.playerAction = static_cast(player->getMyAction()); - actionDoneData.totalPlayerBet = player->getMySet(); - actionDoneData.playerMoney = player->getMyCash(); - actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); - static_cast(notifyActionDone.get())->SetData(actionDoneData); - server.SendToAllPlayers(notifyActionDone, SessionData::Game); -} - -static void SendNewRoundCards(ServerGameThread &server, Game &curGame, int state) -{ - // TODO: no switch needed here if game states are polymorphic - switch(state) { - case GAME_STATE_PREFLOP: { - // nothing to do - } break; - case GAME_STATE_FLOP: { - // deal flop cards - int cards[5]; - curGame.getCurrentHand()->getBoard()->getMyCards(cards); - boost::shared_ptr notifyCards(new NetPacketDealFlopCards); - NetPacketDealFlopCards::Data notifyCardsData; - for (int num = 0; num < 3; num++) - notifyCardsData.flopCards[num] = static_cast(cards[num]); - static_cast(notifyCards.get())->SetData(notifyCardsData); - server.SendToAllPlayers(notifyCards, SessionData::Game); - } break; - case GAME_STATE_TURN: { - // deal turn card - int cards[5]; - curGame.getCurrentHand()->getBoard()->getMyCards(cards); - boost::shared_ptr notifyCards(new NetPacketDealTurnCard); - NetPacketDealTurnCard::Data notifyCardsData; - notifyCardsData.turnCard = static_cast(cards[3]); - static_cast(notifyCards.get())->SetData(notifyCardsData); - server.SendToAllPlayers(notifyCards, SessionData::Game); - } break; - case GAME_STATE_RIVER: { - // deal river card - int cards[5]; - curGame.getCurrentHand()->getBoard()->getMyCards(cards); - boost::shared_ptr notifyCards(new NetPacketDealRiverCard); - NetPacketDealRiverCard::Data notifyCardsData; - notifyCardsData.riverCard = static_cast(cards[4]); - static_cast(notifyCards.get())->SetData(notifyCardsData); - server.SendToAllPlayers(notifyCards, SessionData::Game); - } break; - default: { - // - } - } -} - -//----------------------------------------------------------------------------- - -ServerGameState::~ServerGameState() -{ -} - -//----------------------------------------------------------------------------- - -AbstractServerGameStateReceiving::AbstractServerGameStateReceiving() -{ -} - -AbstractServerGameStateReceiving::~AbstractServerGameStateReceiving() -{ -} - -int -AbstractServerGameStateReceiving::Process(ServerGameThread &server) -{ - // This is the receive loop for the server. - int retVal = MSG_SOCK_INTERNAL_PENDING; - SessionWrapper session = server.GetSessionManager().Select(RECV_TIMEOUT_MSEC); - - if (session.sessionData.get()) - { - boost::shared_ptr packet; - try - { - // Receive the packet. - packet = server.GetReceiver().Recv(session.sessionData->GetSocket(), session.sessionData->GetReceiveBuffer()); - } catch (const NetException &) - { - server.ErrorRemoveSession(session); - return retVal; - } - - // Process packet if one was received. - if (packet.get()) - { - if (packet->ToNetPacketRetrievePlayerInfo()) - { - // Delegate to Lobby. - server.GetLobbyThread().HandleGameRetrievePlayerInfo(session, *packet->ToNetPacketRetrievePlayerInfo()); - } - else if (packet->ToNetPacketRetrieveAvatar()) - { - // Delegate to Lobby. - server.GetLobbyThread().HandleGameRetrieveAvatar(session, *packet->ToNetPacketRetrieveAvatar()); - } - else if (packet->ToNetPacketLeaveCurrentGame()) - { - server.MoveSessionToLobby(session, NTF_NET_REMOVED_ON_REQUEST); - } - // Chat text is always allowed. - else if (packet->ToNetPacketSendChatText()) - { - if (session.playerData.get()) // Only forward if this player is known. - { - // Forward chat text to all players. - // TODO: Some limitation needed. - NetPacketSendChatText::Data inChatData; - packet->ToNetPacketSendChatText()->GetData(inChatData); - - boost::shared_ptr outChat(new NetPacketChatText); - NetPacketChatText::Data outChatData; - outChatData.playerId = session.playerData->GetUniqueId(); - outChatData.text = inChatData.text; - static_cast(outChat.get())->SetData(outChatData); - server.SendToAllPlayers(outChat, SessionData::Game); - } - } - else - { - // Packet processing in subclass. - retVal = InternalProcess(server, session, packet); - } - } - } - return retVal; -} - -//----------------------------------------------------------------------------- - -AbstractServerGameStateTimer::AbstractServerGameStateTimer() -: m_timer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start) -{ -} - -AbstractServerGameStateTimer::~AbstractServerGameStateTimer() -{ -} - -void -AbstractServerGameStateTimer::Init() -{ - m_timer.reset(); - m_timer.start(); -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateInit::Ptr; - -ServerGameStateInit & -ServerGameStateInit::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateInit); - - return *Ptr; -} - -ServerGameStateInit::ServerGameStateInit() -{ -} - -ServerGameStateInit::~ServerGameStateInit() -{ -} - -void -ServerGameStateInit::HandleNewSession(ServerGameThread &server, SessionWrapper session) -{ - if (session.sessionData.get() && session.playerData.get()) - { - size_t curNumPlayers = server.GetCurNumberOfPlayers(); - - // Check the number of players. - if (curNumPlayers >= (size_t)server.GetGameData().maxNumberOfPlayers) - { - server.MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL); - } - else - { - if (session.playerData->GetUniqueId() == server.GetAdminPlayerId()) - { - // This is the admin player. - session.playerData->SetRights(PLAYER_RIGHTS_ADMIN); - } - - // Send ack to client. - boost::shared_ptr joinGameAck(new NetPacketJoinGameAck); - NetPacketJoinGameAck::Data joinGameAckData; - joinGameAckData.gameId = server.GetId(); - joinGameAckData.prights = session.playerData->GetRights(); - joinGameAckData.gameData = server.GetGameData(); - static_cast(joinGameAck.get())->SetData(joinGameAckData); - server.GetSender().Send(session.sessionData->GetSocket(), joinGameAck); - - // Send notifications for connected players to client. - PlayerDataList tmpPlayerList = server.GetFullPlayerDataList(); - PlayerDataList::iterator player_i = tmpPlayerList.begin(); - PlayerDataList::iterator player_end = tmpPlayerList.end(); - while (player_i != player_end) - { - server.GetSender().Send(session.sessionData->GetSocket(), CreateNetPacketPlayerJoined(*(*player_i))); - ++player_i; - } - - // Send "Player Joined" to other fully connected clients. - server.SendToAllPlayers(CreateNetPacketPlayerJoined(*session.playerData), SessionData::Game); - - // Accept session. - server.GetSessionManager().AddSession(session); - - // Notify lobby. - server.GetLobbyThread().NotifyPlayerJoinedGame(server.GetId(), session.playerData->GetUniqueId()); - } - } -} - -int -ServerGameStateInit::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr packet) -{ - int retVal = MSG_SOCK_INTERNAL_PENDING; - - if (packet->ToNetPacketStartEvent()) - { - // Only admins are allowed to start the game. - if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN) - { - NetPacketStartEvent::Data startData; - packet->ToNetPacketStartEvent()->GetData(startData); - - // Fill up with computer players. - server.ResetComputerPlayerList(); - - if (startData.fillUpWithCpuPlayers) - { - int remainingSlots = server.GetGameData().maxNumberOfPlayers - server.GetCurNumberOfPlayers(); - for (int i = 1; i <= remainingSlots; i++) - { - boost::shared_ptr tmpPlayerData( - new PlayerData(server.GetLobbyThread().GetNextUniquePlayerId(), 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL)); - - ostringstream name; - name << SERVER_COMPUTER_PLAYER_NAME << i; - tmpPlayerData->SetName(name.str()); - server.AddComputerPlayer(tmpPlayerData); - - // Send "Player Joined" to other fully connected clients. - server.SendToAllPlayers(CreateNetPacketPlayerJoined(*tmpPlayerData), SessionData::Game); - } - } - // Wait for all players to confirm start of game. - server.SendToAllPlayers(boost::shared_ptr(packet->Clone()), SessionData::Game); - - server.SetState(ServerGameStateWaitAck::Instance()); - } - } - else if (packet->ToNetPacketKickPlayer()) - { - // Only admins are allowed to kick. - if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN) - { - NetPacketKickPlayer::Data kickPlayerData; - packet->ToNetPacketKickPlayer()->GetData(kickPlayerData); - - server.InternalKickPlayer(kickPlayerData.playerId); - } - } - else - { - server.SessionError(session, ERR_SOCK_INVALID_PACKET); - } - - return retVal; -} - -boost::shared_ptr -ServerGameStateInit::CreateNetPacketPlayerJoined(const PlayerData &playerData) -{ - boost::shared_ptr thisPlayerJoined(new NetPacketPlayerJoined); - NetPacketPlayerJoined::Data thisPlayerJoinedData; - thisPlayerJoinedData.playerId = playerData.GetUniqueId(); - thisPlayerJoinedData.prights = playerData.GetRights(); - static_cast(thisPlayerJoined.get())->SetData(thisPlayerJoinedData); - return thisPlayerJoined; -} - -//----------------------------------------------------------------------------- - -AbstractServerGameStateRunning::AbstractServerGameStateRunning() -{ -} - -AbstractServerGameStateRunning::~AbstractServerGameStateRunning() -{ -} - -void -AbstractServerGameStateRunning::HandleNewSession(ServerGameThread &server, SessionWrapper session) -{ - // Do not accept new sessions in this state. - server.MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING); -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateWaitAck::Ptr; - -ServerGameStateWaitAck & -ServerGameStateWaitAck::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateWaitAck); - - return *Ptr; -} - -ServerGameStateWaitAck::ServerGameStateWaitAck() -{ -} - -ServerGameStateWaitAck::~ServerGameStateWaitAck() -{ -} - -int -ServerGameStateWaitAck::Process(ServerGameThread &server) -{ - int retVal; - - if (GetTimer().elapsed().total_seconds() >= SERVER_START_GAME_TIMEOUT_SEC) - { - // On timeout: start anyway. - server.SetState(SERVER_START_GAME_STATE::Instance()); - retVal = MSG_SOCK_INIT_DONE; - } - else - retVal = AbstractServerGameStateReceiving::Process(server); - - return retVal; -} - -int -ServerGameStateWaitAck::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr packet) -{ - int retVal = MSG_SOCK_INTERNAL_PENDING; - - if (packet->ToNetPacketStartEventAck()) - { - session.sessionData->SetReadyFlag(); - if (server.GetSessionManager().CountReadySessions() == server.GetSessionManager().GetRawSessionCount()) - { - // Everyone is ready. - server.GetSessionManager().ResetAllReadyFlags(); - server.SetState(SERVER_START_GAME_STATE::Instance()); - retVal = MSG_SOCK_INIT_DONE; - } - retVal = MSG_SOCK_INIT_DONE; - } - - return retVal; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateStartGame::Ptr; - -ServerGameStateStartGame & -ServerGameStateStartGame::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateStartGame); - - return *Ptr; -} - -ServerGameStateStartGame::ServerGameStateStartGame() -{ -} - -ServerGameStateStartGame::~ServerGameStateStartGame() -{ -} - -int -ServerGameStateStartGame::Process(ServerGameThread &server) -{ - server.InternalStartGame(); - - boost::shared_ptr answer(new NetPacketGameStart); - - NetPacketGameStart::Data gameStartData; - gameStartData.startData = server.GetStartData(); - - // Send player order to clients. - // Assume player list is sorted by number. - PlayerDataList tmpPlayerList = server.GetFullPlayerDataList(); - PlayerDataList::iterator player_i = tmpPlayerList.begin(); - PlayerDataList::iterator player_end = tmpPlayerList.end(); - while (player_i != player_end) - { - NetPacketGameStart::PlayerSlot tmpPlayerSlot; - tmpPlayerSlot.playerId = (*player_i)->GetUniqueId(); - gameStartData.playerSlots.push_back(tmpPlayerSlot); - - ++player_i; - } - - static_cast(answer.get())->SetData(gameStartData); - - server.SendToAllPlayers(answer, SessionData::Game); - server.SetState(ServerGameStateStartHand::Instance()); - - return MSG_NET_GAME_SERVER_START; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateStartHand::Ptr; - -ServerGameStateStartHand & -ServerGameStateStartHand::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateStartHand); - - return *Ptr; -} - -ServerGameStateStartHand::ServerGameStateStartHand() -{ -} - -ServerGameStateStartHand::~ServerGameStateStartHand() -{ -} - -int -ServerGameStateStartHand::Process(ServerGameThread &server) -{ - // Initialize hand. - Game &curGame = server.GetGame(); - curGame.initHand(); - - // HACK: Skip GUI notification run - curGame.getCurrentHand()->getFlop()->skipFirstRunGui(); - curGame.getCurrentHand()->getTurn()->skipFirstRunGui(); - curGame.getCurrentHand()->getRiver()->skipFirstRunGui(); - - // Consider all players, even inactive. - PlayerListIterator i = curGame.getSeatsList()->begin(); - PlayerListIterator end = curGame.getSeatsList()->end(); - - // Send cards to all players. - while (i != end) - { - // also send to inactive players, but not to disconnected players. - boost::shared_ptr tmpPlayer = *i; - if (tmpPlayer->getNetSessionData().get()) - { - int cards[2]; - 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]); - handStartData.smallBlind = curGame.getCurrentHand()->getSmallBlind(); - static_cast(notifyCards.get())->SetData(handStartData); - - server.GetSender().Send(tmpPlayer->getNetSessionData()->GetSocket(), notifyCards); - } - ++i; - } - - // Start hand. - curGame.startHand(); - - // Auto small blind / big blind at the beginning of hand. - i = curGame.getActivePlayerList()->begin(); - end = curGame.getActivePlayerList()->end(); - - while (i != end) - { - 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 = tmpPlayer->getMyUniqueID(); - actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction(); - actionDoneData.totalPlayerBet = tmpPlayer->getMySet(); - actionDoneData.playerMoney = tmpPlayer->getMyCash(); - actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); - static_cast(notifySmallBlind.get())->SetData(actionDoneData); - server.SendToAllPlayers(notifySmallBlind, SessionData::Game); - break; - } - ++i; - } - - i = curGame.getActivePlayerList()->begin(); - end = curGame.getActivePlayerList()->end(); - while (i != end) - { - 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 = tmpPlayer->getMyUniqueID(); - actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction(); - actionDoneData.totalPlayerBet = tmpPlayer->getMySet(); - actionDoneData.playerMoney = tmpPlayer->getMyCash(); - actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); - static_cast(notifyBigBlind.get())->SetData(actionDoneData); - server.SendToAllPlayers(notifyBigBlind, SessionData::Game); - break; - } - ++i; - } - - server.SetState(ServerGameStateStartRound::Instance()); - - return MSG_NET_GAME_SERVER_HAND_START; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateStartRound::Ptr; - -ServerGameStateStartRound & -ServerGameStateStartRound::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateStartRound); - - return *Ptr; -} - -ServerGameStateStartRound::ServerGameStateStartRound() -{ -} - -ServerGameStateStartRound::~ServerGameStateStartRound() -{ -} - -int -ServerGameStateStartRound::Process(ServerGameThread &server) -{ - int retVal = MSG_SOCK_INTERNAL_PENDING; - Game &curGame = server.GetGame(); - - // Main game loop. - int curRound = curGame.getCurrentHand()->getActualRound(); - curGame.getCurrentHand()->switchRounds(); - if (!curGame.getCurrentHand()->getAllInCondition()) - curGame.getCurrentHand()->getCurrentBeRo()->run(); - int newRound = curGame.getCurrentHand()->getActualRound(); - - // If round changes, deal cards if needed. - if (newRound != curRound && newRound != GAME_STATE_POST_RIVER) - { - assert(newRound > curRound); - // Retrieve non-fold players. If only one player is left, no cards are shown. - list > nonFoldPlayers = *curGame.getActivePlayerList(); - nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD); - - if (curGame.getCurrentHand()->getAllInCondition() - && !curGame.getCurrentHand()->getCardsShown() - && nonFoldPlayers.size() > 1) - { - // Send cards of all active players to all players (all in). - boost::shared_ptr allIn(new NetPacketAllInShowCards); - NetPacketAllInShowCards::Data allInData; - - PlayerListConstIterator i = nonFoldPlayers.begin(); - PlayerListConstIterator end = nonFoldPlayers.end(); - - while (i != end) - { - NetPacketAllInShowCards::PlayerCards tmpPlayerCards; - tmpPlayerCards.playerId = (*i)->getMyUniqueID(); - - int tmpCards[2]; - (*i)->getMyCards(tmpCards); - tmpPlayerCards.cards[0] = static_cast(tmpCards[0]); - tmpPlayerCards.cards[1] = static_cast(tmpCards[1]); - - allInData.playerCards.push_back(tmpPlayerCards); - ++i; - } - static_cast(allIn.get())->SetData(allInData); - server.SendToAllPlayers(allIn, SessionData::Game); - curGame.getCurrentHand()->setCardsShown(true); - - server.SetState(ServerGameStateShowCardsDelay::Instance()); - retVal = MSG_NET_GAME_SERVER_CARDS_DELAY; - } - else - { - SendNewRoundCards(server, curGame, newRound); - - server.SetState(ServerGameStateDealCardsDelay::Instance()); - retVal = MSG_NET_GAME_SERVER_CARDS_DELAY; - } - } - else - { - if (newRound != GAME_STATE_POST_RIVER) // continue hand - { - assert (!curGame.getCurrentHand()->getAllInCondition()); // this would be an error. - - // Retrieve current player. - boost::shared_ptr curPlayer = curGame.getCurrentPlayer(); - if (!curPlayer.get()) - throw NetException(ERR_NET_NO_CURRENT_PLAYER, 0); - if (!curPlayer->getMyActiveStatus()) - throw NetException(ERR_NET_PLAYER_NOT_ACTIVE, 0); - - boost::shared_ptr notification(new NetPacketPlayersTurn); - NetPacketPlayersTurn::Data playersTurnData; - playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound(); - playersTurnData.playerId = curPlayer->getMyUniqueID(); - playersTurnData.minimumRaise = curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(); - static_cast(notification.get())->SetData(playersTurnData); - - server.SendToAllPlayers(notification, SessionData::Game); - - server.SetState(ServerGameStateWaitPlayerAction::Instance()); - - retVal = MSG_NET_GAME_SERVER_ROUND; - } - else // hand is over - { - // Engine will find out who won. - curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun(); - - // Retrieve non-fold players. If only one player is left, no cards are shown. - list > nonFoldPlayers = *curGame.getActivePlayerList(); - nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD); - - if (nonFoldPlayers.size() == 1) - { - // End of Hand, but keep cards hidden. - boost::shared_ptr player = nonFoldPlayers.front(); - boost::shared_ptr endHand(new NetPacketEndOfHandHideCards); - NetPacketEndOfHandHideCards::Data endHandData; - endHandData.playerId = player->getMyUniqueID(); - endHandData.moneyWon = 0; // TODO - endHandData.playerMoney = player->getMyCash(); - static_cast(endHand.get())->SetData(endHandData); - - server.SendToAllPlayers(endHand, SessionData::Game); - } - else - { - // End of Hand - show cards of active players. - boost::shared_ptr endHand(new NetPacketEndOfHandShowCards); - NetPacketEndOfHandShowCards::Data endHandData; - - PlayerListConstIterator i = nonFoldPlayers.begin(); - PlayerListConstIterator end = nonFoldPlayers.end(); - - while (i != end) - { - NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult; - tmpPlayerResult.playerId = (*i)->getMyUniqueID(); - - int tmpCards[2]; - int bestHandPos[5]; - (*i)->getMyCards(tmpCards); - tmpPlayerResult.cards[0] = static_cast(tmpCards[0]); - tmpPlayerResult.cards[1] = static_cast(tmpCards[1]); - - (*i)->getMyBestHandPosition(bestHandPos); - for (int num = 0; num < 5; num++) - tmpPlayerResult.bestHandPos[num] = bestHandPos[num]; - - tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt(); - tmpPlayerResult.moneyWon = 0; // TODO - tmpPlayerResult.playerMoney = (*i)->getMyCash(); - - endHandData.playerResults.push_back(tmpPlayerResult); - ++i; - } - static_cast(endHand.get())->SetData(endHandData); - - server.SendToAllPlayers(endHand, SessionData::Game); - } - - // Remove disconnected players. This is the one and only place to do this. - server.RemoveDisconnectedPlayers(); - - // Start next hand - if enough players are left. - list > playersWithCash = *curGame.getActivePlayerList(); - playersWithCash.remove_if(boost::bind(&PlayerInterface::getMyCash, _1) < 1); - - if (playersWithCash.empty()) - { - // No more players left - restart. - server.SetState(SERVER_INITIAL_STATE::Instance()); - retVal = MSG_NET_GAME_SERVER_END; - } - else if (playersWithCash.size() == 1) - { - // View a dialog for a new game - delayed. - server.SetState(ServerGameStateNextGameDelay::Instance()); - retVal = MSG_NET_GAME_SERVER_END; - } - else - { - server.SetState(ServerGameStateNextHandDelay::Instance()); - retVal = MSG_NET_GAME_SERVER_HAND_END; - } - } - } - return retVal; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateWaitPlayerAction::Ptr; - -ServerGameStateWaitPlayerAction & -ServerGameStateWaitPlayerAction::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateWaitPlayerAction); - - return *Ptr; -} - -ServerGameStateWaitPlayerAction::ServerGameStateWaitPlayerAction() -{ -} - -ServerGameStateWaitPlayerAction::~ServerGameStateWaitPlayerAction() -{ -} - -int -ServerGameStateWaitPlayerAction::Process(ServerGameThread &server) -{ - int retVal; - - boost::shared_ptr curPlayer = server.GetGame().getCurrentPlayer(); - if (!curPlayer.get()) - throw NetException(ERR_NET_NO_CURRENT_PLAYER, 0); - - // If the player is computer controlled, let the engine act. - if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) - { - server.SetState(ServerGameStateComputerAction::Instance()); - retVal = MSG_SOCK_INTERNAL_PENDING; - } - // If the player we are waiting for left, continue without him. - else if (!server.GetSessionManager().IsPlayerConnected(curPlayer->getMyName())) - { - PerformPlayerAction(server, curPlayer, PLAYER_ACTION_FOLD, 0); - - server.SetState(ServerGameStateStartRound::Instance()); - retVal = MSG_NET_GAME_SERVER_ACTION; - } - else if (GetTimer().elapsed().total_seconds() >= server.GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC) - { - // Player did not act fast enough. Act for him. - if (server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet() == curPlayer->getMySet()) - PerformPlayerAction(server, curPlayer, PLAYER_ACTION_CHECK, 0); - else - PerformPlayerAction(server, curPlayer, PLAYER_ACTION_FOLD, 0); - - server.SetState(ServerGameStateStartRound::Instance()); - retVal = MSG_NET_GAME_SERVER_ACTION; - } - else - retVal = AbstractServerGameStateReceiving::Process(server); - - return retVal; -} - -int -ServerGameStateWaitPlayerAction::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr packet) -{ - int retVal = MSG_SOCK_INTERNAL_PENDING; - - if (packet->ToNetPacketPlayersAction()) - { - NetPacketPlayersAction::Data actionData; - packet->ToNetPacketPlayersAction()->GetData(actionData); - - Game &curGame = server.GetGame(); - boost::shared_ptr tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId()); - if (!tmpPlayer.get()) - throw NetException(ERR_NET_UNKNOWN_PLAYER_ID, 0); - - // Check whether this is the correct round. - PlayerActionCode code = ACTION_CODE_VALID; - if (curGame.getCurrentHand()->getActualRound() != actionData.gameState) - code = ACTION_CODE_INVALID_STATE; - - // Check whether this is the correct player. - boost::shared_ptr curPlayer = server.GetGame().getCurrentPlayer(); - if (code == ACTION_CODE_VALID - && (curPlayer->getMyUniqueID() != tmpPlayer->getMyUniqueID())) - { - code = ACTION_CODE_NOT_YOUR_TURN; - } - - // Check whether the action is valid. - if (code == ACTION_CODE_VALID - && (tmpPlayer->checkMyAction( - actionData.playerAction, - actionData.playerBet, - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet(), - curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(), - curGame.getCurrentHand()->getSmallBlind()) != 0)) - { - code = ACTION_CODE_NOT_ALLOWED; - } - - if (code == ACTION_CODE_VALID) - { - PerformPlayerAction(server, tmpPlayer, actionData.playerAction, actionData.playerBet); - server.SetState(ServerGameStateStartRound::Instance()); - retVal = MSG_NET_GAME_SERVER_ACTION; - } - else - { - // Send reject message. - boost::shared_ptr reject(new NetPacketPlayersActionRejected); - NetPacketPlayersActionRejected::Data rejectData; - rejectData.gameState = actionData.gameState; - rejectData.playerAction = actionData.playerAction; - rejectData.playerBet = actionData.playerBet; - rejectData.rejectionReason = code; - static_cast(reject.get())->SetData(rejectData); - server.GetSender().Send(session.sessionData->GetSocket(), reject); - } - } - - return retVal; -} - -void -ServerGameStateWaitPlayerAction::PerformPlayerAction(ServerGameThread &server, boost::shared_ptr player, PlayerAction action, int bet) -{ - Game &curGame = server.GetGame(); - assert(player); - player->setMyAction(action); - // Only change the player bet if action is not fold/check - if (action != PLAYER_ACTION_FOLD && action != PLAYER_ACTION_CHECK) - { - - player->setMySet(bet); - - // update minimumRaise - switch(action) { - case PLAYER_ACTION_BET: { - curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(bet); - } break; - case PLAYER_ACTION_RAISE: { - curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()); - } break; - case PLAYER_ACTION_ALLIN: { - if(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() > curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise()) { - curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()); - } - } break; - default: { - } - } - - // update highestSet - if (player->getMySet() > curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()) - curGame.getCurrentHand()->getCurrentBeRo()->setHighestSet(player->getMySet()); - // Update total sets. - curGame.getCurrentHand()->getBoard()->collectSets(); - } - - - SendPlayerAction(server, player); -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateComputerAction::Ptr; - -ServerGameStateComputerAction & -ServerGameStateComputerAction::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateComputerAction); - - return *Ptr; -} - -ServerGameStateComputerAction::ServerGameStateComputerAction() -{ -} - -ServerGameStateComputerAction::~ServerGameStateComputerAction() -{ -} - -int -ServerGameStateComputerAction::Process(ServerGameThread &server) -{ - int retVal = AbstractServerGameStateReceiving::Process(server); - - if (GetTimer().elapsed().total_seconds() >= SERVER_COMPUTER_ACTION_DELAY_SEC) - { - boost::shared_ptr tmpPlayer = server.GetGame().getCurrentPlayer(); - - tmpPlayer->action(); - SendPlayerAction(server, tmpPlayer); - - server.SetState(ServerGameStateStartRound::Instance()); - retVal = MSG_NET_GAME_SERVER_ACTION; - } - - return retVal; -} - -int -ServerGameStateComputerAction::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) -{ - return MSG_SOCK_INTERNAL_PENDING; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateDealCardsDelay::Ptr; - -ServerGameStateDealCardsDelay & -ServerGameStateDealCardsDelay::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateDealCardsDelay); - - return *Ptr; -} - -ServerGameStateDealCardsDelay::ServerGameStateDealCardsDelay() -{ -} - -ServerGameStateDealCardsDelay::~ServerGameStateDealCardsDelay() -{ -} - -int -ServerGameStateDealCardsDelay::Process(ServerGameThread &server) -{ - int retVal = AbstractServerGameStateReceiving::Process(server); - - Game &curGame = server.GetGame(); - - int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0; - int delay = 0; - - switch(curGame.getCurrentHand()->getActualRound()) - { - case GAME_STATE_FLOP: - delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC; - break; - case GAME_STATE_TURN: - delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay; - break; - case GAME_STATE_RIVER: - delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC; - break; - } - if (!delay || GetTimer().elapsed().total_seconds() >= delay) - server.SetState(ServerGameStateStartRound::Instance()); - - return retVal; -} - -int -ServerGameStateDealCardsDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) -{ - return MSG_SOCK_INTERNAL_PENDING; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateShowCardsDelay::Ptr; - -ServerGameStateShowCardsDelay & -ServerGameStateShowCardsDelay::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateShowCardsDelay); - - return *Ptr; -} - -ServerGameStateShowCardsDelay::ServerGameStateShowCardsDelay() -{ -} - -ServerGameStateShowCardsDelay::~ServerGameStateShowCardsDelay() -{ -} - -int -ServerGameStateShowCardsDelay::Process(ServerGameThread &server) -{ - int retVal = AbstractServerGameStateReceiving::Process(server); - - if (GetTimer().elapsed().total_seconds() >= SERVER_SHOW_CARDS_DELAY_SEC) - { - Game &curGame = server.GetGame(); - SendNewRoundCards(server, curGame, curGame.getCurrentHand()->getActualRound()); - - server.SetState(ServerGameStateDealCardsDelay::Instance()); - retVal = MSG_NET_GAME_SERVER_CARDS_DELAY; - } - - return retVal; -} - -int -ServerGameStateShowCardsDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) -{ - return MSG_SOCK_INTERNAL_PENDING; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateNextHandDelay::Ptr; - -ServerGameStateNextHandDelay & -ServerGameStateNextHandDelay::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateNextHandDelay); - - return *Ptr; -} - -ServerGameStateNextHandDelay::ServerGameStateNextHandDelay() -{ -} - -ServerGameStateNextHandDelay::~ServerGameStateNextHandDelay() -{ -} - -int -ServerGameStateNextHandDelay::Process(ServerGameThread &server) -{ - int retVal = AbstractServerGameStateReceiving::Process(server); - - if (GetTimer().elapsed().total_seconds() >= SERVER_DELAY_NEXT_HAND_SEC) - server.SetState(ServerGameStateStartHand::Instance()); - - return retVal; -} - -int -ServerGameStateNextHandDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) -{ - return MSG_SOCK_INTERNAL_PENDING; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateNextGameDelay::Ptr; - -ServerGameStateNextGameDelay & -ServerGameStateNextGameDelay::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateNextGameDelay); - - return *Ptr; -} - -ServerGameStateNextGameDelay::ServerGameStateNextGameDelay() -{ -} - -ServerGameStateNextGameDelay::~ServerGameStateNextGameDelay() -{ -} - -int -ServerGameStateNextGameDelay::Process(ServerGameThread &server) -{ - int retVal = AbstractServerGameStateReceiving::Process(server); - - if (GetTimer().elapsed().total_seconds() >= SERVER_DELAY_NEXT_GAME_SEC) - { - Game &curGame = server.GetGame(); - // The game has ended. Notify all clients. - boost::shared_ptr winnerPlayer; - PlayerListIterator i = curGame.getActivePlayerList()->begin(); - PlayerListIterator end = curGame.getActivePlayerList()->end(); - while (i != end) - { - winnerPlayer = *i; - if (winnerPlayer->getMyCash() > 0) - break; - ++i; - } - - boost::shared_ptr endGame(new NetPacketEndOfGame); - NetPacketEndOfGame::Data endGameData; - endGameData.winnerPlayerId = winnerPlayer->getMyUniqueID(); - static_cast(endGame.get())->SetData(endGameData); - - server.SendToAllPlayers(endGame, SessionData::Game); - - // Wait for the start of a new game. - server.ResetComputerPlayerList(); - server.ResetGame(); - server.SetState(ServerGameStateInit::Instance()); - server.GetLobbyThread().NotifyReopeningGame(server.GetId()); - } - - return retVal; -} - -int -ServerGameStateNextGameDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) -{ - return MSG_SOCK_INTERNAL_PENDING; -} - -//----------------------------------------------------------------------------- - -boost::thread_specific_ptr ServerGameStateFinal::Ptr; - -ServerGameStateFinal & -ServerGameStateFinal::Instance() -{ - if (!Ptr.get()) - Ptr.reset(new ServerGameStateFinal); - - return *Ptr; -} - -ServerGameStateFinal::ServerGameStateFinal() -{ -} - -ServerGameStateFinal::~ServerGameStateFinal() -{ -} - -int -ServerGameStateFinal::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) -{ - return MSG_SOCK_INTERNAL_PENDING; -} - -//----------------------------------------------------------------------------- +/*************************************************************************** + * Copyright (C) 2007 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace std; + +#define SERVER_WAIT_TIMEOUT_MSEC 50 +#define SERVER_DELAY_NEXT_HAND_SEC 10 +#define SERVER_DELAY_NEXT_GAME_SEC 10 +#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5 +#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2 +#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2 +#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 2 +#define SERVER_SHOW_CARDS_DELAY_SEC 2 +#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2 +#define SERVER_COMPUTER_ACTION_DELAY_SEC 2 +#define SERVER_START_GAME_TIMEOUT_SEC 10 + +#define SERVER_COMPUTER_PLAYER_NAME "Computer" + +// Helper functions +// TODO: these are hacks. + +static void SendPlayerAction(ServerGameThread &server, boost::shared_ptr player) +{ + assert(player); + + boost::shared_ptr notifyActionDone(new NetPacketPlayersActionDone); + NetPacketPlayersActionDone::Data actionDoneData; + actionDoneData.gameState = server.GetCurRound(); + actionDoneData.playerId = player->getMyUniqueID(); + actionDoneData.playerAction = static_cast(player->getMyAction()); + actionDoneData.totalPlayerBet = player->getMySet(); + actionDoneData.playerMoney = player->getMyCash(); + actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); + static_cast(notifyActionDone.get())->SetData(actionDoneData); + server.SendToAllPlayers(notifyActionDone, SessionData::Game); +} + +static void SendNewRoundCards(ServerGameThread &server, Game &curGame, int state) +{ + // TODO: no switch needed here if game states are polymorphic + switch(state) { + case GAME_STATE_PREFLOP: { + // nothing to do + } break; + case GAME_STATE_FLOP: { + // deal flop cards + int cards[5]; + curGame.getCurrentHand()->getBoard()->getMyCards(cards); + boost::shared_ptr notifyCards(new NetPacketDealFlopCards); + NetPacketDealFlopCards::Data notifyCardsData; + for (int num = 0; num < 3; num++) + notifyCardsData.flopCards[num] = static_cast(cards[num]); + static_cast(notifyCards.get())->SetData(notifyCardsData); + server.SendToAllPlayers(notifyCards, SessionData::Game); + } break; + case GAME_STATE_TURN: { + // deal turn card + int cards[5]; + curGame.getCurrentHand()->getBoard()->getMyCards(cards); + boost::shared_ptr notifyCards(new NetPacketDealTurnCard); + NetPacketDealTurnCard::Data notifyCardsData; + notifyCardsData.turnCard = static_cast(cards[3]); + static_cast(notifyCards.get())->SetData(notifyCardsData); + server.SendToAllPlayers(notifyCards, SessionData::Game); + } break; + case GAME_STATE_RIVER: { + // deal river card + int cards[5]; + curGame.getCurrentHand()->getBoard()->getMyCards(cards); + boost::shared_ptr notifyCards(new NetPacketDealRiverCard); + NetPacketDealRiverCard::Data notifyCardsData; + notifyCardsData.riverCard = static_cast(cards[4]); + static_cast(notifyCards.get())->SetData(notifyCardsData); + server.SendToAllPlayers(notifyCards, SessionData::Game); + } break; + default: { + // + } + } +} + +//----------------------------------------------------------------------------- + +ServerGameState::~ServerGameState() +{ +} + +//----------------------------------------------------------------------------- + +AbstractServerGameStateReceiving::AbstractServerGameStateReceiving() +{ +} + +AbstractServerGameStateReceiving::~AbstractServerGameStateReceiving() +{ +} + +int +AbstractServerGameStateReceiving::Process(ServerGameThread &server) +{ + // This is the receive loop for the server. + int retVal = MSG_SOCK_INTERNAL_PENDING; + SessionWrapper session = server.GetSessionManager().Select(RECV_TIMEOUT_MSEC); + + if (session.sessionData.get()) + { + boost::shared_ptr packet; + try + { + // Receive the packet. + packet = server.GetReceiver().Recv(session.sessionData->GetSocket(), session.sessionData->GetReceiveBuffer()); + } catch (const NetException &) + { + server.ErrorRemoveSession(session); + return retVal; + } + + // Process packet if one was received. + if (packet.get()) + { + if (packet->ToNetPacketRetrievePlayerInfo()) + { + // Delegate to Lobby. + server.GetLobbyThread().HandleGameRetrievePlayerInfo(session, *packet->ToNetPacketRetrievePlayerInfo()); + } + else if (packet->ToNetPacketRetrieveAvatar()) + { + // Delegate to Lobby. + server.GetLobbyThread().HandleGameRetrieveAvatar(session, *packet->ToNetPacketRetrieveAvatar()); + } + else if (packet->ToNetPacketLeaveCurrentGame()) + { + server.MoveSessionToLobby(session, NTF_NET_REMOVED_ON_REQUEST); + } + // Chat text is always allowed. + else if (packet->ToNetPacketSendChatText()) + { + if (session.playerData.get()) // Only forward if this player is known. + { + // Forward chat text to all players. + // TODO: Some limitation needed. + NetPacketSendChatText::Data inChatData; + packet->ToNetPacketSendChatText()->GetData(inChatData); + + boost::shared_ptr outChat(new NetPacketChatText); + NetPacketChatText::Data outChatData; + outChatData.playerId = session.playerData->GetUniqueId(); + outChatData.text = inChatData.text; + static_cast(outChat.get())->SetData(outChatData); + server.SendToAllPlayers(outChat, SessionData::Game); + } + } + else + { + // Packet processing in subclass. + retVal = InternalProcess(server, session, packet); + } + } + } + return retVal; +} + +//----------------------------------------------------------------------------- + +AbstractServerGameStateTimer::AbstractServerGameStateTimer() +: m_timer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::microsec_timer::manual_start) +{ +} + +AbstractServerGameStateTimer::~AbstractServerGameStateTimer() +{ +} + +void +AbstractServerGameStateTimer::Init() +{ + m_timer.reset(); + m_timer.start(); +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateInit::Ptr; + +ServerGameStateInit & +ServerGameStateInit::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateInit); + + return *Ptr; +} + +ServerGameStateInit::ServerGameStateInit() +{ +} + +ServerGameStateInit::~ServerGameStateInit() +{ +} + +void +ServerGameStateInit::HandleNewSession(ServerGameThread &server, SessionWrapper session) +{ + if (session.sessionData.get() && session.playerData.get()) + { + size_t curNumPlayers = server.GetCurNumberOfPlayers(); + + // Check the number of players. + if (curNumPlayers >= (size_t)server.GetGameData().maxNumberOfPlayers) + { + server.MoveSessionToLobby(session, NTF_NET_REMOVED_GAME_FULL); + } + else + { + if (session.playerData->GetUniqueId() == server.GetAdminPlayerId()) + { + // This is the admin player. + session.playerData->SetRights(PLAYER_RIGHTS_ADMIN); + } + + // Send ack to client. + boost::shared_ptr joinGameAck(new NetPacketJoinGameAck); + NetPacketJoinGameAck::Data joinGameAckData; + joinGameAckData.gameId = server.GetId(); + joinGameAckData.prights = session.playerData->GetRights(); + joinGameAckData.gameData = server.GetGameData(); + static_cast(joinGameAck.get())->SetData(joinGameAckData); + server.GetSender().Send(session.sessionData->GetSocket(), joinGameAck); + + // Send notifications for connected players to client. + PlayerDataList tmpPlayerList = server.GetFullPlayerDataList(); + PlayerDataList::iterator player_i = tmpPlayerList.begin(); + PlayerDataList::iterator player_end = tmpPlayerList.end(); + while (player_i != player_end) + { + server.GetSender().Send(session.sessionData->GetSocket(), CreateNetPacketPlayerJoined(*(*player_i))); + ++player_i; + } + + // Send "Player Joined" to other fully connected clients. + server.SendToAllPlayers(CreateNetPacketPlayerJoined(*session.playerData), SessionData::Game); + + // Accept session. + server.GetSessionManager().AddSession(session); + + // Notify lobby. + server.GetLobbyThread().NotifyPlayerJoinedGame(server.GetId(), session.playerData->GetUniqueId()); + } + } +} + +int +ServerGameStateInit::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr packet) +{ + int retVal = MSG_SOCK_INTERNAL_PENDING; + + if (packet->ToNetPacketStartEvent()) + { + // Only admins are allowed to start the game. + if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN) + { + NetPacketStartEvent::Data startData; + packet->ToNetPacketStartEvent()->GetData(startData); + + // Fill up with computer players. + server.ResetComputerPlayerList(); + + if (startData.fillUpWithCpuPlayers) + { + int remainingSlots = server.GetGameData().maxNumberOfPlayers - server.GetCurNumberOfPlayers(); + for (int i = 1; i <= remainingSlots; i++) + { + boost::shared_ptr tmpPlayerData( + new PlayerData(server.GetLobbyThread().GetNextUniquePlayerId(), 0, PLAYER_TYPE_COMPUTER, PLAYER_RIGHTS_NORMAL)); + + ostringstream name; + name << SERVER_COMPUTER_PLAYER_NAME << i; + tmpPlayerData->SetName(name.str()); + server.AddComputerPlayer(tmpPlayerData); + + // Send "Player Joined" to other fully connected clients. + server.SendToAllPlayers(CreateNetPacketPlayerJoined(*tmpPlayerData), SessionData::Game); + } + } + // Wait for all players to confirm start of game. + server.SendToAllPlayers(boost::shared_ptr(packet->Clone()), SessionData::Game); + + server.SetState(ServerGameStateWaitAck::Instance()); + } + } + else if (packet->ToNetPacketKickPlayer()) + { + // Only admins are allowed to kick. + if (session.playerData->GetRights() == PLAYER_RIGHTS_ADMIN) + { + NetPacketKickPlayer::Data kickPlayerData; + packet->ToNetPacketKickPlayer()->GetData(kickPlayerData); + + server.InternalKickPlayer(kickPlayerData.playerId); + } + } + else + { + server.SessionError(session, ERR_SOCK_INVALID_PACKET); + } + + return retVal; +} + +boost::shared_ptr +ServerGameStateInit::CreateNetPacketPlayerJoined(const PlayerData &playerData) +{ + boost::shared_ptr thisPlayerJoined(new NetPacketPlayerJoined); + NetPacketPlayerJoined::Data thisPlayerJoinedData; + thisPlayerJoinedData.playerId = playerData.GetUniqueId(); + thisPlayerJoinedData.prights = playerData.GetRights(); + static_cast(thisPlayerJoined.get())->SetData(thisPlayerJoinedData); + return thisPlayerJoined; +} + +//----------------------------------------------------------------------------- + +AbstractServerGameStateRunning::AbstractServerGameStateRunning() +{ +} + +AbstractServerGameStateRunning::~AbstractServerGameStateRunning() +{ +} + +void +AbstractServerGameStateRunning::HandleNewSession(ServerGameThread &server, SessionWrapper session) +{ + // Do not accept new sessions in this state. + server.MoveSessionToLobby(session, NTF_NET_REMOVED_ALREADY_RUNNING); +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateWaitAck::Ptr; + +ServerGameStateWaitAck & +ServerGameStateWaitAck::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateWaitAck); + + return *Ptr; +} + +ServerGameStateWaitAck::ServerGameStateWaitAck() +{ +} + +ServerGameStateWaitAck::~ServerGameStateWaitAck() +{ +} + +int +ServerGameStateWaitAck::Process(ServerGameThread &server) +{ + int retVal; + + if (GetTimer().elapsed().total_seconds() >= SERVER_START_GAME_TIMEOUT_SEC) + { + // On timeout: start anyway. + server.SetState(SERVER_START_GAME_STATE::Instance()); + retVal = MSG_SOCK_INIT_DONE; + } + else + retVal = AbstractServerGameStateReceiving::Process(server); + + return retVal; +} + +int +ServerGameStateWaitAck::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr packet) +{ + int retVal = MSG_SOCK_INTERNAL_PENDING; + + if (packet->ToNetPacketStartEventAck()) + { + session.sessionData->SetReadyFlag(); + if (server.GetSessionManager().CountReadySessions() == server.GetSessionManager().GetRawSessionCount()) + { + // Everyone is ready. + server.GetSessionManager().ResetAllReadyFlags(); + server.SetState(SERVER_START_GAME_STATE::Instance()); + retVal = MSG_SOCK_INIT_DONE; + } + retVal = MSG_SOCK_INIT_DONE; + } + + return retVal; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateStartGame::Ptr; + +ServerGameStateStartGame & +ServerGameStateStartGame::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateStartGame); + + return *Ptr; +} + +ServerGameStateStartGame::ServerGameStateStartGame() +{ +} + +ServerGameStateStartGame::~ServerGameStateStartGame() +{ +} + +int +ServerGameStateStartGame::Process(ServerGameThread &server) +{ + server.InternalStartGame(); + + boost::shared_ptr answer(new NetPacketGameStart); + + NetPacketGameStart::Data gameStartData; + gameStartData.startData = server.GetStartData(); + + // Send player order to clients. + // Assume player list is sorted by number. + PlayerDataList tmpPlayerList = server.GetFullPlayerDataList(); + PlayerDataList::iterator player_i = tmpPlayerList.begin(); + PlayerDataList::iterator player_end = tmpPlayerList.end(); + while (player_i != player_end) + { + NetPacketGameStart::PlayerSlot tmpPlayerSlot; + tmpPlayerSlot.playerId = (*player_i)->GetUniqueId(); + gameStartData.playerSlots.push_back(tmpPlayerSlot); + + ++player_i; + } + + static_cast(answer.get())->SetData(gameStartData); + + server.SendToAllPlayers(answer, SessionData::Game); + server.SetState(ServerGameStateStartHand::Instance()); + + return MSG_NET_GAME_SERVER_START; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateStartHand::Ptr; + +ServerGameStateStartHand & +ServerGameStateStartHand::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateStartHand); + + return *Ptr; +} + +ServerGameStateStartHand::ServerGameStateStartHand() +{ +} + +ServerGameStateStartHand::~ServerGameStateStartHand() +{ +} + +int +ServerGameStateStartHand::Process(ServerGameThread &server) +{ + // Initialize hand. + Game &curGame = server.GetGame(); + curGame.initHand(); + + // HACK: Skip GUI notification run + curGame.getCurrentHand()->getFlop()->skipFirstRunGui(); + curGame.getCurrentHand()->getTurn()->skipFirstRunGui(); + curGame.getCurrentHand()->getRiver()->skipFirstRunGui(); + + // Consider all players, even inactive. + PlayerListIterator i = curGame.getSeatsList()->begin(); + PlayerListIterator end = curGame.getSeatsList()->end(); + + // Send cards to all players. + while (i != end) + { + // also send to inactive players, but not to disconnected players. + boost::shared_ptr tmpPlayer = *i; + if (tmpPlayer->getNetSessionData().get()) + { + int cards[2]; + 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]); + handStartData.smallBlind = curGame.getCurrentHand()->getSmallBlind(); + static_cast(notifyCards.get())->SetData(handStartData); + + server.GetSender().Send(tmpPlayer->getNetSessionData()->GetSocket(), notifyCards); + } + ++i; + } + + // Start hand. + curGame.startHand(); + + // Auto small blind / big blind at the beginning of hand. + i = curGame.getActivePlayerList()->begin(); + end = curGame.getActivePlayerList()->end(); + + while (i != end) + { + 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 = tmpPlayer->getMyUniqueID(); + actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction(); + actionDoneData.totalPlayerBet = tmpPlayer->getMySet(); + actionDoneData.playerMoney = tmpPlayer->getMyCash(); + actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); + static_cast(notifySmallBlind.get())->SetData(actionDoneData); + server.SendToAllPlayers(notifySmallBlind, SessionData::Game); + break; + } + ++i; + } + + i = curGame.getActivePlayerList()->begin(); + end = curGame.getActivePlayerList()->end(); + while (i != end) + { + 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 = tmpPlayer->getMyUniqueID(); + actionDoneData.playerAction = (PlayerAction)tmpPlayer->getMyAction(); + actionDoneData.totalPlayerBet = tmpPlayer->getMySet(); + actionDoneData.playerMoney = tmpPlayer->getMyCash(); + actionDoneData.highestSet = server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet(); + static_cast(notifyBigBlind.get())->SetData(actionDoneData); + server.SendToAllPlayers(notifyBigBlind, SessionData::Game); + break; + } + ++i; + } + + server.SetState(ServerGameStateStartRound::Instance()); + + return MSG_NET_GAME_SERVER_HAND_START; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateStartRound::Ptr; + +ServerGameStateStartRound & +ServerGameStateStartRound::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateStartRound); + + return *Ptr; +} + +ServerGameStateStartRound::ServerGameStateStartRound() +{ +} + +ServerGameStateStartRound::~ServerGameStateStartRound() +{ +} + +int +ServerGameStateStartRound::Process(ServerGameThread &server) +{ + int retVal = MSG_SOCK_INTERNAL_PENDING; + Game &curGame = server.GetGame(); + + // Main game loop. + int curRound = curGame.getCurrentHand()->getCurrentRound(); + curGame.getCurrentHand()->switchRounds(); + if (!curGame.getCurrentHand()->getAllInCondition()) + curGame.getCurrentHand()->getCurrentBeRo()->run(); + int newRound = curGame.getCurrentHand()->getCurrentRound(); + + // If round changes, deal cards if needed. + if (newRound != curRound && newRound != GAME_STATE_POST_RIVER) + { + assert(newRound > curRound); + // Retrieve non-fold players. If only one player is left, no cards are shown. + list > nonFoldPlayers = *curGame.getActivePlayerList(); + nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD); + + if (curGame.getCurrentHand()->getAllInCondition() + && !curGame.getCurrentHand()->getCardsShown() + && nonFoldPlayers.size() > 1) + { + // Send cards of all active players to all players (all in). + boost::shared_ptr allIn(new NetPacketAllInShowCards); + NetPacketAllInShowCards::Data allInData; + + PlayerListConstIterator i = nonFoldPlayers.begin(); + PlayerListConstIterator end = nonFoldPlayers.end(); + + while (i != end) + { + NetPacketAllInShowCards::PlayerCards tmpPlayerCards; + tmpPlayerCards.playerId = (*i)->getMyUniqueID(); + + int tmpCards[2]; + (*i)->getMyCards(tmpCards); + tmpPlayerCards.cards[0] = static_cast(tmpCards[0]); + tmpPlayerCards.cards[1] = static_cast(tmpCards[1]); + + allInData.playerCards.push_back(tmpPlayerCards); + ++i; + } + static_cast(allIn.get())->SetData(allInData); + server.SendToAllPlayers(allIn, SessionData::Game); + curGame.getCurrentHand()->setCardsShown(true); + + server.SetState(ServerGameStateShowCardsDelay::Instance()); + retVal = MSG_NET_GAME_SERVER_CARDS_DELAY; + } + else + { + SendNewRoundCards(server, curGame, newRound); + + server.SetState(ServerGameStateDealCardsDelay::Instance()); + retVal = MSG_NET_GAME_SERVER_CARDS_DELAY; + } + } + else + { + if (newRound != GAME_STATE_POST_RIVER) // continue hand + { + assert (!curGame.getCurrentHand()->getAllInCondition()); // this would be an error. + + // Retrieve current player. + boost::shared_ptr curPlayer = curGame.getCurrentPlayer(); + if (!curPlayer.get()) + throw NetException(ERR_NET_NO_CURRENT_PLAYER, 0); + if (!curPlayer->getMyActiveStatus()) + throw NetException(ERR_NET_PLAYER_NOT_ACTIVE, 0); + + boost::shared_ptr notification(new NetPacketPlayersTurn); + NetPacketPlayersTurn::Data playersTurnData; + playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getCurrentRound(); + playersTurnData.playerId = curPlayer->getMyUniqueID(); + playersTurnData.minimumRaise = curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(); + static_cast(notification.get())->SetData(playersTurnData); + + server.SendToAllPlayers(notification, SessionData::Game); + + server.SetState(ServerGameStateWaitPlayerAction::Instance()); + + retVal = MSG_NET_GAME_SERVER_ROUND; + } + else // hand is over + { + // Engine will find out who won. + curGame.getCurrentHand()->getCurrentBeRo()->postRiverRun(); + + // Retrieve non-fold players. If only one player is left, no cards are shown. + list > nonFoldPlayers = *curGame.getActivePlayerList(); + nonFoldPlayers.remove_if(boost::bind(&PlayerInterface::getMyAction, _1) == PLAYER_ACTION_FOLD); + + if (nonFoldPlayers.size() == 1) + { + // End of Hand, but keep cards hidden. + boost::shared_ptr player = nonFoldPlayers.front(); + boost::shared_ptr endHand(new NetPacketEndOfHandHideCards); + NetPacketEndOfHandHideCards::Data endHandData; + endHandData.playerId = player->getMyUniqueID(); + endHandData.moneyWon = 0; // TODO + endHandData.playerMoney = player->getMyCash(); + static_cast(endHand.get())->SetData(endHandData); + + server.SendToAllPlayers(endHand, SessionData::Game); + } + else + { + // End of Hand - show cards of active players. + boost::shared_ptr endHand(new NetPacketEndOfHandShowCards); + NetPacketEndOfHandShowCards::Data endHandData; + + PlayerListConstIterator i = nonFoldPlayers.begin(); + PlayerListConstIterator end = nonFoldPlayers.end(); + + while (i != end) + { + NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult; + tmpPlayerResult.playerId = (*i)->getMyUniqueID(); + + int tmpCards[2]; + int bestHandPos[5]; + (*i)->getMyCards(tmpCards); + tmpPlayerResult.cards[0] = static_cast(tmpCards[0]); + tmpPlayerResult.cards[1] = static_cast(tmpCards[1]); + + (*i)->getMyBestHandPosition(bestHandPos); + for (int num = 0; num < 5; num++) + tmpPlayerResult.bestHandPos[num] = bestHandPos[num]; + + tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt(); + tmpPlayerResult.moneyWon = 0; // TODO + tmpPlayerResult.playerMoney = (*i)->getMyCash(); + + endHandData.playerResults.push_back(tmpPlayerResult); + ++i; + } + static_cast(endHand.get())->SetData(endHandData); + + server.SendToAllPlayers(endHand, SessionData::Game); + } + + // Remove disconnected players. This is the one and only place to do this. + server.RemoveDisconnectedPlayers(); + + // Start next hand - if enough players are left. + list > playersWithCash = *curGame.getActivePlayerList(); + playersWithCash.remove_if(boost::bind(&PlayerInterface::getMyCash, _1) < 1); + + if (playersWithCash.empty()) + { + // No more players left - restart. + server.SetState(SERVER_INITIAL_STATE::Instance()); + retVal = MSG_NET_GAME_SERVER_END; + } + else if (playersWithCash.size() == 1) + { + // View a dialog for a new game - delayed. + server.SetState(ServerGameStateNextGameDelay::Instance()); + retVal = MSG_NET_GAME_SERVER_END; + } + else + { + server.SetState(ServerGameStateNextHandDelay::Instance()); + retVal = MSG_NET_GAME_SERVER_HAND_END; + } + } + } + return retVal; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateWaitPlayerAction::Ptr; + +ServerGameStateWaitPlayerAction & +ServerGameStateWaitPlayerAction::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateWaitPlayerAction); + + return *Ptr; +} + +ServerGameStateWaitPlayerAction::ServerGameStateWaitPlayerAction() +{ +} + +ServerGameStateWaitPlayerAction::~ServerGameStateWaitPlayerAction() +{ +} + +int +ServerGameStateWaitPlayerAction::Process(ServerGameThread &server) +{ + int retVal; + + boost::shared_ptr curPlayer = server.GetGame().getCurrentPlayer(); + if (!curPlayer.get()) + throw NetException(ERR_NET_NO_CURRENT_PLAYER, 0); + + // If the player is computer controlled, let the engine act. + if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) + { + server.SetState(ServerGameStateComputerAction::Instance()); + retVal = MSG_SOCK_INTERNAL_PENDING; + } + // If the player we are waiting for left, continue without him. + else if (!server.GetSessionManager().IsPlayerConnected(curPlayer->getMyName())) + { + PerformPlayerAction(server, curPlayer, PLAYER_ACTION_FOLD, 0); + + server.SetState(ServerGameStateStartRound::Instance()); + retVal = MSG_NET_GAME_SERVER_ACTION; + } + else if (GetTimer().elapsed().total_seconds() >= server.GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC) + { + // Player did not act fast enough. Act for him. + if (server.GetGame().getCurrentHand()->getCurrentBeRo()->getHighestSet() == curPlayer->getMySet()) + PerformPlayerAction(server, curPlayer, PLAYER_ACTION_CHECK, 0); + else + PerformPlayerAction(server, curPlayer, PLAYER_ACTION_FOLD, 0); + + server.SetState(ServerGameStateStartRound::Instance()); + retVal = MSG_NET_GAME_SERVER_ACTION; + } + else + retVal = AbstractServerGameStateReceiving::Process(server); + + return retVal; +} + +int +ServerGameStateWaitPlayerAction::InternalProcess(ServerGameThread &server, SessionWrapper session, boost::shared_ptr packet) +{ + int retVal = MSG_SOCK_INTERNAL_PENDING; + + if (packet->ToNetPacketPlayersAction()) + { + NetPacketPlayersAction::Data actionData; + packet->ToNetPacketPlayersAction()->GetData(actionData); + + Game &curGame = server.GetGame(); + boost::shared_ptr tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId()); + if (!tmpPlayer.get()) + throw NetException(ERR_NET_UNKNOWN_PLAYER_ID, 0); + + // Check whether this is the correct round. + PlayerActionCode code = ACTION_CODE_VALID; + if (curGame.getCurrentHand()->getCurrentRound() != actionData.gameState) + code = ACTION_CODE_INVALID_STATE; + + // Check whether this is the correct player. + boost::shared_ptr curPlayer = server.GetGame().getCurrentPlayer(); + if (code == ACTION_CODE_VALID + && (curPlayer->getMyUniqueID() != tmpPlayer->getMyUniqueID())) + { + code = ACTION_CODE_NOT_YOUR_TURN; + } + + // Check whether the action is valid. + if (code == ACTION_CODE_VALID + && (tmpPlayer->checkMyAction( + actionData.playerAction, + actionData.playerBet, + curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet(), + curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise(), + curGame.getCurrentHand()->getSmallBlind()) != 0)) + { + code = ACTION_CODE_NOT_ALLOWED; + } + + if (code == ACTION_CODE_VALID) + { + PerformPlayerAction(server, tmpPlayer, actionData.playerAction, actionData.playerBet); + server.SetState(ServerGameStateStartRound::Instance()); + retVal = MSG_NET_GAME_SERVER_ACTION; + } + else + { + // Send reject message. + boost::shared_ptr reject(new NetPacketPlayersActionRejected); + NetPacketPlayersActionRejected::Data rejectData; + rejectData.gameState = actionData.gameState; + rejectData.playerAction = actionData.playerAction; + rejectData.playerBet = actionData.playerBet; + rejectData.rejectionReason = code; + static_cast(reject.get())->SetData(rejectData); + server.GetSender().Send(session.sessionData->GetSocket(), reject); + } + } + + return retVal; +} + +void +ServerGameStateWaitPlayerAction::PerformPlayerAction(ServerGameThread &server, boost::shared_ptr player, PlayerAction action, int bet) +{ + Game &curGame = server.GetGame(); + assert(player); + player->setMyAction(action); + // Only change the player bet if action is not fold/check + if (action != PLAYER_ACTION_FOLD && action != PLAYER_ACTION_CHECK) + { + + player->setMySet(bet); + + // update minimumRaise + switch(action) { + case PLAYER_ACTION_BET: { + curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(bet); + } break; + case PLAYER_ACTION_RAISE: { + curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()); + } break; + case PLAYER_ACTION_ALLIN: { + if(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() > curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise()) { + curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()); + } + } break; + default: { + } + } + + // update highestSet + if (player->getMySet() > curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()) + curGame.getCurrentHand()->getCurrentBeRo()->setHighestSet(player->getMySet()); + // Update total sets. + curGame.getCurrentHand()->getBoard()->collectSets(); + } + + + SendPlayerAction(server, player); +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateComputerAction::Ptr; + +ServerGameStateComputerAction & +ServerGameStateComputerAction::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateComputerAction); + + return *Ptr; +} + +ServerGameStateComputerAction::ServerGameStateComputerAction() +{ +} + +ServerGameStateComputerAction::~ServerGameStateComputerAction() +{ +} + +int +ServerGameStateComputerAction::Process(ServerGameThread &server) +{ + int retVal = AbstractServerGameStateReceiving::Process(server); + + if (GetTimer().elapsed().total_seconds() >= SERVER_COMPUTER_ACTION_DELAY_SEC) + { + boost::shared_ptr tmpPlayer = server.GetGame().getCurrentPlayer(); + + tmpPlayer->action(); + SendPlayerAction(server, tmpPlayer); + + server.SetState(ServerGameStateStartRound::Instance()); + retVal = MSG_NET_GAME_SERVER_ACTION; + } + + return retVal; +} + +int +ServerGameStateComputerAction::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) +{ + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateDealCardsDelay::Ptr; + +ServerGameStateDealCardsDelay & +ServerGameStateDealCardsDelay::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateDealCardsDelay); + + return *Ptr; +} + +ServerGameStateDealCardsDelay::ServerGameStateDealCardsDelay() +{ +} + +ServerGameStateDealCardsDelay::~ServerGameStateDealCardsDelay() +{ +} + +int +ServerGameStateDealCardsDelay::Process(ServerGameThread &server) +{ + int retVal = AbstractServerGameStateReceiving::Process(server); + + Game &curGame = server.GetGame(); + + int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0; + int delay = 0; + + switch(curGame.getCurrentHand()->getCurrentRound()) + { + case GAME_STATE_FLOP: + delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC; + break; + case GAME_STATE_TURN: + delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay; + break; + case GAME_STATE_RIVER: + delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC; + break; + } + if (!delay || GetTimer().elapsed().total_seconds() >= delay) + server.SetState(ServerGameStateStartRound::Instance()); + + return retVal; +} + +int +ServerGameStateDealCardsDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) +{ + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateShowCardsDelay::Ptr; + +ServerGameStateShowCardsDelay & +ServerGameStateShowCardsDelay::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateShowCardsDelay); + + return *Ptr; +} + +ServerGameStateShowCardsDelay::ServerGameStateShowCardsDelay() +{ +} + +ServerGameStateShowCardsDelay::~ServerGameStateShowCardsDelay() +{ +} + +int +ServerGameStateShowCardsDelay::Process(ServerGameThread &server) +{ + int retVal = AbstractServerGameStateReceiving::Process(server); + + if (GetTimer().elapsed().total_seconds() >= SERVER_SHOW_CARDS_DELAY_SEC) + { + Game &curGame = server.GetGame(); + SendNewRoundCards(server, curGame, curGame.getCurrentHand()->getCurrentRound()); + + server.SetState(ServerGameStateDealCardsDelay::Instance()); + retVal = MSG_NET_GAME_SERVER_CARDS_DELAY; + } + + return retVal; +} + +int +ServerGameStateShowCardsDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) +{ + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateNextHandDelay::Ptr; + +ServerGameStateNextHandDelay & +ServerGameStateNextHandDelay::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateNextHandDelay); + + return *Ptr; +} + +ServerGameStateNextHandDelay::ServerGameStateNextHandDelay() +{ +} + +ServerGameStateNextHandDelay::~ServerGameStateNextHandDelay() +{ +} + +int +ServerGameStateNextHandDelay::Process(ServerGameThread &server) +{ + int retVal = AbstractServerGameStateReceiving::Process(server); + + if (GetTimer().elapsed().total_seconds() >= SERVER_DELAY_NEXT_HAND_SEC) + server.SetState(ServerGameStateStartHand::Instance()); + + return retVal; +} + +int +ServerGameStateNextHandDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) +{ + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateNextGameDelay::Ptr; + +ServerGameStateNextGameDelay & +ServerGameStateNextGameDelay::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateNextGameDelay); + + return *Ptr; +} + +ServerGameStateNextGameDelay::ServerGameStateNextGameDelay() +{ +} + +ServerGameStateNextGameDelay::~ServerGameStateNextGameDelay() +{ +} + +int +ServerGameStateNextGameDelay::Process(ServerGameThread &server) +{ + int retVal = AbstractServerGameStateReceiving::Process(server); + + if (GetTimer().elapsed().total_seconds() >= SERVER_DELAY_NEXT_GAME_SEC) + { + Game &curGame = server.GetGame(); + // The game has ended. Notify all clients. + boost::shared_ptr winnerPlayer; + PlayerListIterator i = curGame.getActivePlayerList()->begin(); + PlayerListIterator end = curGame.getActivePlayerList()->end(); + while (i != end) + { + winnerPlayer = *i; + if (winnerPlayer->getMyCash() > 0) + break; + ++i; + } + + boost::shared_ptr endGame(new NetPacketEndOfGame); + NetPacketEndOfGame::Data endGameData; + endGameData.winnerPlayerId = winnerPlayer->getMyUniqueID(); + static_cast(endGame.get())->SetData(endGameData); + + server.SendToAllPlayers(endGame, SessionData::Game); + + // Wait for the start of a new game. + server.ResetComputerPlayerList(); + server.ResetGame(); + server.SetState(ServerGameStateInit::Instance()); + server.GetLobbyThread().NotifyReopeningGame(server.GetId()); + } + + return retVal; +} + +int +ServerGameStateNextGameDelay::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) +{ + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- + +boost::thread_specific_ptr ServerGameStateFinal::Ptr; + +ServerGameStateFinal & +ServerGameStateFinal::Instance() +{ + if (!Ptr.get()) + Ptr.reset(new ServerGameStateFinal); + + return *Ptr; +} + +ServerGameStateFinal::ServerGameStateFinal() +{ +} + +ServerGameStateFinal::~ServerGameStateFinal() +{ +} + +int +ServerGameStateFinal::InternalProcess(ServerGameThread &/*server*/, SessionWrapper /*session*/, boost::shared_ptr /*packet*/) +{ + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- diff --git a/src/net/common/servergamethread.cpp b/src/net/common/servergamethread.cpp index d0783558..78fe5ef7 100644 --- a/src/net/common/servergamethread.cpp +++ b/src/net/common/servergamethread.cpp @@ -1,552 +1,552 @@ -/*************************************************************************** - * Copyright (C) 2007 by Lothar May * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; - - -class ServerSenderCallback : public SenderCallback -{ -public: - ServerSenderCallback(ServerGameThread &server) : m_server(server) {} - virtual ~ServerSenderCallback() {} - - virtual void SignalNetError(SOCKET /*sock*/, int /*errorID*/, int /*osErrorID*/) - { - // We just ignore send errors for now, on server side. - // A serious send error should trigger a read error or a read - // returning 0 afterwards, and we will handle this error. - } - -private: - ServerGameThread &m_server; -}; - - -ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig) -: m_lobbyThread(lobbyThread), m_adminPlayerId(adminPlayerId), m_gui(gui), m_id(id), - m_name(name), m_password(pwd), m_playerConfig(playerConfig), m_curState(NULL), m_gameNum(1) -{ - m_senderCallback.reset(new ServerSenderCallback(*this)); - m_sender.reset(new SenderThread(GetSenderCallback())); - m_receiver.reset(new ReceiverHelper); -} - -ServerGameThread::~ServerGameThread() -{ -} - -void -ServerGameThread::Init(const GameData &gameData) -{ - m_gameData = gameData; -} - -u_int32_t -ServerGameThread::GetId() const -{ - return m_id; -} - -const std::string & -ServerGameThread::GetName() const -{ - return m_name; -} - -void -ServerGameThread::AddSession(SessionWrapper session) -{ - // Must be thread safe. - boost::mutex::scoped_lock lock(m_sessionQueueMutex); - m_sessionQueue.push_back(session); -} - -GameState -ServerGameThread::GetCurRound() const -{ - return static_cast(GetGame().getCurrentHand()->getActualRound()); -} - -void -ServerGameThread::SendToAllPlayers(boost::shared_ptr packet, SessionData::State state) -{ - GetSessionManager().SendToAllSessions(GetSender(), packet, state); -} - -void -ServerGameThread::RemoveAllSessions() -{ - // Called from lobby thread. - // Clean up ALL sessions which are left. - ServerLobbyThread &lobbyThread = GetLobbyThread(); - boost::mutex::scoped_lock lock(m_sessionQueueMutex); - while (!m_sessionQueue.empty()) - { - SessionWrapper tmpSession = m_sessionQueue.front(); - m_sessionQueue.pop_front(); - lobbyThread.RemoveSessionFromGame(tmpSession); - } - GetSessionManager().ForEach(boost::bind(&ServerLobbyThread::RemoveSessionFromGame, boost::ref(lobbyThread), _1)); -} - -void -ServerGameThread::Main() -{ - SetState(SERVER_INITIAL_STATE::Instance()); - GetSender().Run(); - - try - { - do - { - { - // Handle one new session at a time. - SessionWrapper tmpSession; - { - boost::mutex::scoped_lock lock(m_sessionQueueMutex); - if (!m_sessionQueue.empty()) - { - tmpSession = m_sessionQueue.front(); - m_sessionQueue.pop_front(); - } - } - if (tmpSession.sessionData.get()) - GetState().HandleNewSession(*this, tmpSession); - } - // Process current state. - GetState().Process(*this); - } while (!ShouldTerminate() && GetSessionManager().HasSessions()); - } catch (const NetException &e) - { - GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); - } - GetSender().SignalTermination(); - GetSender().Join(SENDER_THREAD_TERMINATE_TIMEOUT); - - ResetComputerPlayerList(); - GetLobbyThread().RemoveGame(GetId()); -} - -void -ServerGameThread::InternalStartGame() -{ - // Set order of players. - AssignPlayerNumbers(); - - // Initialize the game. - GuiInterface &gui = GetGui(); - PlayerDataList playerData = GetFullPlayerDataList(); - - // Create EngineFactory - boost::shared_ptr factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen - - // Set start data. - StartData startData; - startData.numberOfPlayers = playerData.size(); - - int tmpDealerPos = 0; - Tools::getRandNumber(0, startData.numberOfPlayers-1, 1, &tmpDealerPos, 0); - // 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(); - - int tmpPos = 0; - while (player_i != player_end) - { - startData.startDealerPlayerId = static_cast((*player_i)->GetUniqueId()); - if (tmpPos == tmpDealerPos) - break; - ++tmpPos; - ++player_i; - } - assert(player_i != player_end); - - SetStartData(startData); - - m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum())); - - GetLobbyThread().NotifyStartingGame(GetId()); -} - -void -ServerGameThread::ResetGame() -{ - m_game.reset(); -} - -void -ServerGameThread::InternalKickPlayer(unsigned playerId) -{ - SessionWrapper tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId); - MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED); -} - -PlayerDataList -ServerGameThread::GetFullPlayerDataList() const -{ - PlayerDataList playerList(GetSessionManager().GetPlayerDataList()); - boost::mutex::scoped_lock lock(m_computerPlayerListMutex); - copy(m_computerPlayerList.begin(), m_computerPlayerList.end(), back_inserter(playerList)); - - return playerList; -} - -boost::shared_ptr -ServerGameThread::GetPlayerDataByUniqueId(unsigned playerId) const -{ - boost::shared_ptr tmpPlayer; - SessionWrapper session = GetSessionManager().GetSessionByUniquePlayerId(playerId); - if (session.playerData.get()) - { - tmpPlayer = session.playerData; - } - else - { - boost::mutex::scoped_lock lock(m_computerPlayerListMutex); - PlayerDataList::const_iterator i = m_computerPlayerList.begin(); - PlayerDataList::const_iterator end = m_computerPlayerList.end(); - while (i != end) - { - if ((*i)->GetUniqueId() == playerId) - { - tmpPlayer = *i; - break; - } - ++i; - } - } - return tmpPlayer; -} - -PlayerIdList -ServerGameThread::GetPlayerIdList() const -{ - PlayerIdList idList(GetSessionManager().GetPlayerIdList()); - boost::mutex::scoped_lock lock(m_computerPlayerListMutex); - PlayerDataList::const_iterator i = m_computerPlayerList.begin(); - PlayerDataList::const_iterator end = m_computerPlayerList.end(); - while (i != end) - { - idList.push_back((*i)->GetUniqueId()); - ++i; - } - - return idList; -} - -bool -ServerGameThread::IsPlayerConnected(const std::string &name) const -{ - return GetSessionManager().IsPlayerConnected(name); -} - -bool -ServerGameThread::IsRunning() const -{ - return m_game.get() != NULL; -} - -unsigned -ServerGameThread::GetAdminPlayerId() const -{ - boost::mutex::scoped_lock lock(m_adminPlayerIdMutex); - return m_adminPlayerId; -} - -void -ServerGameThread::SetAdminPlayerId(unsigned playerId) -{ - boost::mutex::scoped_lock lock(m_adminPlayerIdMutex); - m_adminPlayerId = playerId; -} - -void -ServerGameThread::AddComputerPlayer(boost::shared_ptr player) -{ - { - boost::mutex::scoped_lock lock(m_computerPlayerListMutex); - m_computerPlayerList.push_back(player); - } - GetLobbyThread().AddComputerPlayer(player); -} - -void -ServerGameThread::ResetComputerPlayerList() -{ - boost::mutex::scoped_lock lock(m_computerPlayerListMutex); - - PlayerDataList::iterator i = m_computerPlayerList.begin(); - PlayerDataList::iterator end = m_computerPlayerList.end(); - - while (i != end) - { - GetLobbyThread().RemoveComputerPlayer(*i); - RemovePlayerData(*i); - ++i; - } - - m_computerPlayerList.clear(); -} - -void -ServerGameThread::GracefulRemoveSession(SessionWrapper session) -{ - assert(session.sessionData.get()); - GetSessionManager().RemoveSession(session.sessionData->GetSocket()); - - boost::shared_ptr tmpPlayerData = session.playerData; - if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty()) - { - RemovePlayerData(tmpPlayerData); - } -} - -void -ServerGameThread::RemovePlayerData(boost::shared_ptr player) -{ - if (player->GetRights() == PLAYER_RIGHTS_ADMIN) - { - // Find new admin for the game - PlayerDataList playerList(GetSessionManager().GetPlayerDataList()); - if (!playerList.empty()) - { - boost::shared_ptr newAdmin = playerList.front(); - SetAdminPlayerId(newAdmin->GetUniqueId()); - newAdmin->SetRights(PLAYER_RIGHTS_ADMIN); - // Send "Game Admin Changed" to clients. - boost::shared_ptr adminChanged(new NetPacketGameAdminChanged); - NetPacketGameAdminChanged::Data adminChangedData; - adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin. - static_cast(adminChanged.get())->SetData(adminChangedData); - GetSessionManager().SendToAllSessions(GetSender(), adminChanged, SessionData::Game); - - GetLobbyThread().NotifyGameAdminChanged(GetId(), newAdmin->GetUniqueId()); - } - } - // Reset player rights. - player->SetRights(PLAYER_RIGHTS_NORMAL); - - // Send "Player Left" to clients. - boost::shared_ptr thisPlayerLeft(new NetPacketPlayerLeft); - NetPacketPlayerLeft::Data thisPlayerLeftData; - thisPlayerLeftData.playerId = player->GetUniqueId(); - static_cast(thisPlayerLeft.get())->SetData(thisPlayerLeftData); - GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game); - - GetLobbyThread().NotifyPlayerLeftGame(GetId(), player->GetUniqueId()); -} - -void -ServerGameThread::ErrorRemoveSession(SessionWrapper session) -{ - GetLobbyThread().RemoveSessionFromGame(session); - GracefulRemoveSession(session); -} - -void -ServerGameThread::SessionError(SessionWrapper session, int errorCode) -{ - assert(session.sessionData.get()); - ErrorRemoveSession(session); - GetLobbyThread().SessionError(session, errorCode); -} - -void -ServerGameThread::MoveSessionToLobby(SessionWrapper session, int reason) -{ - GracefulRemoveSession(session); - GetLobbyThread().ReAddSession(session, reason); -} - -void -ServerGameThread::RemoveDisconnectedPlayers() -{ - // This should only be called between hands. - if (m_game.get()) - { - PlayerListIterator i = m_game->getSeatsList()->begin(); - PlayerListIterator end = m_game->getSeatsList()->end(); - while (i != end) - { - 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->setNetSessionData(boost::shared_ptr()); - } - ++i; - } - } -} - -size_t -ServerGameThread::GetCurNumberOfPlayers() const -{ - return GetFullPlayerDataList().size(); -} - -void -ServerGameThread::AssignPlayerNumbers() -{ - int playerNumber = 0; - - PlayerDataList playerList = GetFullPlayerDataList(); - PlayerDataList::iterator player_i = playerList.begin(); - PlayerDataList::iterator player_end = playerList.end(); - - while (player_i != player_end) - { - (*player_i)->SetNumber(playerNumber); - ++playerNumber; - ++player_i; - } -} - -SessionManager & -ServerGameThread::GetSessionManager() -{ - return m_sessionManager; -} - -const SessionManager & -ServerGameThread::GetSessionManager() const -{ - return m_sessionManager; -} - -ServerLobbyThread & -ServerGameThread::GetLobbyThread() -{ - return m_lobbyThread; -} - -ServerCallback & -ServerGameThread::GetCallback() -{ - return m_gui; -} - -ServerGameState & -ServerGameThread::GetState() -{ - assert(m_curState); - return *m_curState; -} - -void -ServerGameThread::SetState(ServerGameState &newState) -{ - newState.Init(); - m_curState = &newState; -} - -SenderThread & -ServerGameThread::GetSender() -{ - assert(m_sender.get()); - return *m_sender; -} - -ReceiverHelper & -ServerGameThread::GetReceiver() -{ - assert(m_receiver.get()); - return *m_receiver; -} - -Game & -ServerGameThread::GetGame() -{ - assert(m_game.get()); - return *m_game; -} - -const Game & -ServerGameThread::GetGame() const -{ - assert(m_game.get()); - return *m_game; -} - -const GameData & -ServerGameThread::GetGameData() const -{ - return m_gameData; -} - -const StartData & -ServerGameThread::GetStartData() const -{ - return m_startData; -} - -void -ServerGameThread::SetStartData(const StartData &startData) -{ - m_startData = startData; -} - -bool -ServerGameThread::IsPasswordProtected() const -{ - return !m_password.empty(); -} - -bool -ServerGameThread::CheckPassword(const string &password) const -{ - return (password == m_password); -} - -ServerSenderCallback & -ServerGameThread::GetSenderCallback() -{ - assert(m_senderCallback.get()); - return *m_senderCallback; -} - -GuiInterface & -ServerGameThread::GetGui() -{ - return m_gui; -} - -unsigned -ServerGameThread::GetNextGameNum() -{ - return m_gameNum++; -} - +/*************************************************************************** + * Copyright (C) 2007 by Lothar May * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; + + +class ServerSenderCallback : public SenderCallback +{ +public: + ServerSenderCallback(ServerGameThread &server) : m_server(server) {} + virtual ~ServerSenderCallback() {} + + virtual void SignalNetError(SOCKET /*sock*/, int /*errorID*/, int /*osErrorID*/) + { + // We just ignore send errors for now, on server side. + // A serious send error should trigger a read error or a read + // returning 0 afterwards, and we will handle this error. + } + +private: + ServerGameThread &m_server; +}; + + +ServerGameThread::ServerGameThread(ServerLobbyThread &lobbyThread, u_int32_t id, const string &name, const string &pwd, unsigned adminPlayerId, GuiInterface &gui, ConfigFile *playerConfig) +: m_lobbyThread(lobbyThread), m_adminPlayerId(adminPlayerId), m_gui(gui), m_id(id), + m_name(name), m_password(pwd), m_playerConfig(playerConfig), m_curState(NULL), m_gameNum(1) +{ + m_senderCallback.reset(new ServerSenderCallback(*this)); + m_sender.reset(new SenderThread(GetSenderCallback())); + m_receiver.reset(new ReceiverHelper); +} + +ServerGameThread::~ServerGameThread() +{ +} + +void +ServerGameThread::Init(const GameData &gameData) +{ + m_gameData = gameData; +} + +u_int32_t +ServerGameThread::GetId() const +{ + return m_id; +} + +const std::string & +ServerGameThread::GetName() const +{ + return m_name; +} + +void +ServerGameThread::AddSession(SessionWrapper session) +{ + // Must be thread safe. + boost::mutex::scoped_lock lock(m_sessionQueueMutex); + m_sessionQueue.push_back(session); +} + +GameState +ServerGameThread::GetCurRound() const +{ + return static_cast(GetGame().getCurrentHand()->getCurrentRound()); +} + +void +ServerGameThread::SendToAllPlayers(boost::shared_ptr packet, SessionData::State state) +{ + GetSessionManager().SendToAllSessions(GetSender(), packet, state); +} + +void +ServerGameThread::RemoveAllSessions() +{ + // Called from lobby thread. + // Clean up ALL sessions which are left. + ServerLobbyThread &lobbyThread = GetLobbyThread(); + boost::mutex::scoped_lock lock(m_sessionQueueMutex); + while (!m_sessionQueue.empty()) + { + SessionWrapper tmpSession = m_sessionQueue.front(); + m_sessionQueue.pop_front(); + lobbyThread.RemoveSessionFromGame(tmpSession); + } + GetSessionManager().ForEach(boost::bind(&ServerLobbyThread::RemoveSessionFromGame, boost::ref(lobbyThread), _1)); +} + +void +ServerGameThread::Main() +{ + SetState(SERVER_INITIAL_STATE::Instance()); + GetSender().Run(); + + try + { + do + { + { + // Handle one new session at a time. + SessionWrapper tmpSession; + { + boost::mutex::scoped_lock lock(m_sessionQueueMutex); + if (!m_sessionQueue.empty()) + { + tmpSession = m_sessionQueue.front(); + m_sessionQueue.pop_front(); + } + } + if (tmpSession.sessionData.get()) + GetState().HandleNewSession(*this, tmpSession); + } + // Process current state. + GetState().Process(*this); + } while (!ShouldTerminate() && GetSessionManager().HasSessions()); + } catch (const NetException &e) + { + GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); + } + GetSender().SignalTermination(); + GetSender().Join(SENDER_THREAD_TERMINATE_TIMEOUT); + + ResetComputerPlayerList(); + GetLobbyThread().RemoveGame(GetId()); +} + +void +ServerGameThread::InternalStartGame() +{ + // Set order of players. + AssignPlayerNumbers(); + + // Initialize the game. + GuiInterface &gui = GetGui(); + PlayerDataList playerData = GetFullPlayerDataList(); + + // Create EngineFactory + boost::shared_ptr factory(new LocalEngineFactory(m_playerConfig)); // LocalEngine erstellen + + // Set start data. + StartData startData; + startData.numberOfPlayers = playerData.size(); + + int tmpDealerPos = 0; + Tools::getRandNumber(0, startData.numberOfPlayers-1, 1, &tmpDealerPos, 0); + // 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(); + + int tmpPos = 0; + while (player_i != player_end) + { + startData.startDealerPlayerId = static_cast((*player_i)->GetUniqueId()); + if (tmpPos == tmpDealerPos) + break; + ++tmpPos; + ++player_i; + } + assert(player_i != player_end); + + SetStartData(startData); + + m_game.reset(new Game(&gui, factory, playerData, GetGameData(), GetStartData(), GetNextGameNum())); + + GetLobbyThread().NotifyStartingGame(GetId()); +} + +void +ServerGameThread::ResetGame() +{ + m_game.reset(); +} + +void +ServerGameThread::InternalKickPlayer(unsigned playerId) +{ + SessionWrapper tmpSession = GetSessionManager().GetSessionByUniquePlayerId(playerId); + MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_KICKED); +} + +PlayerDataList +ServerGameThread::GetFullPlayerDataList() const +{ + PlayerDataList playerList(GetSessionManager().GetPlayerDataList()); + boost::mutex::scoped_lock lock(m_computerPlayerListMutex); + copy(m_computerPlayerList.begin(), m_computerPlayerList.end(), back_inserter(playerList)); + + return playerList; +} + +boost::shared_ptr +ServerGameThread::GetPlayerDataByUniqueId(unsigned playerId) const +{ + boost::shared_ptr tmpPlayer; + SessionWrapper session = GetSessionManager().GetSessionByUniquePlayerId(playerId); + if (session.playerData.get()) + { + tmpPlayer = session.playerData; + } + else + { + boost::mutex::scoped_lock lock(m_computerPlayerListMutex); + PlayerDataList::const_iterator i = m_computerPlayerList.begin(); + PlayerDataList::const_iterator end = m_computerPlayerList.end(); + while (i != end) + { + if ((*i)->GetUniqueId() == playerId) + { + tmpPlayer = *i; + break; + } + ++i; + } + } + return tmpPlayer; +} + +PlayerIdList +ServerGameThread::GetPlayerIdList() const +{ + PlayerIdList idList(GetSessionManager().GetPlayerIdList()); + boost::mutex::scoped_lock lock(m_computerPlayerListMutex); + PlayerDataList::const_iterator i = m_computerPlayerList.begin(); + PlayerDataList::const_iterator end = m_computerPlayerList.end(); + while (i != end) + { + idList.push_back((*i)->GetUniqueId()); + ++i; + } + + return idList; +} + +bool +ServerGameThread::IsPlayerConnected(const std::string &name) const +{ + return GetSessionManager().IsPlayerConnected(name); +} + +bool +ServerGameThread::IsRunning() const +{ + return m_game.get() != NULL; +} + +unsigned +ServerGameThread::GetAdminPlayerId() const +{ + boost::mutex::scoped_lock lock(m_adminPlayerIdMutex); + return m_adminPlayerId; +} + +void +ServerGameThread::SetAdminPlayerId(unsigned playerId) +{ + boost::mutex::scoped_lock lock(m_adminPlayerIdMutex); + m_adminPlayerId = playerId; +} + +void +ServerGameThread::AddComputerPlayer(boost::shared_ptr player) +{ + { + boost::mutex::scoped_lock lock(m_computerPlayerListMutex); + m_computerPlayerList.push_back(player); + } + GetLobbyThread().AddComputerPlayer(player); +} + +void +ServerGameThread::ResetComputerPlayerList() +{ + boost::mutex::scoped_lock lock(m_computerPlayerListMutex); + + PlayerDataList::iterator i = m_computerPlayerList.begin(); + PlayerDataList::iterator end = m_computerPlayerList.end(); + + while (i != end) + { + GetLobbyThread().RemoveComputerPlayer(*i); + RemovePlayerData(*i); + ++i; + } + + m_computerPlayerList.clear(); +} + +void +ServerGameThread::GracefulRemoveSession(SessionWrapper session) +{ + assert(session.sessionData.get()); + GetSessionManager().RemoveSession(session.sessionData->GetSocket()); + + boost::shared_ptr tmpPlayerData = session.playerData; + if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty()) + { + RemovePlayerData(tmpPlayerData); + } +} + +void +ServerGameThread::RemovePlayerData(boost::shared_ptr player) +{ + if (player->GetRights() == PLAYER_RIGHTS_ADMIN) + { + // Find new admin for the game + PlayerDataList playerList(GetSessionManager().GetPlayerDataList()); + if (!playerList.empty()) + { + boost::shared_ptr newAdmin = playerList.front(); + SetAdminPlayerId(newAdmin->GetUniqueId()); + newAdmin->SetRights(PLAYER_RIGHTS_ADMIN); + // Send "Game Admin Changed" to clients. + boost::shared_ptr adminChanged(new NetPacketGameAdminChanged); + NetPacketGameAdminChanged::Data adminChangedData; + adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin. + static_cast(adminChanged.get())->SetData(adminChangedData); + GetSessionManager().SendToAllSessions(GetSender(), adminChanged, SessionData::Game); + + GetLobbyThread().NotifyGameAdminChanged(GetId(), newAdmin->GetUniqueId()); + } + } + // Reset player rights. + player->SetRights(PLAYER_RIGHTS_NORMAL); + + // Send "Player Left" to clients. + boost::shared_ptr thisPlayerLeft(new NetPacketPlayerLeft); + NetPacketPlayerLeft::Data thisPlayerLeftData; + thisPlayerLeftData.playerId = player->GetUniqueId(); + static_cast(thisPlayerLeft.get())->SetData(thisPlayerLeftData); + GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game); + + GetLobbyThread().NotifyPlayerLeftGame(GetId(), player->GetUniqueId()); +} + +void +ServerGameThread::ErrorRemoveSession(SessionWrapper session) +{ + GetLobbyThread().RemoveSessionFromGame(session); + GracefulRemoveSession(session); +} + +void +ServerGameThread::SessionError(SessionWrapper session, int errorCode) +{ + assert(session.sessionData.get()); + ErrorRemoveSession(session); + GetLobbyThread().SessionError(session, errorCode); +} + +void +ServerGameThread::MoveSessionToLobby(SessionWrapper session, int reason) +{ + GracefulRemoveSession(session); + GetLobbyThread().ReAddSession(session, reason); +} + +void +ServerGameThread::RemoveDisconnectedPlayers() +{ + // This should only be called between hands. + if (m_game.get()) + { + PlayerListIterator i = m_game->getSeatsList()->begin(); + PlayerListIterator end = m_game->getSeatsList()->end(); + while (i != end) + { + 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->setNetSessionData(boost::shared_ptr()); + } + ++i; + } + } +} + +size_t +ServerGameThread::GetCurNumberOfPlayers() const +{ + return GetFullPlayerDataList().size(); +} + +void +ServerGameThread::AssignPlayerNumbers() +{ + int playerNumber = 0; + + PlayerDataList playerList = GetFullPlayerDataList(); + PlayerDataList::iterator player_i = playerList.begin(); + PlayerDataList::iterator player_end = playerList.end(); + + while (player_i != player_end) + { + (*player_i)->SetNumber(playerNumber); + ++playerNumber; + ++player_i; + } +} + +SessionManager & +ServerGameThread::GetSessionManager() +{ + return m_sessionManager; +} + +const SessionManager & +ServerGameThread::GetSessionManager() const +{ + return m_sessionManager; +} + +ServerLobbyThread & +ServerGameThread::GetLobbyThread() +{ + return m_lobbyThread; +} + +ServerCallback & +ServerGameThread::GetCallback() +{ + return m_gui; +} + +ServerGameState & +ServerGameThread::GetState() +{ + assert(m_curState); + return *m_curState; +} + +void +ServerGameThread::SetState(ServerGameState &newState) +{ + newState.Init(); + m_curState = &newState; +} + +SenderThread & +ServerGameThread::GetSender() +{ + assert(m_sender.get()); + return *m_sender; +} + +ReceiverHelper & +ServerGameThread::GetReceiver() +{ + assert(m_receiver.get()); + return *m_receiver; +} + +Game & +ServerGameThread::GetGame() +{ + assert(m_game.get()); + return *m_game; +} + +const Game & +ServerGameThread::GetGame() const +{ + assert(m_game.get()); + return *m_game; +} + +const GameData & +ServerGameThread::GetGameData() const +{ + return m_gameData; +} + +const StartData & +ServerGameThread::GetStartData() const +{ + return m_startData; +} + +void +ServerGameThread::SetStartData(const StartData &startData) +{ + m_startData = startData; +} + +bool +ServerGameThread::IsPasswordProtected() const +{ + return !m_password.empty(); +} + +bool +ServerGameThread::CheckPassword(const string &password) const +{ + return (password == m_password); +} + +ServerSenderCallback & +ServerGameThread::GetSenderCallback() +{ + assert(m_senderCallback.get()); + return *m_senderCallback; +} + +GuiInterface & +ServerGameThread::GetGui() +{ + return m_gui; +} + +unsigned +ServerGameThread::GetNextGameNum() +{ + return m_gameNum++; +} +