changing parameter in some log-functions; run astyle

This commit is contained in:
floty
2012-01-07 18:42:24 +00:00
parent 476ee936f0
commit 800199f6f0
12 changed files with 182 additions and 121 deletions
+1 -1
View File
@@ -152,7 +152,7 @@ void LocalBeRo::run()
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID");
}
}
if(myHand->getLog()) myHand->getLog()->logBoardCards(myBeRoID, tempBoardCardsArray);
if(myHand->getLog()) myHand->getLog()->logBoardCards(tempBoardCardsArray);
logBoardCardsDone = true;
}
@@ -89,7 +89,7 @@ void LocalBeRoPostRiver::postRiverRun()
if ((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) nonfoldPlayersCounter++;
}
if(nonfoldPlayersCounter>1) {
if(getMyHand()->getLog()) getMyHand()->getLog()->logHoleCardsHandName(GAME_STATE_POST_RIVER,getMyHand()->getActivePlayerList());
if(getMyHand()->getLog()) getMyHand()->getLog()->logHoleCardsHandName(getMyHand()->getActivePlayerList());
}
if(getMyHand()->getLog()) {
getMyHand()->getLog()->logHandWinner(getMyHand()->getActivePlayerList(), highestCardsValue, getMyHand()->getBoard()->getWinners());
+7 -4
View File
@@ -527,7 +527,7 @@ void LocalHand::switchRounds()
// logging last player action
PlayerListConstIterator previousPlayerIt = getRunningPlayerIt(previousPlayerID);
if(previousPlayerIt != runningPlayerList->end()) {
if(myLog) myLog->logPlayerAction(currentRound,(*previousPlayerIt)->getMyID()+1,myLog->transformPlayerActionLog((*previousPlayerIt)->getMyAction()),(*previousPlayerIt)->getMySet());
if(myLog) myLog->logPlayerAction((*previousPlayerIt)->getMyName(),myLog->transformPlayerActionLog((*previousPlayerIt)->getMyAction()),(*previousPlayerIt)->getMySet());
}
PlayerListIterator it, it_1;
@@ -569,6 +569,7 @@ void LocalHand::switchRounds()
myGui->refreshPot();
myGui->refreshSet();
currentRound = GAME_STATE_POST_RIVER;
myLog->setCurrentRound(currentRound);
}
// check for all in condition
@@ -630,11 +631,13 @@ void LocalHand::switchRounds()
myGui->flipHolecardsAllIn();
// Logging HoleCards
if(currentRound<GAME_STATE_RIVER) {
if(myLog) myLog->logHoleCardsHandName(currentRound,activePlayerList);
if(myLog) myLog->logHoleCardsHandName(activePlayerList);
}
if (currentRound < GAME_STATE_POST_RIVER) // do not increment past 4
if (currentRound < GAME_STATE_POST_RIVER) { // do not increment past 4
currentRound = GameState(currentRound + 1);
myLog->setCurrentRound(currentRound);
}
//log board cards for allin
if(currentRound >= GAME_STATE_FLOP) {
@@ -642,7 +645,7 @@ void LocalHand::switchRounds()
myBoard->getMyCards(tempBoardCardsArray);
myGui->logDealBoardCardsMsg(currentRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]);
if(myLog) myLog->logBoardCards(currentRound, tempBoardCardsArray);
if(myLog) myLog->logBoardCards(tempBoardCardsArray);
}
}
+1
View File
@@ -90,6 +90,7 @@ public:
void setCurrentRound(GameState theValue) {
currentRound = theValue;
myLog->setCurrentRound(currentRound);
}
GameState getCurrentRound() const {
return currentRound;
+87 -42
View File
@@ -28,11 +28,8 @@
using namespace std;
Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), uniqueGameID(0), curHandID(0), sql("")
Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), uniqueGameID(0), currentHandID(0), currentRound(GAME_STATE_PREFLOP), sql("")
{
logVersion = 1;
}
Log::~Log()
@@ -94,7 +91,7 @@ Log::init()
sql += "\"" + boost::lexical_cast<string>(POKERTH_BETA_RELEASE_STRING) + "\",";
sql += "\"" + boost::lexical_cast<string>(curDate) + "\",";
sql += "\"" + boost::lexical_cast<string>(curTime) + "\",";
sql += boost::lexical_cast<string>(logVersion) + ");";
sql += boost::lexical_cast<string>(SQLITE_LOG_VERSION) + ");";
// create game table
sql += "CREATE TABLE Game (";
@@ -103,12 +100,16 @@ Log::init()
sql += ",Startmoney INTEGER NOT NULL";
sql += ",StartSb INTEGER NOT NULL";
sql += ",DealerPos INTEGER NOT NULL";
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + " TEXT";
}
sql += ",Winner_Seat INTEGER";
sql += ");";
// create player table
sql += "CREATE TABLE Player (";
sql += "UniqueGameID INTEGER NOT NULL";
sql += ",Seat INTEGER NOT NULL";
sql += ",Player TEXT NOT NULL";
sql += ",PRIMARY KEY(UniqueGameID,Seat));";
// create hand table
sql += "CREATE TABLE Hand (";
sql += "HandID INTEGER NOT NULL";
@@ -170,26 +171,31 @@ Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned deal
sql += ",Startmoney";
sql += ",StartSb";
sql += ",DealerPos";
for(i=1; i<=MAX_NUMBER_OF_PLAYERS; i++) {
sql += ",Seat_" + boost::lexical_cast<std::string>(i);
}
sql += ") VALUES (";
sql += boost::lexical_cast<string>(uniqueGameID);
sql += "," + boost::lexical_cast<string>(gameID);
sql += "," + boost::lexical_cast<string>(startCash);
sql += "," + boost::lexical_cast<string>(startSmallBlind);
sql += "," + boost::lexical_cast<string>(dealerPosition);
sql += ");";
i = 1;
for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) {
if((*it_c)->getMyActiveStatus()) {
sql += "INSERT INTO Player (";
sql += "UniqueGameID";
sql += ",Seat";
sql += ",Player";
sql += ") VALUES (";
sql += boost::lexical_cast<string>(uniqueGameID);
sql += "," + boost::lexical_cast<string>(i);
sql += ",\"" + (*it_c)->getMyName() +"\"";
} else {
sql += ",NULL";
sql += ");";
}
i++;
}
sql += ");";
if(myConfig->readConfigInt("LogInterval") == 0) {
exec_transaction();
}
exec_transaction();
}
}
}
@@ -199,7 +205,8 @@ void
Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList)
{
curHandID = handID;
currentRound = GAME_STATE_PREFLOP;
currentHandID = handID;
PlayerListConstIterator it_c;
for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) {
(*it_c)->setLogHoleCardsDone(false);
@@ -226,7 +233,7 @@ Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + "_Cash";
}
sql += ") VALUES (";
sql += boost::lexical_cast<string>(curHandID);
sql += boost::lexical_cast<string>(currentHandID);
sql += "," + boost::lexical_cast<string>(uniqueGameID);
sql += "," + boost::lexical_cast<string>(dealerPosition);
sql += "," + boost::lexical_cast<string>(smallBlind);
@@ -257,22 +264,22 @@ Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned
}
}
if(countActivePlayer==2) {
logPlayerAction(GAME_STATE_PREFLOP,smallBlindPosition,LOG_ACTION_DEALER);
logPlayerAction(smallBlindPosition,LOG_ACTION_DEALER);
} else {
if(dealerButtonOnTable) {
logPlayerAction(GAME_STATE_PREFLOP,dealerPosition,LOG_ACTION_DEALER);
logPlayerAction(dealerPosition,LOG_ACTION_DEALER);
}
}
// log blinds
for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) {
if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND && (*it_c)->getMySet()>0) {
logPlayerAction(GAME_STATE_PREFLOP,smallBlindPosition,LOG_ACTION_SMALL_BLIND,(*it_c)->getMySet());
logPlayerAction(smallBlindPosition,LOG_ACTION_SMALL_BLIND,(*it_c)->getMySet());
}
}
for(it_c = seatsList->begin(); it_c!=seatsList->end(); ++it_c) {
if((*it_c)->getMyButton() == BUTTON_BIG_BLIND && (*it_c)->getMySet()>0) {
logPlayerAction(GAME_STATE_PREFLOP,bigBlindPosition,LOG_ACTION_BIG_BLIND,(*it_c)->getMySet());
logPlayerAction(bigBlindPosition,LOG_ACTION_BIG_BLIND,(*it_c)->getMySet());
}
}
@@ -286,7 +293,45 @@ Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned
}
void
Log::logPlayerAction(GameState bero, int seat, PlayerActionLog action, int amount)
Log::logPlayerAction(string playerName, PlayerActionLog action, int amount)
{
if(SQLITE_LOG) {
if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled
if( mySqliteLogDb != 0 ) {
// sqlite-db is open
char **result_Player=0;
int nRow_Player=0;
int nCol_Player=0;
char *errmsg = 0;
// read seat
string sql_select = "SELECT Seat FROM Player WHERE UniqueGameID=" + boost::lexical_cast<std::string>(uniqueGameID);
sql_select += " AND ";
sql_select += "Player=\"" + playerName +"\"";
if(sqlite3_get_table(mySqliteLogDb,sql_select.data(),&result_Player,&nRow_Player,&nCol_Player,&errmsg) != SQLITE_OK) {
cout << "Error in statement: " << sql_select.data() << "[" << errmsg << "]." << endl;
} else {
if(nRow_Player == 1) {
logPlayerAction(boost::lexical_cast<int>(result_Player[1]), action, amount);
} else {
cout << sql_select << endl;
cout << "Implausible information about player " << playerName << " in log-db!" << endl;
}
}
sqlite3_free_table(result_Player);
}
}
}
}
void
Log::logPlayerAction(int seat, PlayerActionLog action, int amount)
{
if(SQLITE_LOG) {
@@ -306,9 +351,9 @@ Log::logPlayerAction(GameState bero, int seat, PlayerActionLog action, int amoun
sql += ",Action";
sql += ",Amount";
sql += ") VALUES (";
sql += boost::lexical_cast<string>(curHandID);
sql += boost::lexical_cast<string>(currentHandID);
sql += "," + boost::lexical_cast<string>(uniqueGameID);
sql += "," + boost::lexical_cast<string>(bero);;
sql += "," + boost::lexical_cast<string>(currentRound);;
sql += "," + boost::lexical_cast<string>(seat);
switch(action) {
case LOG_ACTION_DEALER:
@@ -422,7 +467,7 @@ Log::transformPlayerActionLog(PlayerAction action)
}
void
Log::logBoardCards(GameState bero, int boardCards[5])
Log::logBoardCards(int boardCards[5])
{
if(SQLITE_LOG) {
@@ -432,7 +477,7 @@ Log::logBoardCards(GameState bero, int boardCards[5])
if( mySqliteLogDb != 0 ) {
// sqlite-db is open
switch(bero) {
switch(currentRound) {
case GAME_STATE_FLOP: {
sql += "UPDATE Hand SET ";
sql += "BoardCard_1=" + boost::lexical_cast<string>(boardCards[0]) + ",";
@@ -455,7 +500,7 @@ Log::logBoardCards(GameState bero, int boardCards[5])
}
sql += " WHERE ";
sql += "UniqueGameID=" + boost::lexical_cast<string>(uniqueGameID) + " AND ";
sql += "HandID=" + boost::lexical_cast<string>(curHandID);
sql += "HandID=" + boost::lexical_cast<string>(currentHandID);
sql += ";";
if(myConfig->readConfigInt("LogInterval") == 0) {
exec_transaction();
@@ -466,22 +511,22 @@ Log::logBoardCards(GameState bero, int boardCards[5])
}
void
Log::logHoleCardsHandName(GameState bero, PlayerList activePlayerList)
Log::logHoleCardsHandName(PlayerList activePlayerList)
{
PlayerListConstIterator it_c;
for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD && ( ((*it_c)->checkIfINeedToShowCards() && bero==GAME_STATE_POST_RIVER ) || ( bero!=GAME_STATE_POST_RIVER && !(*it_c)->getLogHoleCardsDone()) ) ) {
if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD && ( ((*it_c)->checkIfINeedToShowCards() && currentRound==GAME_STATE_POST_RIVER ) || ( currentRound!=GAME_STATE_POST_RIVER && !(*it_c)->getLogHoleCardsDone()) ) ) {
logHoleCardsHandName(bero, activePlayerList, *it_c);
logHoleCardsHandName(activePlayerList, *it_c);
}
}
}
void
Log::logHoleCardsHandName(GameState bero, PlayerList activePlayerList, boost::shared_ptr<PlayerInterface> player, bool forceExecLog)
Log::logHoleCardsHandName(PlayerList activePlayerList, boost::shared_ptr<PlayerInterface> player, bool forceExecLog)
{
if(SQLITE_LOG) {
@@ -494,11 +539,11 @@ Log::logHoleCardsHandName(GameState bero, PlayerList activePlayerList, boost::sh
int myCards[2];
player->getMyCards(myCards);
sql += "UPDATE Hand SET ";
if(bero==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0) {
if(currentRound==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0) {
sql += "Seat_" + boost::lexical_cast<string>(player->getMyID()+1) + "_Hand_text=\"" + CardsValue::determineHandName(player->getMyCardsValueInt(),activePlayerList) + "\"";
sql += ",Seat_" + boost::lexical_cast<string>(player->getMyID()+1) + "_Hand_int=" + boost::lexical_cast<string>(player->getMyCardsValueInt());
}
if(bero==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0 && !player->getLogHoleCardsDone()) {
if(currentRound==GAME_STATE_POST_RIVER && player->getMyCardsValueInt()>0 && !player->getLogHoleCardsDone()) {
sql+= ",";
}
if(!player->getLogHoleCardsDone()) {
@@ -507,16 +552,16 @@ Log::logHoleCardsHandName(GameState bero, PlayerList activePlayerList, boost::sh
}
sql += " WHERE ";
sql += "UniqueGameID=" + boost::lexical_cast<string>(uniqueGameID) + " AND ";
sql += "HandID=" + boost::lexical_cast<string>(curHandID);
sql += "HandID=" + boost::lexical_cast<string>(currentHandID);
sql += ";";
if(myConfig->readConfigInt("LogInterval") == 0 || forceExecLog) {
exec_transaction();
}
if(!player->getLogHoleCardsDone()) {
logPlayerAction(bero,player->getMyID()+1,LOG_ACTION_SHOW);
logPlayerAction(player->getMyName(),LOG_ACTION_SHOW);
} else {
logPlayerAction(bero,player->getMyID()+1,LOG_ACTION_HAS);
logPlayerAction(player->getMyName(),LOG_ACTION_HAS);
}
player->setLogHoleCardsDone(true);
@@ -537,7 +582,7 @@ Log::logHandWinner(PlayerList activePlayerList, int highestCardsValue, std::list
// log winner
for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
if((*it_c)->getMyAction() != PLAYER_ACTION_FOLD && (*it_c)->getMyCardsValueInt() == highestCardsValue) {
logPlayerAction(GAME_STATE_POST_RIVER,(*it_c)->getMyID()+1,LOG_ACTION_WIN,(*it_c)->getLastMoneyWon());
logPlayerAction((*it_c)->getMyName(),LOG_ACTION_WIN,(*it_c)->getLastMoneyWon());
}
}
@@ -547,7 +592,7 @@ Log::logHandWinner(PlayerList activePlayerList, int highestCardsValue, std::list
for(it_int = winners.begin(); it_int != winners.end(); ++it_int) {
if((*it_int) == (*it_c)->getMyUniqueID()) {
logPlayerAction(GAME_STATE_POST_RIVER,(*it_c)->getMyID()+1,LOG_ACTION_WIN_SIDE_POT,(*it_c)->getLastMoneyWon());
logPlayerAction((*it_c)->getMyName(),LOG_ACTION_WIN_SIDE_POT,(*it_c)->getLastMoneyWon());
}
}
}
@@ -567,7 +612,7 @@ Log::logGameWinner(PlayerList activePlayerList)
if (playersPositiveCashCounter==1) {
for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
if ((*it_c)->getMyCash() > 0) {
logPlayerAction(GAME_STATE_POST_RIVER,(*it_c)->getMyID()+1,LOG_ACTION_WIN_GAME);
logPlayerAction((*it_c)->getMyName(),LOG_ACTION_WIN_GAME);
}
}
// for log after every game
@@ -584,7 +629,7 @@ Log::logPlayerSitsOut(PlayerList activePlayerList)
for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
if((*it_c)->getMyCash() == 0) {
logPlayerAction(GAME_STATE_POST_RIVER, (*it_c)->getMyID()+1, LOG_ACTION_SIT_OUT);
logPlayerAction((*it_c)->getMyName(), LOG_ACTION_SIT_OUT);
}
}
+11 -5
View File
@@ -37,11 +37,12 @@ public:
void init();
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(GameState bero, int seat, PlayerActionLog action, int amount = 0);
void logPlayerAction(std::string playerName, PlayerActionLog action, int amount = 0);
void logPlayerAction(int seat, PlayerActionLog action, int amount = 0);
PlayerActionLog transformPlayerActionLog(PlayerAction action);
void logBoardCards(GameState bero, int boardCards[5]);
void logHoleCardsHandName(GameState bero, PlayerList activePlayerList);
void logHoleCardsHandName(GameState bero, PlayerList activePlayerList, boost::shared_ptr<PlayerInterface> player, bool forceExecLog = 0);
void logBoardCards(int boardCards[5]);
void logHoleCardsHandName(PlayerList activePlayerList);
void logHoleCardsHandName(PlayerList activePlayerList, boost::shared_ptr<PlayerInterface> player, bool forceExecLog = 0);
void logHandWinner(PlayerList activePlayerList, int highestCardsValue, std::list<unsigned> winners);
void logGameWinner(PlayerList activePlayerList);
void logPlayerSitsOut(PlayerList activePlayerList);
@@ -49,6 +50,10 @@ public:
void logAfterGame();
// void closeLogDbAtExit();
void setCurrentRound(GameState theValue) {
currentRound = theValue;
}
private:
@@ -58,7 +63,8 @@ private:
sqlite3 *mySqliteLogDb;
ConfigFile *myConfig;
int uniqueGameID;
int curHandID;
int currentHandID;
GameState currentRound;
std::string sql;
};