From 45d71f08668dd8cfffe4e9df49fdf2085fb2afbe Mon Sep 17 00:00:00 2001 From: doitux Date: Fri, 28 Sep 2007 05:23:13 +0000 Subject: [PATCH] implement new blinds settings (II) --- src/game.cpp | 91 +++++++++++++- src/game.h | 12 +- .../gamelobbydialog/gamelobbydialogimpl.cpp | 39 +++++- .../qt/gamelobbydialog/gamelobbydialogimpl.h | 4 +- src/gui/qt/mainwindow/mainwindowimpl.cpp | 116 +++++++++++++++--- 5 files changed, 237 insertions(+), 25 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index ec9cf254..bd70e2ec 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -18,7 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "game.h" -#include "gamedata.h" #include #include @@ -29,13 +28,13 @@ using namespace std; Game::Game(GuiInterface* gui, boost::shared_ptr factory, - const PlayerDataList &playerDataList, const GameData &gameData, + const PlayerDataList &playerDataList, const GameData gameData, const StartData &startData, int gameId) : myFactory(factory), myGui(gui), actualHand(0), actualBoard(0), startQuantityPlayers(startData.numberOfPlayers), startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), - myGameID(gameId), actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) + myGameID(gameId), actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0), lastHandBlindsRaised(1), lastTimeBlindsRaised(0), myGameData(gameData) { // cout << "Create Game Object" << "\n"; int i; @@ -107,6 +106,10 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, } actualBoard->setPlayerLists(playerArray, seatsList, activePlayerList, runningPlayerList); // delete playerArray + + //start timer + blindsTimer.reset(); + blindsTimer.start(); } Game::~Game() @@ -144,8 +147,8 @@ void Game::initHand() actualHandID++; - // smallBlind alle x Runden erhöhen - if((actualHandID-1)%startHandsBeforeRaiseSmallBlind == 0 && actualHandID > 1) { actualSmallBlind *= 2; } + // calculate smallBlind + raiseBlinds(); //Spieler Action auf 0 setzen // for(i=0; i Game::getCurrentPlayer() return tmpPlayer; } +void Game::raiseBlinds() { + +// cout << "timer minutes " << blindsTimer.elapsed().total_seconds()/60 << "\n"; +// cout << "gameData.raiseIntervallMode " << myGameData.raiseIntervallMode << "\n"; +// cout << "gameData.raiseMode " << myGameData.raiseMode << "\n"; +// cout << "gameData.afterManualBlindsMode " << myGameData.afterManualBlindsMode << "\n"; + + bool raiseBlinds = false; + + if (myGameData.raiseIntervallMode == RAISE_ON_HANDNUMBER) { + + if (lastHandBlindsRaised + myGameData.raiseSmallBlindEveryHandsValue <= actualHandID) { + raiseBlinds = true; + lastHandBlindsRaised = actualHandID; + + cout << "raise now on hands \n"; + } + } + else { + if (lastTimeBlindsRaised + myGameData.raiseSmallBlindEveryMinutesValue <= blindsTimer.elapsed().total_seconds()/60) { + raiseBlinds = true; + lastTimeBlindsRaised = blindsTimer.elapsed().total_seconds()/60; + + cout << "raise now on minutes \n"; + } + } + + if (raiseBlinds) { + + // At this point, the blinds must be raised + // Now we check how the blinds should be raised + + if (myGameData.raiseMode == DOUBLE_BLINDS) { + actualSmallBlind *= 2; + cout << "double small blind \n"; + } + else { + // Increase the position of the list + list blindsList = myGameData.manualBlindsList; + list::iterator it; + + if(!blindsList.empty()) { + it = find(blindsList.begin(), blindsList.end(), actualSmallBlind); + if(it != blindsList.end()) { + it++; + cout << "increase position in blindslist \n"; + } + else { + cout << "blindslist exceeds\n"; + if(actualSmallBlind == myGameData.firstSmallBlind) { + it = blindsList.begin(); + } + } + } + else { cout << "blindslist is empty \n"; } + // Check if we can get an element of the list or the position exceeds the lis + if (blindsList.empty() || it == blindsList.end()) { + + // The position exceeds the list + if (myGameData.afterManualBlindsMode == AFTERMB_DOUBLE_BLINDS) { + actualSmallBlind *= 2; + cout << "after blindslist double blind\n"; + } + else { + if(myGameData.afterManualBlindsMode == AFTERMB_RAISE_ABOUT) { + actualSmallBlind += 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; + cout << "set new small blind from blindslist \n"; + } + } + } +} diff --git a/src/game.h b/src/game.h index 4134829c..ea6646d8 100755 --- a/src/game.h +++ b/src/game.h @@ -21,11 +21,13 @@ #define GAME_H #include "game_defs.h" +#include "gamedata.h" #include "playerdata.h" #include "configfile.h" #include #include +#include class GuiInterface; class HandInterface; @@ -43,7 +45,7 @@ class Game { public: Game(GuiInterface *gui, boost::shared_ptr factory, - const PlayerDataList &playerDataList, const GameData &gameData, + const PlayerDataList &playerDataList, const GameData gameData, const StartData &startData, int gameId); ~Game(); @@ -80,6 +82,8 @@ public: boost::shared_ptr getPlayerByUniqueId(unsigned id); boost::shared_ptr getCurrentPlayer(); + void raiseBlinds(); + private: boost::shared_ptr myFactory; @@ -106,6 +110,12 @@ private: int actualSmallBlind; int actualHandID; unsigned dealerPosition; + int lastHandBlindsRaised; + int lastTimeBlindsRaised; + const GameData myGameData; + + //timer + boost::timers::portable::second_timer blindsTimer; }; #endif diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp index e2a1d547..2428c04e 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp @@ -79,9 +79,42 @@ void gameLobbyDialogImpl::createGame() // Set Game Data gameData.maxNumberOfPlayers = myCreateInternetGameDialog->spinBox_quantityPlayers->value(); gameData.startMoney = myCreateInternetGameDialog->spinBox_startCash->value(); - gameData.smallBlind = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value(); - gameData.handsBeforeRaise = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); - gameData.guiSpeed = myCreateInternetGameDialog->spinBox_gameSpeed->value(); + gameData.smallBlind = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value();//TODO remove + gameData.firstSmallBlind = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value(); + + if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_raiseBlindsAtHands->isChecked()) { + gameData.raiseIntervallMode = RAISE_ON_HANDNUMBER; + gameData.raiseSmallBlindEveryHandsValue = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); + gameData.handsBeforeRaise = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); //TODO remove + } + else { + gameData.raiseIntervallMode = RAISE_ON_MINUTES; + gameData.raiseSmallBlindEveryMinutesValue = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryMinutes->value(); + } + + if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_alwaysDoubleBlinds->isChecked()) { + gameData.raiseMode = DOUBLE_BLINDS; + } + else { + gameData.raiseMode = MANUAL_BLINDS_ORDER; + std::list tempBlindList; + int i; + bool ok = TRUE; + for(i=0; igetChangeCompleteBlindsDialog()->listWidget_blinds->count(); i++) { + tempBlindList.push_back(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->listWidget_blinds->item(i)->text().toInt(&ok,10)); + } + gameData.manualBlindsList = tempBlindList; + + if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysDoubleBlinds->isChecked()) { gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS; } + else { + if(myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysRaiseAbout->isChecked()) { + gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT; + gameData.afterMBAlwaysRaiseValue = myCreateInternetGameDialog->getChangeCompleteBlindsDialog()->spinBox_afterThisAlwaysRaiseValue->value(); + } + else { gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND; } + } + } + gameData.guiSpeed = myCreateInternetGameDialog->spinBox_gameSpeed->value(); gameData.playerActionTimeoutSec = myCreateInternetGameDialog->spinBox_netTimeOutPlayerAction->value(); diff --git a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h index 6f0619f9..dd718bc9 100644 --- a/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h +++ b/src/gui/qt/gamelobbydialog/gamelobbydialogimpl.h @@ -96,10 +96,10 @@ private: ConfigFile *myConfig; Session *mySession; createInternetGameDialogImpl *myCreateInternetGameDialog; - LobbyChat *myChat; - QString currentGameName; bool isAdmin; + LobbyChat *myChat; + }; #endif diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 597a4e9e..f1dcb6e6 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -723,14 +723,39 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { gameData.startMoney = v->spinBox_startCash->value(); gameData.smallBlind = v->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value(); //TODO remove gameData.firstSmallBlind = v->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value(); - if(v->getChangeCompleteBlindsDialog()->radioButton_raiseBlindsAtHands->isChecked()) gameData.raiseIntervallMode = RAISE_ON_HANDNUMBER; - else gameData.raiseIntervallMode = RAISE_ON_MINUTES; - gameData.raiseSmallBlindEveryHandsValue = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); - gameData.handsBeforeRaise = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); //TODO remove - gameData.raiseSmallBlindEveryMinutesValue = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryMinutes->value(); - if(v->getChangeCompleteBlindsDialog()->radioButton_alwaysDoubleBlinds->isChecked()) gameData.raiseMode = DOUBLE_BLINDS; - else gameData.raiseMode = MANUAL_BLINDS_ORDER; - + + if(v->getChangeCompleteBlindsDialog()->radioButton_raiseBlindsAtHands->isChecked()) { + gameData.raiseIntervallMode = RAISE_ON_HANDNUMBER; + gameData.raiseSmallBlindEveryHandsValue = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); + gameData.handsBeforeRaise = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); //TODO remove + } + else { + gameData.raiseIntervallMode = RAISE_ON_MINUTES; + gameData.raiseSmallBlindEveryMinutesValue = v->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryMinutes->value(); + } + + if(v->getChangeCompleteBlindsDialog()->radioButton_alwaysDoubleBlinds->isChecked()) { + gameData.raiseMode = DOUBLE_BLINDS; + } + else { + gameData.raiseMode = MANUAL_BLINDS_ORDER; + list tempBlindList; + int i; + bool ok = TRUE; + for(i=0; igetChangeCompleteBlindsDialog()->listWidget_blinds->count(); i++) { + tempBlindList.push_back(v->getChangeCompleteBlindsDialog()->listWidget_blinds->item(i)->text().toInt(&ok,10)); + } + gameData.manualBlindsList = tempBlindList; + + if(v->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysDoubleBlinds->isChecked()) { gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS; } + else { + if(v->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysRaiseAbout->isChecked()) { + gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT; + gameData.afterMBAlwaysRaiseValue = v->getChangeCompleteBlindsDialog()->spinBox_afterThisAlwaysRaiseValue->value(); + } + else { gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND; } + } + } //Speeds gameData.guiSpeed = v->spinBox_gameSpeed->value(); @@ -740,8 +765,37 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { // Set Game Data gameData.maxNumberOfPlayers = myConfig->readConfigInt("NumberOfPlayers"); gameData.startMoney = myConfig->readConfigInt("StartCash"); - gameData.smallBlind = myConfig->readConfigInt("FirstSmallBlind"); - gameData.handsBeforeRaise = myConfig->readConfigInt("RaiseSmallBlindEveryHands"); + gameData.smallBlind = myConfig->readConfigInt("FirstSmallBlind"); //TODO remove + gameData.handsBeforeRaise = myConfig->readConfigInt("RaiseSmallBlindEveryHands"); //TODO remove + + gameData.firstSmallBlind = myConfig->readConfigInt("FirstSmallBlind"); + + if(myConfig->readConfigInt("RaiseBlindsAtHands")) { + gameData.raiseIntervallMode = RAISE_ON_HANDNUMBER; + gameData.raiseSmallBlindEveryHandsValue = myConfig->readConfigInt("RaiseSmallBlindEveryHands"); + gameData.handsBeforeRaise = myConfig->readConfigInt("RaiseSmallBlindEveryHands"); //TODO remove + } + else { + gameData.raiseIntervallMode = RAISE_ON_MINUTES; + gameData.raiseSmallBlindEveryMinutesValue = myConfig->readConfigInt("RaiseSmallBlindEveryMinutes"); + } + + if(myConfig->readConfigInt("AlwaysDoubleBlinds")) { + gameData.raiseMode = DOUBLE_BLINDS; + } + else { + gameData.raiseMode = MANUAL_BLINDS_ORDER; + gameData.manualBlindsList = myConfig->readConfigIntList("ManualBlindsList"); + + if(myConfig->readConfigInt("AfterMBAlwaysDoubleBlinds")) { gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS; } + else { + if(myConfig->readConfigInt("AfterMBAlwaysRaiseAbout")) { + gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT; + gameData.afterMBAlwaysRaiseValue = myConfig->readConfigInt("AfterMBAlwaysRaiseValue"); + } + else { gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND; } + } + } //Speeds gameData.guiSpeed = myConfig->readConfigInt("GameSpeed"); } @@ -788,9 +842,43 @@ void mainWindowImpl::callCreateNetworkGameDialog() { GameData gameData; gameData.maxNumberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); gameData.startMoney = myCreateNetworkGameDialog->spinBox_startCash->value(); - gameData.smallBlind = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value(); - gameData.handsBeforeRaise = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); - gameData.guiSpeed = myCreateNetworkGameDialog->spinBox_gameSpeed->value(); + gameData.smallBlind = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value();//TODO remove + gameData.firstSmallBlind = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_firstSmallBlind->value(); + + if(myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->radioButton_raiseBlindsAtHands->isChecked()) { + gameData.raiseIntervallMode = RAISE_ON_HANDNUMBER; + gameData.raiseSmallBlindEveryHandsValue = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); + gameData.handsBeforeRaise = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryHands->value(); //TODO remove + } + else { + gameData.raiseIntervallMode = RAISE_ON_MINUTES; + gameData.raiseSmallBlindEveryMinutesValue = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_raiseSmallBlindEveryMinutes->value(); + } + + if(myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->radioButton_alwaysDoubleBlinds->isChecked()) { + gameData.raiseMode = DOUBLE_BLINDS; + } + else { + gameData.raiseMode = MANUAL_BLINDS_ORDER; + list tempBlindList; + int i; + bool ok = TRUE; + for(i=0; igetChangeCompleteBlindsDialog()->listWidget_blinds->count(); i++) { + tempBlindList.push_back(myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->listWidget_blinds->item(i)->text().toInt(&ok,10)); + } + gameData.manualBlindsList = tempBlindList; + + if(myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysDoubleBlinds->isChecked()) { gameData.afterManualBlindsMode = AFTERMB_DOUBLE_BLINDS; } + else { + if(myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->radioButton_afterThisAlwaysRaiseAbout->isChecked()) { + gameData.afterManualBlindsMode = AFTERMB_RAISE_ABOUT; + gameData.afterMBAlwaysRaiseValue = myCreateNetworkGameDialog->getChangeCompleteBlindsDialog()->spinBox_afterThisAlwaysRaiseValue->value(); + } + else { gameData.afterManualBlindsMode = AFTERMB_STAY_AT_LAST_BLIND; } + } + } + + gameData.guiSpeed = myCreateNetworkGameDialog->spinBox_gameSpeed->value(); gameData.playerActionTimeoutSec = myCreateNetworkGameDialog->spinBox_netTimeOutPlayerAction->value(); myGameLobbyDialog->setSession(&getSession()); @@ -2856,7 +2944,7 @@ void mainWindowImpl::localGameModification() { } //Set the playing mode to "manual" - playingMode = 0; + playingMode = 1; }