From ef96b76c1da7f839f0f3c637b299b9677e7488de Mon Sep 17 00:00:00 2001 From: floty Date: Sat, 15 Mar 2014 18:58:04 +0100 Subject: [PATCH] replace throwing exceptions in distribute pot function by error handling with error messages --- src/engine/local_engine/localboard.cpp | 45 ++++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 9c154146..92f75b40 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -145,7 +145,7 @@ void LocalBoard::distributePot(unsigned dealerPosition) // determine the number of level winners winnerCount = potLevel.size()-2; if (!winnerCount) { - throw LocalException(__FILE__, __LINE__, ERR_NO_WINNER); + LOG_ERROR(__FILE__ << " (" << __LINE__ << "): distributePot-ERROR: no winner found"); } // check if this is the final pot level for at least one winner @@ -161,7 +161,7 @@ void LocalBoard::distributePot(unsigned dealerPosition) if(finalPot) break; } - if(finalPot) { + if(finalPot && winnerCount>0) { // distribute the pot level sum to level winners mod = (potLevel[1])%winnerCount; // pot level sum divisible by winnerCount @@ -175,13 +175,13 @@ void LocalBoard::distributePot(unsigned dealerPosition) } } if(it == seatsList->end()) { - throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); - } - (*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount)); - - // filling winners vector - winners.push_back((*it)->getMyUniqueID()); - (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount ); + LOG_ERROR(__FILE__ << " (" << __LINE__ << "): distributePot-ERROR: seat not found"); + } else { + (*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount)); + // filling winners vector + winners.push_back((*it)->getMyUniqueID()); + (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount ); + } } } @@ -196,7 +196,8 @@ void LocalBoard::distributePot(unsigned dealerPosition) } } if(it == seatsList->end()) { - throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); + it = seatsList->begin(); + LOG_ERROR(__FILE__ << " (" << __LINE__ << "): distributePot-ERROR: dealer position not found"); } for(j=0; jsetMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); - // filling winners vector - winners.push_back((*it)->getMyUniqueID()); - (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + ((potLevel[1])/winnerCount) + 1 ); - } else { - (*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount)); - // filling winners vector - winners.push_back((*it)->getMyUniqueID()); - (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount ); - } + if(winnerHit) { + if(jsetMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); + // filling winners vector + winners.push_back((*it)->getMyUniqueID()); + (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + ((potLevel[1])/winnerCount) + 1 ); + } else { + (*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount)); + // filling winners vector + winners.push_back((*it)->getMyUniqueID()); + (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount ); + } + } } } potCarryOver = 0;