replace throwing exceptions in distribute pot function by error handling with error messages

This commit is contained in:
floty
2014-03-15 18:58:04 +01:00
parent 7f3c8a8608
commit ef96b76c1d
+24 -21
View File
@@ -145,7 +145,7 @@ void LocalBoard::distributePot(unsigned dealerPosition)
// determine the number of level winners // determine the number of level winners
winnerCount = potLevel.size()-2; winnerCount = potLevel.size()-2;
if (!winnerCount) { 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 // 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) break;
} }
if(finalPot) { if(finalPot && winnerCount>0) {
// distribute the pot level sum to level winners // distribute the pot level sum to level winners
mod = (potLevel[1])%winnerCount; mod = (potLevel[1])%winnerCount;
// pot level sum divisible by winnerCount // pot level sum divisible by winnerCount
@@ -175,13 +175,13 @@ void LocalBoard::distributePot(unsigned dealerPosition)
} }
} }
if(it == seatsList->end()) { if(it == seatsList->end()) {
throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND); LOG_ERROR(__FILE__ << " (" << __LINE__ << "): distributePot-ERROR: seat not found");
} } else {
(*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount)); (*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount));
// filling winners vector
// filling winners vector winners.push_back((*it)->getMyUniqueID());
winners.push_back((*it)->getMyUniqueID()); (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount );
(*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount ); }
} }
} }
@@ -196,7 +196,8 @@ void LocalBoard::distributePot(unsigned dealerPosition)
} }
} }
if(it == seatsList->end()) { 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; j<winnerCount; j++) { for(j=0; j<winnerCount; j++) {
@@ -216,17 +217,19 @@ void LocalBoard::distributePot(unsigned dealerPosition)
} }
if(j<mod) { if(winnerHit) {
(*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); if(j<mod) {
// filling winners vector (*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1);
winners.push_back((*it)->getMyUniqueID()); // filling winners vector
(*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + ((potLevel[1])/winnerCount) + 1 ); winners.push_back((*it)->getMyUniqueID());
} else { (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + ((potLevel[1])/winnerCount) + 1 );
(*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount)); } else {
// filling winners vector (*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount));
winners.push_back((*it)->getMyUniqueID()); // filling winners vector
(*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount ); winners.push_back((*it)->getMyUniqueID());
} (*it)->setLastMoneyWon( (*it)->getLastMoneyWon() + (potLevel[1])/winnerCount );
}
}
} }
} }
potCarryOver = 0; potCarryOver = 0;