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());
}
// 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<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;
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
+36 -14
View File
@@ -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<string>(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<string>(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;
+3 -1
View File
@@ -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();