sqlite-logging at the end of hand/game possible; moving winner/sitOut-logging from gui to engine

This commit is contained in:
floty
2011-11-01 18:03:48 +00:00
parent 3f8086eba4
commit 3352a199fc
4 changed files with 73 additions and 20 deletions
+34 -2
View File
@@ -92,8 +92,38 @@ void LocalBeRoPostRiver::postRiverRun()
getMyHand()->getLog()->logHoleCardsHandName(5,getMyHand()->getActivePlayerList()); getMyHand()->getLog()->logHoleCardsHandName(5,getMyHand()->getActivePlayerList());
} }
// logging winner if game is over // logging winner of the hand
// wenn nur noch ein Spieler aktive "neues Spiel"-Dialog anzeigen 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<unsigned> winners = getMyHand()->getBoard()->getWinners();
list<unsigned>::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; int playersPositiveCashCounter = 0;
for (it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) { for (it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) {
if ((*it_c)->getMyCash() > 0) playersPositiveCashCounter++; 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); getMyHand()->getLog()->logPlayerAction(5,(*it_c)->getMyID()+1,LOG_ACTION_WIN_GAME);
} }
} }
// for log after every game
getMyHand()->getLog()->logAfterGame();
} }
//starte die Animaionsreihe //starte die Animaionsreihe
+36 -14
View File
@@ -122,7 +122,7 @@ Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID
sql += ",Amount INTEGER"; sql += ",Amount INTEGER";
sql += ");"; 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; curGameID = gameID;
@@ -173,13 +174,16 @@ void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned
} }
} }
sql += ");"; 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; curHandID = handID;
@@ -224,7 +228,7 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns
} }
sql += ");"; sql += ");";
if(myConfig->readConfigInt("LogInterval") == 0) { 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) // !! 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) { if(SQLITE_LOG) {
@@ -327,14 +332,15 @@ void Log::logPlayerAction(int bero, int seat, PlayerActionLog action, int amount
} }
sql += ");"; sql += ");";
if(myConfig->readConfigInt("LogInterval") == 0) { 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) { if(SQLITE_LOG) {
@@ -370,14 +376,15 @@ void Log::logBoardCards(int bero, int boardCards[5])
sql += "HandID=" + boost::lexical_cast<string>(curHandID); sql += "HandID=" + boost::lexical_cast<string>(curHandID);
sql += ";"; sql += ";";
if(myConfig->readConfigInt("LogInterval") == 0) { 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) { if(SQLITE_LOG) {
@@ -410,7 +417,7 @@ void Log::logHoleCardsHandName(int bero, PlayerList activePlayerList)
sql += "HandID=" + boost::lexical_cast<string>(curHandID); sql += "HandID=" + boost::lexical_cast<string>(curHandID);
sql += ";"; sql += ";";
if(myConfig->readConfigInt("LogInterval") == 0) { if(myConfig->readConfigInt("LogInterval") == 0) {
exec_transaction(&sql); exec_transaction();
} }
if(!logHoleCardsDone) { 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; char *errmsg = NULL;
string sql_transaction = "BEGIN;" + *sql + "COMMIT;"; string sql_transaction = "BEGIN;" + sql + "COMMIT;";
*sql = ""; sql = "";
if(sqlite3_exec(mySqliteLogDb, sql_transaction.data(), 0, 0, &errmsg) != SQLITE_OK) { if(sqlite3_exec(mySqliteLogDb, sql_transaction.data(), 0, 0, &errmsg) != SQLITE_OK) {
cout << "Error in statement: " << sql_transaction.data() << "[" << errmsg << "]." << endl; cout << "Error in statement: " << sql_transaction.data() << "[" << errmsg << "]." << endl;
+3 -1
View File
@@ -39,7 +39,9 @@ public:
void logPlayerAction(int bero, int seat, PlayerActionLog action, int amount = 0); void logPlayerAction(int bero, int seat, PlayerActionLog action, int amount = 0);
void logBoardCards(int bero, int boardCards[5]); void logBoardCards(int bero, int boardCards[5]);
void logHoleCardsHandName(int bero, PlayerList activePlayerList); void logHoleCardsHandName(int bero, PlayerList activePlayerList);
void exec_transaction(std::string *sql); void logAfterHand();
void logAfterGame();
void exec_transaction();
// void closeLogDbAtExit(); // void closeLogDbAtExit();
-3
View File
@@ -2464,7 +2464,6 @@ void gameTableImpl::postRiverRunAnimation3()
// if (textLabel_handLabel->text() == "River") { // if (textLabel_handLabel->text() == "River") {
//set Player value (logging) //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); 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) { for(it_int = winners.begin(); it_int != winners.end(); ++it_int) {
if((*it_int) == (*it_c)->getMyUniqueID()) { 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); 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) { for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
if((*it_c)->getMyCash() == 0) { if((*it_c)->getMyCash() == 0) {
currentHand->getGuiInterface()->logPlayerSitsOut((*it_c)->getMyName()); currentHand->getGuiInterface()->logPlayerSitsOut((*it_c)->getMyName());
currentHand->getLog()->logPlayerAction(5, (*it_c)->getMyID()+1, LOG_ACTION_SIT_OUT);
} }
} }