From 3352a199fcc2213e17e38e976b5251af2a5f1afd Mon Sep 17 00:00:00 2001 From: floty Date: Tue, 1 Nov 2011 18:03:48 +0000 Subject: [PATCH] sqlite-logging at the end of hand/game possible; moving winner/sitOut-logging from gui to engine --- .../local_engine/localberopostriver.cpp | 36 ++++++++++++- src/engine/log.cpp | 50 +++++++++++++------ src/engine/log.h | 4 +- src/gui/qt/gametable/gametableimpl.cpp | 3 -- 4 files changed, 73 insertions(+), 20 deletions(-) diff --git a/src/engine/local_engine/localberopostriver.cpp b/src/engine/local_engine/localberopostriver.cpp index 8eda25c4..c2304029 100644 --- a/src/engine/local_engine/localberopostriver.cpp +++ b/src/engine/local_engine/localberopostriver.cpp @@ -92,8 +92,38 @@ void LocalBeRoPostRiver::postRiverRun() getMyHand()->getLog()->logHoleCardsHandName(5,getMyHand()->getActivePlayerList()); } - // logging winner if game is over - // wenn nur noch ein Spieler aktive "neues Spiel"-Dialog anzeigen + // logging winner of the hand + for(it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) { + if((*it_c)->getMyAction() != PLAYER_ACTION_FOLD && (*it_c)->getMyCardsValueInt() == highestCardsValue) { + getMyHand()->getLog()->logPlayerAction(5,(*it_c)->getMyID()+1,LOG_ACTION_WIN,(*it_c)->getLastMoneyWon()); + } + } + + // log side pot winners + list winners = getMyHand()->getBoard()->getWinners(); + list::iterator it_int; + for(it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) { + if((*it_c)->getMyAction() != PLAYER_ACTION_FOLD && (*it_c)->getMyCardsValueInt() != highestCardsValue ) { + + for(it_int = winners.begin(); it_int != winners.end(); ++it_int) { + if((*it_int) == (*it_c)->getMyUniqueID()) { + getMyHand()->getLog()->logPlayerAction(5,(*it_c)->getMyID()+1,LOG_ACTION_WIN_SIDE_POT,(*it_c)->getLastMoneyWon()); + } + } + } + } + + // log player sits out + for(it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) { + if((*it_c)->getMyCash() == 0) { + getMyHand()->getLog()->logPlayerAction(5, (*it_c)->getMyID()+1, LOG_ACTION_SIT_OUT); + } + } + + // for log after every hand + getMyHand()->getLog()->logAfterHand(); + + // log winner of the game if only one player is left int playersPositiveCashCounter = 0; for (it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) { if ((*it_c)->getMyCash() > 0) playersPositiveCashCounter++; @@ -104,6 +134,8 @@ void LocalBeRoPostRiver::postRiverRun() getMyHand()->getLog()->logPlayerAction(5,(*it_c)->getMyID()+1,LOG_ACTION_WIN_GAME); } } + // for log after every game + getMyHand()->getLog()->logAfterGame(); } //starte die Animaionsreihe diff --git a/src/engine/log.cpp b/src/engine/log.cpp index fe8da41f..72bf4378 100644 --- a/src/engine/log.cpp +++ b/src/engine/log.cpp @@ -122,7 +122,7 @@ Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID sql += ",Amount INTEGER"; sql += ");"; - exec_transaction(&sql); + exec_transaction(); } } } @@ -136,7 +136,8 @@ Log::~Log() } } -void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) +void +Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) { curGameID = gameID; @@ -173,13 +174,16 @@ void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned } } sql += ");"; - exec_transaction(&sql); + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(); + } } } } } -void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList) +void +Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList) { curHandID = handID; @@ -224,7 +228,7 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns } sql += ");"; if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(&sql); + exec_transaction(); } // !! TODO !! Hack, weil Button-Regel noch falsch und dealerPosition noch teilweise falsche ID enthält (HeadsUp: dealerPosition=bigBlindPosition <-- falsch) @@ -251,7 +255,8 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns } } -void Log::logPlayerAction(int bero, int seat, PlayerActionLog action, int amount) +void +Log::logPlayerAction(int bero, int seat, PlayerActionLog action, int amount) { if(SQLITE_LOG) { @@ -327,14 +332,15 @@ void Log::logPlayerAction(int bero, int seat, PlayerActionLog action, int amount } sql += ");"; if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(&sql); + exec_transaction(); } } } } } -void Log::logBoardCards(int bero, int boardCards[5]) +void +Log::logBoardCards(int bero, int boardCards[5]) { if(SQLITE_LOG) { @@ -370,14 +376,15 @@ void Log::logBoardCards(int bero, int boardCards[5]) sql += "HandID=" + boost::lexical_cast(curHandID); sql += ";"; if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(&sql); + exec_transaction(); } } } } } -void Log::logHoleCardsHandName(int bero, PlayerList activePlayerList) +void +Log::logHoleCardsHandName(int bero, PlayerList activePlayerList) { if(SQLITE_LOG) { @@ -410,7 +417,7 @@ void Log::logHoleCardsHandName(int bero, PlayerList activePlayerList) sql += "HandID=" + boost::lexical_cast(curHandID); sql += ";"; if(myConfig->readConfigInt("LogInterval") == 0) { - exec_transaction(&sql); + exec_transaction(); } if(!logHoleCardsDone) { @@ -427,12 +434,27 @@ void Log::logHoleCardsHandName(int bero, PlayerList activePlayerList) } } -void Log::exec_transaction(string *sql) +void +Log::logAfterHand() { + if(myConfig->readConfigInt("LogInterval") == 1) { + exec_transaction(); + } +} + +void +Log::logAfterGame() { + if(myConfig->readConfigInt("LogInterval") == 2) { + exec_transaction(); + } +} + +void +Log::exec_transaction() { char *errmsg = NULL; - string sql_transaction = "BEGIN;" + *sql + "COMMIT;"; - *sql = ""; + string sql_transaction = "BEGIN;" + sql + "COMMIT;"; + sql = ""; if(sqlite3_exec(mySqliteLogDb, sql_transaction.data(), 0, 0, &errmsg) != SQLITE_OK) { cout << "Error in statement: " << sql_transaction.data() << "[" << errmsg << "]." << endl; diff --git a/src/engine/log.h b/src/engine/log.h index a1e01a6f..7c983ff1 100644 --- a/src/engine/log.h +++ b/src/engine/log.h @@ -39,7 +39,9 @@ public: void logPlayerAction(int bero, int seat, PlayerActionLog action, int amount = 0); void logBoardCards(int bero, int boardCards[5]); void logHoleCardsHandName(int bero, PlayerList activePlayerList); - void exec_transaction(std::string *sql); + void logAfterHand(); + void logAfterGame(); + void exec_transaction(); // void closeLogDbAtExit(); diff --git a/src/gui/qt/gametable/gametableimpl.cpp b/src/gui/qt/gametable/gametableimpl.cpp index b950005d..ea0bc6c4 100755 --- a/src/gui/qt/gametable/gametableimpl.cpp +++ b/src/gui/qt/gametable/gametableimpl.cpp @@ -2464,7 +2464,6 @@ void gameTableImpl::postRiverRunAnimation3() // if (textLabel_handLabel->text() == "River") { //set Player value (logging) - currentHand->getLog()->logPlayerAction(5,(*it_c)->getMyID()+1,LOG_ACTION_WIN,(*it_c)->getLastMoneyWon()); myGuiLog->logPlayerWinsMsg(QString::fromUtf8((*it_c)->getMyName().c_str()),(*it_c)->getLastMoneyWon(),true); // } @@ -2490,7 +2489,6 @@ void gameTableImpl::postRiverRunAnimation3() for(it_int = winners.begin(); it_int != winners.end(); ++it_int) { if((*it_int) == (*it_c)->getMyUniqueID()) { - currentHand->getLog()->logPlayerAction(5,(*it_c)->getMyID()+1,LOG_ACTION_WIN_SIDE_POT,(*it_c)->getLastMoneyWon()); myGuiLog->logPlayerWinsMsg(QString::fromUtf8((*it_c)->getMyName().c_str()), (*it_c)->getLastMoneyWon(), false); } } @@ -2501,7 +2499,6 @@ void gameTableImpl::postRiverRunAnimation3() for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { if((*it_c)->getMyCash() == 0) { currentHand->getGuiInterface()->logPlayerSitsOut((*it_c)->getMyName()); - currentHand->getLog()->logPlayerAction(5, (*it_c)->getMyID()+1, LOG_ACTION_SIT_OUT); } }