From 6c19233c18b53e37c24f1c5fb9877cd4a28a3039 Mon Sep 17 00:00:00 2001 From: doitux Date: Wed, 26 Sep 2007 10:13:10 +0000 Subject: [PATCH] adds activePlayerList and runningPlayerList (XIII) - BUGGY!!! - last sable rev866 --- src/engine/boardinterface.h | 1 + src/engine/local_engine/localbero.cpp | 4 +- src/engine/local_engine/localbero.h | 9 ++ src/engine/local_engine/localberopreflop.cpp | 13 ++- src/engine/local_engine/localberopreflop.h | 1 + src/engine/local_engine/localhand.cpp | 107 +++++++++---------- src/engine/local_engine/localplayer.cpp | 2 +- src/game.cpp | 29 ++--- src/game.h | 1 + src/gui/qt/mainwindow/mainwindowimpl.cpp | 4 +- 10 files changed, 96 insertions(+), 75 deletions(-) diff --git a/src/engine/boardinterface.h b/src/engine/boardinterface.h index 28adc9b8..bd6e1b39 100644 --- a/src/engine/boardinterface.h +++ b/src/engine/boardinterface.h @@ -29,6 +29,7 @@ class HandInterface; typedef boost::shared_ptr > > PlayerList; typedef std::list >::iterator PlayerListIterator; +typedef std::list >::const_iterator PlayerListConstIterator; class BoardInterface { diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index 6d68b510..4a206c68 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -14,7 +14,7 @@ using namespace std; LocalBeRo::LocalBeRo(HandInterface* hi, int id, int dP, int sB, GameState gS) -: BeRoInterface(), myHand(hi), myBeRoID(gS), myID(id), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(false), minimumRaise(2*sB), firstRun(true), firstRound(true), firstHeadsUpRound(true), logBoardCardsDone(false) +: BeRoInterface(), myHand(hi), myBeRoID(gS), myID(id), dealerPosition(dP), smallBlindPosition(0), smallBlind(sB), highestSet(false), minimumRaise(2*sB), firstRun(true), firstRound(true), firstHeadsUpRound(true), currentPlayersTurn(0), firstRoundLastPlayersTurn(0), logBoardCardsDone(false) { currentPlayersTurnIt = myHand->getRunningPlayerList()->begin(); lastPlayersTurnIt = myHand->getRunningPlayerList()->begin(); @@ -38,7 +38,7 @@ void LocalBeRo::nextPlayer() { // myHand->getPlayerArray()[playersTurn]->action(); - cout << "playerID in nextPlayer(): " << (*currentPlayersTurnIt)->getMyID() << endl; +// cout << "playerID in nextPlayer(): " << (*currentPlayersTurnIt)->getMyID() << endl; (*currentPlayersTurnIt)->action(); diff --git a/src/engine/local_engine/localbero.h b/src/engine/local_engine/localbero.h index 2b865b19..e268507b 100644 --- a/src/engine/local_engine/localbero.h +++ b/src/engine/local_engine/localbero.h @@ -53,6 +53,12 @@ protected: void setPlayersTurn(int theValue) { playersTurn = theValue; } int getPlayersTurn() const { return playersTurn;} + void setCurrentPlayersTurn(unsigned theValue) { currentPlayersTurn = theValue; } + unsigned getCurrentPlayersTurn() const { return currentPlayersTurn;} + + void setFirstRoundLastPlayersTurn(unsigned theValue) { firstRoundLastPlayersTurn = theValue; } + unsigned getFirstRoundLastPlayersTurn() const { return firstRoundLastPlayersTurn;} + void setCurrentPlayersTurnIt(PlayerListIterator theValue) { currentPlayersTurnIt = theValue; } PlayerListIterator getCurrentPlayersTurnIt() const { return currentPlayersTurnIt; } @@ -98,6 +104,9 @@ private: PlayerListIterator currentPlayersTurnIt; // iterator for runningPlayerList PlayerListIterator lastPlayersTurnIt; // iterator for runningPlayerList + unsigned currentPlayersTurn; + unsigned firstRoundLastPlayersTurn; + bool logBoardCardsDone; int lastActionPlayer; diff --git a/src/engine/local_engine/localberopreflop.cpp b/src/engine/local_engine/localberopreflop.cpp index ef754e0b..522a241e 100644 --- a/src/engine/local_engine/localberopreflop.cpp +++ b/src/engine/local_engine/localberopreflop.cpp @@ -24,8 +24,10 @@ using namespace std; -LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* hi, int id, int dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_PREFLOP) +LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* hi, int id, int dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_PREFLOP), bigBlindPosition(0) { + PlayerListConstIterator it_c; + setHighestSet(2*getSmallBlind()); // determine bigBlindPosition @@ -33,6 +35,13 @@ LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* hi, int id, int dP, int sB) : if((*bigBlindPositionIt)->getMyButton() == BUTTON_BIG_BLIND) break; } + for(it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); it_c++) { + if((*it_c)->getMyButton() == BUTTON_BIG_BLIND) { + bigBlindPosition = (*it_c)->getMyUniqueID(); + break; + }; + } + // search player in runningPlayerList before first action player -> run() determine next player who will do first action PlayerListIterator it_1, it_2, it_3; @@ -80,7 +89,7 @@ LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* hi, int id, int dP, int sB) : setCurrentPlayersTurnIt(getLastPlayersTurnIt()); - cout << "playerID constructor preflopRun(): " << (*(getCurrentPlayersTurnIt()))->getMyID() << endl; +// cout << "playerID constructor beropreflop: " << (*(getCurrentPlayersTurnIt()))->getMyID() << endl; /////////////// testing diff --git a/src/engine/local_engine/localberopreflop.h b/src/engine/local_engine/localberopreflop.h index fdc3816d..bf4c1a82 100644 --- a/src/engine/local_engine/localberopreflop.h +++ b/src/engine/local_engine/localberopreflop.h @@ -35,6 +35,7 @@ public: private: PlayerListIterator bigBlindPositionIt; // iterator for activePlayerList + unsigned bigBlindPosition; }; #endif diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 0b33dfce..ef487fd8 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -27,12 +27,12 @@ using namespace std; LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardInterface *b, std::vector > sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) -: myFactory(f), myGui(g), myBoard(b), playerArray(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(0), +: myFactory(f), myGui(g), myBoard(b), playerArray(sl), activePlayerList(apl), runningPlayerList(rpl), myBeRo(0), myID(id), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), lastPlayersTurn(0), allInCondition(false), cardsShown(false), bettingRoundsPlayed(0) { int i, j, k; - PlayerListIterator it; + PlayerListConstIterator it_c; CardsValue myCardsValue; @@ -46,10 +46,10 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI // roundStartCashArray fllen - for(i=0; isetMyRoundStartCash(playerArray[i]->getMyCash()); - } - +// for(i=0; isetMyRoundStartCash(playerArray[i]->getMyCash()); +// } + // Karten generieren und Board sowie Player zuweisen int *cardsArray = new int[2*activePlayerList->size()+5]; Tools::getRandNumber(0, 51, 2*activePlayerList->size()+5, cardsArray, 1); @@ -65,18 +65,19 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI k = 0; myBoard->setMyCards(tempBoardArray); - for(it=activePlayerList->begin(); it!=activePlayerList->end(); it++, k++) { + for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++, k++) { - (*it)->getMyBestHandPosition(bestHandPos); + (*it_c)->getMyBestHandPosition(bestHandPos); for(j=0; j<2; j++) { tempPlayerArray[j] = cardsArray[2*k+j+5]; tempPlayerAndBoardArray[j] = cardsArray[2*k+j+5]; } - (*it)->setMyCards(tempPlayerArray); - (*it)->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray, bestHandPos)); - (*it)->setMyBestHandPosition(bestHandPos); + (*it_c)->setMyCards(tempPlayerArray); + (*it_c)->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray, bestHandPos)); + (*it_c)->setMyBestHandPosition(bestHandPos); + (*it_c)->setMyRoundStartCash((*it_c)->getMyCash()); // myBestHandPosition auf Fehler ueberpruefen for(j=0; j<5; j++) { @@ -86,10 +87,10 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI } // sBluff für alle aktiver Spieler außer human player setzen --> TODO for ai-player in internet - if((*it)->getMyID() != 0) { + if((*it_c)->getMyID() != 0) { Tools::getRandNumber(1,100,1,&sBluff,0); - (*it)->setSBluff(sBluff); - (*it)->setSBluffStatus(0); + (*it_c)->setSBluff(sBluff); + (*it_c)->setSBluffStatus(0); } } @@ -99,7 +100,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI if(DEBUG_MODE) { - int temp5Array[5]; +// int temp5Array[5]; switch(myID) { @@ -285,7 +286,7 @@ void LocalHand::start() { void LocalHand::assignButtons() { int i,j; - PlayerListIterator it; + PlayerListConstIterator it_c; // alle Buttons loeschen for (i=0; isetMyButton(0); } @@ -317,50 +318,43 @@ void LocalHand::assignButtons() { } //do sets --> TODO switch? - for (it=runningPlayerList->begin(); it!=runningPlayerList->end(); ) { + for (it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); it_c++) { //small blind - if((*it)->getMyButton() == 2) { + if((*it_c)->getMyButton() == 2) { // All in ? - if((*it)->getMyCash() <= smallBlind) { + if((*it_c)->getMyCash() <= smallBlind) { - (*it)->setMySet((*it)->getMyCash()); + (*it_c)->setMySet((*it_c)->getMyCash()); // 1 to do not log this - (*it)->setMyAction(6,1); + (*it_c)->setMyAction(6,1); // delete this player from runningPlayerList - it = runningPlayerList->erase(it); +// it_c = runningPlayerList->erase(it_c); } else { - (*it)->setMySet(smallBlind); - it++; + (*it_c)->setMySet(smallBlind); } - } else { - - //big blind - if((*it)->getMyButton() == 3) { - - // all in ? - if((*it)->getMyCash() <= 2*smallBlind) { - - (*it)->setMySet((*it)->getMyCash()); - // 1 to do not log this - (*it)->setMyAction(6,1); - // delete this player from runningPlayerList - it = runningPlayerList->erase(it); - - } - else { - (*it)->setMySet(2*smallBlind); - it++; - } - } else { - it++; - } - } + //big blind + if((*it_c)->getMyButton() == 3) { + + // all in ? + if((*it_c)->getMyCash() <= 2*smallBlind) { + + (*it_c)->setMySet((*it_c)->getMyCash()); + // 1 to do not log this + (*it_c)->setMyAction(6,1); + // delete this player from runningPlayerList +// it_c = runningPlayerList->erase(it_c); + + } + else { + (*it_c)->setMySet(2*smallBlind); + } + } } } @@ -370,16 +364,17 @@ void LocalHand::switchRounds() { // cout << "playerID begin switchRounds(): " << getCurrentBeRo()->get int i; - PlayerListIterator it, it_1; + PlayerListIterator it; + PlayerListConstIterator it_c; // refresh runningPlayerList for(it=runningPlayerList->begin(); it!=runningPlayerList->end(); ) { if((*it)->getMyAction() == 1 || (*it)->getMyAction() == 6) { it = runningPlayerList->erase(it); - it_1 = it; - if(it_1 == runningPlayerList->begin()) it_1 = runningPlayerList->end(); - it_1--; - getCurrentBeRo()->setCurrentPlayersTurnIt(it_1); +// it_1 = it; +// if(it_1 == runningPlayerList->begin()) it_1 = runningPlayerList->end(); +// it_1--; +// getCurrentBeRo()->setCurrentPlayersTurnIt(it_1); } else { it++; } @@ -387,14 +382,14 @@ void LocalHand::switchRounds() { // Anzahl der Spieler ermitteln, welche All In sind int allInPlayersCounter = 0; - for (it=activePlayerList->begin(); it!=activePlayerList->end(); it++) { - if ((*it)->getMyAction() == 6) allInPlayersCounter++; + for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) { + if ((*it_c)->getMyAction() == 6) allInPlayersCounter++; } // TODO -> runningPlayerList.size() int nonFoldPlayerCounter = 0; - for (it=activePlayerList->begin(); it!=activePlayerList->end(); it++) { - if ((*it)->getMyAction() != 1) nonFoldPlayerCounter++; + for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) { + if ((*it_c)->getMyAction() != 1) nonFoldPlayerCounter++; } //wenn nur noch einer nicht-folded dann gleich den Pot verteilen diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 987ec573..26f81398 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -976,7 +976,7 @@ void LocalPlayer::action() { actualHand->getGuiInterface()->logPlayerActionMsg(myName, myAction, mySet); actualHand->getGuiInterface()->nextPlayerAnimation(); - cout << "playerID in action(): " << (*(actualHand->getCurrentBeRo()->getCurrentPlayersTurnIt()))->getMyID() << endl; +// cout << "playerID in action(): " << (*(actualHand->getCurrentBeRo()->getCurrentPlayersTurnIt()))->getMyID() << endl; } diff --git a/src/game.cpp b/src/game.cpp index 93ea9049..c45d8ee1 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -69,10 +69,11 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, actualBoard = myFactory->createBoard(); - // Player erstellen activePlayerList = PlayerList(new std::list >); runningPlayerList = PlayerList(new std::list >); + // Player erstellen + player_i = playerDataList.begin(); player_end = playerDataList.end(); for(i=0; i 1) { actualSmallBlind *= 2; } - // Spieler mit leerem Cash auf inactive setzen - PlayerListIterator it; + //Spieler Action auf 0 setzen +// for(i=0; isetMyAction(0); +// } - for(it=activePlayerList->begin(); it!=activePlayerList->end(); ) { + //Spieler Action auf 0 setzen + for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); it_c++) { + (*it_c)->setMyAction(PLAYER_ACTION_NONE); + } + + // Spieler mit leerem Cash auf inactive setzen + PlayerListIterator it = activePlayerList->begin(); + + while( it!=activePlayerList->end() ) { if((*it)->getMyCash() == 0) { // cout << "playerID: " << (*it)->getMyID() << endl; @@ -161,11 +173,6 @@ void Game::initHand() } } - //Spieler Action auf 0 setzen - for(i=0; isetMyAction(0); - } - runningPlayerList->clear(); (*runningPlayerList) = (*activePlayerList); @@ -173,13 +180,11 @@ void Game::initHand() actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, activePlayerList, runningPlayerList, actualHandID, startQuantityPlayers, dealerPosition, actualSmallBlind, startCash); - // Dealer-Button weiterschieben --> Achtung inactive + // Dealer-Button weiterschieben --> Achtung inactive -> TODO exception-rule !!! for(i=0; (igetMyActiveStatus())) || i==0; i++) { dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS); } - - // Abfrage Cash==0 -> player inactive -> actualQuantityPlayer-- } void Game::startHand() diff --git a/src/game.h b/src/game.h index e0b7a50d..408780f0 100755 --- a/src/game.h +++ b/src/game.h @@ -37,6 +37,7 @@ struct StartData; typedef boost::shared_ptr > > PlayerList; typedef std::list >::iterator PlayerListIterator; +typedef std::list >::const_iterator PlayerListConstIterator; class Game { diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 34657e19..1c09ab1e 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -2082,8 +2082,8 @@ void mainWindowImpl::postRiverRunAnimation3() { // groupBoxArray[i]->setPalette(tempPalette); actionLabelArray[i]->setPixmap(QPixmap(myAppDataPath +"gfx/gui/table/default/action_winner.png")); - //show winnercards if more than one player is active - if ( currentHand->getRunningPlayerList()->size() != 1 && myConfig->readConfigInt("ShowFadeOutCardsAnimation")) { + //show winnercards if more than one player is active TODO + if ( currentHand->getActivePlayerList()->size() != 1 && myConfig->readConfigInt("ShowFadeOutCardsAnimation")) { int j; int bestHandPos[5];