sqlite-log: implementing action logging

This commit is contained in:
floty
2011-02-27 00:03:39 +00:00
parent 63b28d7167
commit 1f833d106a
7 changed files with 212 additions and 58 deletions
+9
View File
@@ -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);
}
}
+17 -6
View File
@@ -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:
{}
+9 -7
View File
@@ -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<howMany; i++) {
int counter(0);
while(counter < howMany) {
if(!RAND_bytes(rand_buf, 4)) {
LOG_MSG("RAND_bytes failed!");
}
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<unsigned int>::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<unsigned int>::max()) / r ) ) * r) {
+151 -45
View File
@@ -242,7 +242,7 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns
sql += ",Seat_" + boost::lexical_cast<std::string>(i) + "_Cash";
}
sql += ") VALUES (";
sql += boost::lexical_cast<string>(handID);
sql += boost::lexical_cast<string>(curHandID);
sql += "," + boost::lexical_cast<string>(curGameID);
sql += "," + boost::lexical_cast<string>(dealerPosition+1);
sql += "," + boost::lexical_cast<string>(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<string>(handID);
sql += "," + boost::lexical_cast<string>(curGameID);
sql += ",0";
sql += "," + boost::lexical_cast<string>(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<string>(handID);
sql += "," + boost::lexical_cast<string>(curGameID);
sql += ",0";
sql += "," + boost::lexical_cast<string>(smallBlindPosition+1);
sql += ",'posts small blind'";
sql += "," + boost::lexical_cast<string>(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<string>(curHandID);
// sql += "," + boost::lexical_cast<string>(curGameID);
// sql += ",0";
// sql += "," + boost::lexical_cast<string>(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<string>(curHandID);
// sql += "," + boost::lexical_cast<string>(curGameID);
// sql += ",0";
// sql += "," + boost::lexical_cast<string>(smallBlindPosition+1);
// sql += ",'posts small blind'";
// sql += "," + boost::lexical_cast<string>(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<string>(curHandID);
// sql += "," + boost::lexical_cast<string>(curGameID);
// sql += ",0";
// sql += "," + boost::lexical_cast<string>(bigBlindPosition+1);
// sql += ",\'posts big blind'";
// sql += "," + boost::lexical_cast<string>(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<string>(handID);
sql += boost::lexical_cast<string>(curHandID);
sql += "," + boost::lexical_cast<string>(curGameID);
sql += ",0";
sql += "," + boost::lexical_cast<string>(bigBlindPosition+1);
sql += ",\'posts big blind'";
sql += "," + boost::lexical_cast<string>(bigBlind);
sql += "," + boost::lexical_cast<string>(bero);;
sql += "," + boost::lexical_cast<string>(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<string>(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
+1
View File
@@ -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();