diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 5dff0bab..92b01cd7 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -486,26 +486,35 @@ void LocalHand::setBlinds() // All in ? if((*it_c)->getMyCash() <= smallBlind) { + myLog->logPlayerAction(0,smallBlindPosition+1,LOG_ACTION_SMALL_BLIND,(*it_c)->getMyCash()); (*it_c)->setMySet((*it_c)->getMyCash()); // 1 to do not log this (*it_c)->setMyAction(PLAYER_ACTION_ALLIN,1); } else { + myLog->logPlayerAction(0,smallBlindPosition+1,LOG_ACTION_SMALL_BLIND,smallBlind); (*it_c)->setMySet(smallBlind); } } + } + + //do sets --> TODO switch? + for (it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); ++it_c) { + //big blind if((*it_c)->getMyButton() == BUTTON_BIG_BLIND) { // all in ? if((*it_c)->getMyCash() <= 2*smallBlind) { + myLog->logPlayerAction(0,bigBlindPosition+1,LOG_ACTION_BIG_BLIND,(*it_c)->getMyCash()); (*it_c)->setMySet((*it_c)->getMyCash()); // 1 to do not log this (*it_c)->setMyAction(PLAYER_ACTION_ALLIN,1); } else { + myLog->logPlayerAction(0,bigBlindPosition+1,LOG_ACTION_BIG_BLIND,2*smallBlind); (*it_c)->setMySet(2*smallBlind); } } diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index e5445ecc..c67966ef 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -3229,12 +3229,14 @@ void LocalPlayer::evaluation(int bet, int raise) {} break; // fold - case 1: - {} + case 1: { + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_FOLD); + } break; // check - case 2: - {} + case 2: { + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_CHECK); + } break; // call case 3: { @@ -3244,12 +3246,14 @@ void LocalPlayer::evaluation(int bet, int raise) mySet += myCash; myCash = 0; myAction = 6; + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_ALL_IN,mySet); // cout << "evaluation(call) - mySet: " << mySet << endl; } // sonst else { myCash = myCash - highestSet + mySet; mySet = highestSet; + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_CALL,mySet); } } break; @@ -3266,6 +3270,7 @@ void LocalPlayer::evaluation(int bet, int raise) myCash = 0; myAction = 6; highestSet = mySet; + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_ALL_IN,mySet); } // sonst else { @@ -3273,6 +3278,7 @@ void LocalPlayer::evaluation(int bet, int raise) myCash = myCash - bet; mySet = bet; highestSet = mySet; + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_BET,mySet); } // lastPlayerAction für Karten umblättern reihenfolge setzrn @@ -3287,12 +3293,14 @@ void LocalPlayer::evaluation(int bet, int raise) mySet += myCash; myCash = 0; myAction = 6; + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_ALL_IN,mySet); } // sonst else { myCash = myCash - highestSet + mySet; mySet = highestSet; myAction = 3; + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_CALL,mySet); } } else { if(raise < currentHand->getCurrentBeRo()->getMinimumRaise()) { @@ -3329,6 +3337,7 @@ void LocalPlayer::evaluation(int bet, int raise) myAction = 6; highestSet = mySet; } + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_ALL_IN,mySet); } // sonst else { @@ -3338,13 +3347,15 @@ void LocalPlayer::evaluation(int bet, int raise) highestSet = mySet; // lastPlayerAction für Karten umblättern reihenfolge setzrn currentHand->setLastActionPlayer(myUniqueID); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_BET,mySet); } } } break; // all in - case 6: - {} + case 6: { + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,myID+1,LOG_ACTION_ALL_IN,mySet); + } break; default: {} diff --git a/src/engine/local_engine/tools.cpp b/src/engine/local_engine/tools.cpp index f12c0aa9..b03e04c6 100755 --- a/src/engine/local_engine/tools.cpp +++ b/src/engine/local_engine/tools.cpp @@ -34,23 +34,25 @@ void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool unsigned char rand_buf[4]; unsigned int randNumber; - int i,j; + int i; if (!different) { - for (i=0; i::max()) / r ) ) * r) { - randArray[i] = start + (randNumber % r); + randArray[counter] = start + (randNumber % r); + counter++; } } @@ -73,8 +75,8 @@ void Tools::getRandNumber(int start, int end, int howMany, int* randArray, bool } randNumber = 0; - for(j=0; j<4; j++) { - randNumber += (rand_buf[j] << 8*j); + for(i=0; i<4; i++) { + randNumber += (rand_buf[i] << 8*i); } if(randNumber < ( (unsigned int) ( ((double)numeric_limits::max()) / r ) ) * r) { diff --git a/src/engine/log.cpp b/src/engine/log.cpp index a719dda7..9c40d3f2 100644 --- a/src/engine/log.cpp +++ b/src/engine/log.cpp @@ -242,7 +242,7 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns sql += ",Seat_" + boost::lexical_cast(i) + "_Cash"; } sql += ") VALUES ("; - sql += boost::lexical_cast(handID); + sql += boost::lexical_cast(curHandID); sql += "," + boost::lexical_cast(curGameID); sql += "," + boost::lexical_cast(dealerPosition+1); sql += "," + boost::lexical_cast(smallBlind); @@ -261,47 +261,86 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; } - // Action 'starts as dealer' - sql = "INSERT INTO Action ("; - sql += "HandID"; - sql += ",GameID"; - sql += ",BeRo"; - sql += ",Player"; - sql += ",Action"; - sql += ",Amount"; - sql += ") VALUES ("; - sql += boost::lexical_cast(handID); - sql += "," + boost::lexical_cast(curGameID); - sql += ",0"; - sql += "," + boost::lexical_cast(dealerPosition+1); - sql += ",'starts as dealer'"; - sql += ",NULL"; - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - } + logPlayerAction(0,dealerPosition+1,LOG_ACTION_DEALER); - // Action 'posts small blind' - sql = "INSERT INTO Action ("; - sql += "HandID"; - sql += ",GameID"; - sql += ",BeRo"; - sql += ",Player"; - sql += ",Action"; - sql += ",Amount"; - sql += ") VALUES ("; - sql += boost::lexical_cast(handID); - sql += "," + boost::lexical_cast(curGameID); - sql += ",0"; - sql += "," + boost::lexical_cast(smallBlindPosition+1); - sql += ",'posts small blind'"; - sql += "," + boost::lexical_cast(smallBlind); - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - } +// // Action 'starts as dealer' +// sql = "INSERT INTO Action ("; +// sql += "HandID"; +// sql += ",GameID"; +// sql += ",BeRo"; +// sql += ",Player"; +// sql += ",Action"; +// sql += ",Amount"; +// sql += ") VALUES ("; +// sql += boost::lexical_cast(curHandID); +// sql += "," + boost::lexical_cast(curGameID); +// sql += ",0"; +// sql += "," + boost::lexical_cast(dealerPosition+1); +// sql += ",'starts as dealer'"; +// sql += ",NULL"; +// sql += ")"; +// if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { +// cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; +// } + +// // Action 'posts small blind' +// sql = "INSERT INTO Action ("; +// sql += "HandID"; +// sql += ",GameID"; +// sql += ",BeRo"; +// sql += ",Player"; +// sql += ",Action"; +// sql += ",Amount"; +// sql += ") VALUES ("; +// sql += boost::lexical_cast(curHandID); +// sql += "," + boost::lexical_cast(curGameID); +// sql += ",0"; +// sql += "," + boost::lexical_cast(smallBlindPosition+1); +// sql += ",'posts small blind'"; +// sql += "," + boost::lexical_cast(smallBlind); +// sql += ")"; +// if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { +// cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; +// } + +// // Action 'posts big blind' +// sql = "INSERT INTO Action ("; +// sql += "HandID"; +// sql += ",GameID"; +// sql += ",BeRo"; +// sql += ",Player"; +// sql += ",Action"; +// sql += ",Amount"; +// sql += ") VALUES ("; +// sql += boost::lexical_cast(curHandID); +// sql += "," + boost::lexical_cast(curGameID); +// sql += ",0"; +// sql += "," + boost::lexical_cast(bigBlindPosition+1); +// sql += ",\'posts big blind'"; +// sql += "," + boost::lexical_cast(bigBlind); +// sql += ")"; +// if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { +// cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; +// } + } + } + } +} + +void Log::logPlayerAction(int bero, int seat, int action, int amount) +{ + + if(SQLITE_LOG) { + + if(logOnOff) { + //if write logfiles is enabled + + string sql; + char *errmsg; + + if( mySqliteLogDb != 0 ) { + // sqlite-db is open - // Action 'posts big blind' sql = "INSERT INTO Action ("; sql += "HandID"; sql += ",GameID"; @@ -310,12 +349,61 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns sql += ",Action"; sql += ",Amount"; sql += ") VALUES ("; - sql += boost::lexical_cast(handID); + sql += boost::lexical_cast(curHandID); sql += "," + boost::lexical_cast(curGameID); - sql += ",0"; - sql += "," + boost::lexical_cast(bigBlindPosition+1); - sql += ",\'posts big blind'"; - sql += "," + boost::lexical_cast(bigBlind); + sql += "," + boost::lexical_cast(bero);; + sql += "," + boost::lexical_cast(seat); + switch(action) { + case LOG_ACTION_DEALER: + sql += ",'starts as dealer'"; + break; + case LOG_ACTION_SMALL_BLIND: + sql += ",'posts small blind'"; + break; + case LOG_ACTION_BIG_BLIND: + sql += ",'posts big blind'"; + break; + case LOG_ACTION_FOLD: + sql += ",'folds'"; + break; + case LOG_ACTION_CHECK: + sql += ",'checks'"; + break; + case LOG_ACTION_CALL: + sql += ",'calls'"; + break; + case LOG_ACTION_BET: + sql += ",'bets'"; + break; + case LOG_ACTION_ALL_IN: + sql += ",'is all in with'"; + break; + case LOG_ACTION_SHOW: + sql += ",'shows'"; + break; + case LOG_ACTION_HAS: + sql += ",'has'"; + break; + case LOG_ACTION_WIN: + sql += ",'wins'"; + break; + case LOG_ACTION_WIN_SIDE_POT: + sql += ",'wins (side pot)'"; + break; + case LOG_ACTION_SIT_OUT: + sql += ",'sits out'"; + break; + case LOG_ACTION_WIN_GAME: + sql += ",'wins game'"; + break; + default: + return; + } + if(amount>0) { + sql += "," + boost::lexical_cast(amount); + } else { + sql += ",NULL"; + } sql += ")"; if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; @@ -342,3 +430,21 @@ void Log::logBoardCards(GameState beroID, int boardCards[5]) // } //} + + + +// ACTION-Code +// 0 starts as dealer +// 1 posts small blind +// 2 posts big blind +// 3 folds +// 4 checks +// 5 calls +// 6 bets +// 7 is all in with +// 8 shows +// 9 has +// 10 wins +// 11 wins (side pot) +// 11 sits out +// 12 wins game diff --git a/src/engine/log.h b/src/engine/log.h index 33448e06..7dcceb4c 100644 --- a/src/engine/log.h +++ b/src/engine/log.h @@ -34,6 +34,7 @@ public: void logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList); void logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList); + void logPlayerAction(int bero, int seat, int action, int amount = 0); void logBoardCards(GameState beroID, int boardCards[5]); // void closeLogDbAtExit(); diff --git a/src/game_defs.h b/src/game_defs.h index 3cc9a424..2f2bf073 100644 --- a/src/game_defs.h +++ b/src/game_defs.h @@ -81,6 +81,23 @@ enum PlayerActionCode { ACTION_CODE_NOT_ALLOWED }; +enum PlayerActionLog { + LOG_ACTION_DEALER = 0, + LOG_ACTION_SMALL_BLIND, + LOG_ACTION_BIG_BLIND, + LOG_ACTION_FOLD, + LOG_ACTION_CHECK, + LOG_ACTION_CALL, + LOG_ACTION_BET, + LOG_ACTION_ALL_IN, + LOG_ACTION_SHOW, + LOG_ACTION_HAS, + LOG_ACTION_WIN, + LOG_ACTION_WIN_SIDE_POT, + LOG_ACTION_SIT_OUT, + LOG_ACTION_WIN_GAME, +}; + enum DenyKickPlayerReason { KICK_DENIED_INVALID_STATE = 0, KICK_DENIED_TOO_FEW_PLAYERS, diff --git a/src/gui/qt/gametable/gametableimpl.cpp b/src/gui/qt/gametable/gametableimpl.cpp index dfe61a1d..8ed3e5af 100755 --- a/src/gui/qt/gametable/gametableimpl.cpp +++ b/src/gui/qt/gametable/gametableimpl.cpp @@ -1826,6 +1826,7 @@ void gameTableImpl::myFold() boost::shared_ptr currentHand = myStartWindow->getSession()->getCurrentGame()->getCurrentHand(); boost::shared_ptr humanPlayer = currentHand->getSeatsList()->front(); humanPlayer->setMyAction(1); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_FOLD); humanPlayer->setMyTurn(0); //set that i was the last active player. need this for unhighlighting groupbox @@ -1844,6 +1845,7 @@ void gameTableImpl::myCheck() boost::shared_ptr currentHand = myStartWindow->getSession()->getCurrentGame()->getCurrentHand(); boost::shared_ptr humanPlayer = currentHand->getSeatsList()->front(); humanPlayer->setMyTurn(0); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_CHECK); humanPlayer->setMyAction(2); //set that i was the last active player. need this for unhighlighting groupbox @@ -1910,9 +1912,11 @@ void gameTableImpl::myCall() humanPlayer->setMySet(humanPlayer->getMyCash()); humanPlayer->setMyCash(0); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_ALL_IN,humanPlayer->getMySet()); humanPlayer->setMyAction(6); } else { humanPlayer->setMySet(tempHighestSet - humanPlayer->getMySet()); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_CALL,humanPlayer->getMySet()); humanPlayer->setMyAction(3); } humanPlayer->setMyTurn(0); @@ -1947,6 +1951,7 @@ void gameTableImpl::mySet() humanPlayer->setMySet(humanPlayer->getMyCash()); humanPlayer->setMyCash(0); humanPlayer->setMyAction(6); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_ALL_IN,humanPlayer->getMySet()); // full bet rule if(currentHand->getCurrentBeRo()->getHighestSet() + currentHand->getCurrentBeRo()->getMinimumRaise() > humanPlayer->getMySet()) { @@ -1958,6 +1963,7 @@ void gameTableImpl::mySet() //do not if allIn if(humanPlayer->getMyAction() != 6) { humanPlayer->setMyAction(5); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_BET,humanPlayer->getMySet()); } myActionIsRaise = 0; @@ -1968,6 +1974,7 @@ void gameTableImpl::mySet() //do not if allIn if(humanPlayer->getMyAction() != 6) { humanPlayer->setMyAction(4); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_BET,humanPlayer->getMySet()); } myActionIsBet = 0; @@ -2005,6 +2012,7 @@ void gameTableImpl::myAllIn() humanPlayer->setMySet(humanPlayer->getMyCash()); humanPlayer->setMyCash(0); humanPlayer->setMyAction(6); + currentHand->getLog()->logPlayerAction(currentHand->getCurrentRound()+1,1,LOG_ACTION_ALL_IN,humanPlayer->getMySet()); // full bet rule if(currentHand->getCurrentBeRo()->getHighestSet() + currentHand->getCurrentBeRo()->getMinimumRaise() > humanPlayer->getMySet()) {