From 7f07d066aa4c8d57c628471f6fabaee1c761540c Mon Sep 17 00:00:00 2001 From: floty Date: Sun, 14 Oct 2007 11:01:44 +0000 Subject: [PATCH] asserts -> LocalExceptions --- src/engine/berointerface.h | 30 +++++---- src/engine/local_engine/engine_msg.h | 35 +++++++++++ src/engine/local_engine/localbero.cpp | 65 ++++++++++++++------ src/engine/local_engine/localbero.h | 33 +++++----- src/engine/local_engine/localberopreflop.cpp | 19 ++++-- src/engine/local_engine/localboard.cpp | 13 +++- src/engine/local_engine/localhand.cpp | 15 ++++- src/engine/network_engine/clientbero.cpp | 30 +++++---- src/engine/network_engine/clientbero.h | 30 +++++---- src/engine/network_engine/clienthand.h | 2 +- src/game.cpp | 11 +++- 11 files changed, 202 insertions(+), 81 deletions(-) create mode 100644 src/engine/local_engine/engine_msg.h diff --git a/src/engine/berointerface.h b/src/engine/berointerface.h index 1f82d342..30d4de3c 100644 --- a/src/engine/berointerface.h +++ b/src/engine/berointerface.h @@ -1,14 +1,22 @@ -// -// C++ Interface: berointerface -// -// Description: Betting rounds interface -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #ifndef BEROINTERFACE_H #define BEROINTERFACE_H diff --git a/src/engine/local_engine/engine_msg.h b/src/engine/local_engine/engine_msg.h new file mode 100644 index 00000000..955f10b9 --- /dev/null +++ b/src/engine/local_engine/engine_msg.h @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef _ENGINE_MSG_H_ +#define _ENGINE_MSG_H_ + +// Engine errors -> LocalExceptions +#define ERR_SEAT_NOT_FOUND 10001 +#define ERR_ACTIVE_PLAYER_NOT_FOUND 10002 +#define ERR_RUNNING_PLAYER_NOT_FOUND 10003 + +#define ERR_NEXT_DEALER_NOT_FOUND 10010 +#define ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND 10011 +#define ERR_FORMER_RUNNING_PLAYER_NOT_FOUND 10012 + +#define ERR_NO_WINNER 10020 + +#endif + diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index ce420601..90580cd0 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -1,16 +1,27 @@ -// -// C++ Implementation: localbero -// -// Description: -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #include "localbero.h" +#include "localexception.h" +#include "engine_msg.h" + using namespace std; LocalBeRo::LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState gS) @@ -28,7 +39,9 @@ LocalBeRo::LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState g break; } } - assert(it_c!=myHand->getActivePlayerList()->end()); + if(it_c == myHand->getActivePlayerList()->end()) { + throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + } // determine smallBlindPosition for(it_c=myHand->getActivePlayerList()->begin(); it_c!=myHand->getActivePlayerList()->end(); it_c++) { @@ -37,7 +50,9 @@ LocalBeRo::LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState g break; } } - assert(it_c!=myHand->getActivePlayerList()->end()); + if(it_c == myHand->getActivePlayerList()->end()) { + throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + } @@ -71,7 +86,9 @@ void LocalBeRo::nextPlayer() { // cout << "playerID in nextPlayer(): " << (*currentPlayersTurnIt)->getMyID() << endl; PlayerListConstIterator currentPlayersTurnConstIt = myHand->getRunningPlayerIt(currentPlayersTurnId); - assert( currentPlayersTurnConstIt != myHand->getRunningPlayerList()->end() ); + if(currentPlayersTurnConstIt == myHand->getRunningPlayerList()->end()) { + throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + } (*currentPlayersTurnConstIt)->action(); @@ -156,11 +173,13 @@ void LocalBeRo::run() { size_t i; // running player before smallBlind - bool runningPlayerFound = false; + bool formerRunningPlayerFound = false; if(myHand->getActivePlayerList()->size() > 2) { it_1 = myHand->getActivePlayerIt(smallBlindPositionId); - assert( it_1 != myHand->getActivePlayerList()->end() ); + if(it_1 == myHand->getActivePlayerList()->end()) { + throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + } for(i=0; igetActivePlayerList()->size(); i++) { @@ -171,11 +190,13 @@ void LocalBeRo::run() { // running player found if(it_2 != myHand->getRunningPlayerList()->end()) { firstRoundLastPlayersTurnId = (*it_2)->getMyUniqueID(); - runningPlayerFound = true; + formerRunningPlayerFound = true; break; } } - assert(runningPlayerFound); + if(!formerRunningPlayerFound) { + throw LocalException(ERR_FORMER_RUNNING_PLAYER_NOT_FOUND); + } } // heads up: bigBlind begins -> dealer/smallBlind is running player before bigBlind else { @@ -321,7 +342,9 @@ void LocalBeRo::run() { // determine next running player PlayerListConstIterator currentPlayersTurnIt = myHand->getRunningPlayerIt( currentPlayersTurnId ); - assert( currentPlayersTurnIt != myHand->getRunningPlayerList()->end() ); + if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) { + throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + } currentPlayersTurnIt++; if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) currentPlayersTurnIt = myHand->getRunningPlayerList()->begin(); @@ -362,7 +385,9 @@ void LocalBeRo::run() { // if(myHand->getActivePlayerList()->size() < 3 && (myHand->getPlayerArray()[playersTurn]->getMyID() == dealerPosition || myHand->getPlayerArray()[playersTurn]->getMyID() == smallBlindPosition)) { firstRound = 0; } currentPlayersTurnIt = myHand->getRunningPlayerIt( currentPlayersTurnId ); - assert( currentPlayersTurnIt != myHand->getRunningPlayerList()->end() ); + if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) { + throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + } (*currentPlayersTurnIt)->setMyTurn(true); diff --git a/src/engine/local_engine/localbero.h b/src/engine/local_engine/localbero.h index 99e8be2c..d6e0153d 100644 --- a/src/engine/local_engine/localbero.h +++ b/src/engine/local_engine/localbero.h @@ -1,14 +1,22 @@ -// -// C++ Interface: localbero -// -// Description: -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #ifndef LOCALBERO_H #define LOCALBERO_H @@ -19,9 +27,6 @@ #include "berointerface.h" #include "handinterface.h" -/** - @author FThauer FHammer -*/ class LocalBeRo : public BeRoInterface{ public: LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState gS); diff --git a/src/engine/local_engine/localberopreflop.cpp b/src/engine/local_engine/localberopreflop.cpp index 50cc5465..e9572409 100644 --- a/src/engine/local_engine/localberopreflop.cpp +++ b/src/engine/local_engine/localberopreflop.cpp @@ -19,6 +19,9 @@ ***************************************************************************/ #include "localberopreflop.h" +#include "localexception.h" +#include "engine_msg.h" + #include #include @@ -87,7 +90,9 @@ void LocalBeRoPreflop::run() { if(smallBlindPositionIt == getMyHand()->getRunningPlayerList()->end()) { it = getMyHand()->getActivePlayerIt(getSmallBlindPositionId()); - assert(it != getMyHand()->getActivePlayerList()->end()); + if(it == getMyHand()->getActivePlayerList()->end()) { + throw LocalException(ERR_ACTIVE_PLAYER_NOT_FOUND); + } if(it == getMyHand()->getActivePlayerList()->begin()) it = getMyHand()->getActivePlayerList()->end(); it--; @@ -221,7 +226,9 @@ void LocalBeRoPreflop::run() { // cout << "currentPlayerID: " << getCurrentPlayersTurnId() << endl; PlayerListConstIterator currentPlayersTurnIt = getMyHand()->getRunningPlayerIt( getCurrentPlayersTurnId() ); - assert( currentPlayersTurnIt != getMyHand()->getRunningPlayerList()->end() ); + if(currentPlayersTurnIt == getMyHand()->getRunningPlayerList()->end()) { + throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + } currentPlayersTurnIt++; if(currentPlayersTurnIt == getMyHand()->getRunningPlayerList()->end()) currentPlayersTurnIt = getMyHand()->getRunningPlayerList()->begin(); @@ -344,9 +351,11 @@ void LocalBeRoPreflop::run() { // getMyHand()->getPlayerArray()[getPlayersTurn()]->setMyTurn(1); - currentPlayersTurnConstIt = getMyHand()->getRunningPlayerIt( getCurrentPlayersTurnId() ); - assert(currentPlayersTurnConstIt != getMyHand()->getRunningPlayerList()->end()); - (*currentPlayersTurnConstIt)->setMyTurn(true); + currentPlayersTurnIt = getMyHand()->getRunningPlayerIt( getCurrentPlayersTurnId() ); + if(currentPlayersTurnIt == getMyHand()->getRunningPlayerList()->end()) { + throw LocalException(ERR_RUNNING_PLAYER_NOT_FOUND); + } + (*currentPlayersTurnIt)->setMyTurn(true); // (*(getCurrentPlayersTurnIt()))->setMyTurn(true); diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 9b0b3ebf..2deffece 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -22,6 +22,7 @@ #include "handinterface.h" #include #include "localexception.h" +#include "engine_msg.h" using namespace std; @@ -158,7 +159,9 @@ void LocalBoard::distributePot() { // determine the number of level winners winnerCount = potLevel.size()-2; - assert(winnerCount); + if (!winnerCount) { + throw LocalException(ERR_NO_WINNER); + } // distribute the pot level sum to level winners mod = (potLevel[1])%winnerCount; @@ -170,7 +173,9 @@ void LocalBoard::distributePot() { for(j=2; jgetSeatIt(potLevel[j]); - assert(it != seatsList->end()); + if(it == seatsList->end()) { + throw LocalException(ERR_SEAT_NOT_FOUND); + } (*it)->setMyCash( (*it)->getMyCash() + ((potLevel[1])/winnerCount)); } @@ -205,7 +210,9 @@ void LocalBoard::distributePot() { it = currentHand->getSeatIt(winnerPointer); - assert(it != seatsList->end()); + if(it == seatsList->end()) { + throw LocalException(ERR_SEAT_NOT_FOUND); + } if(jsetMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1); } else { diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 485632fe..a8622641 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -22,6 +22,9 @@ #include "cardsvalue.h" #include +#include "localexception.h" +#include "engine_msg.h" + #include using namespace std; @@ -377,7 +380,9 @@ void LocalHand::assignButtons() { // DealerButton zuweisen it = getSeatIt(dealerPosition); - assert(it != seatsList->end() ); + if(it == seatsList->end()) { + throw LocalException(ERR_SEAT_NOT_FOUND); + } (*it)->setMyButton(BUTTON_DEALER); @@ -411,7 +416,9 @@ void LocalHand::assignButtons() { // assign big blind next to small blind. ATTENTION: in heads up it is small blind bool nextActivePlayerFound = false; PlayerListIterator dealerPositionIt = getSeatIt(dealerPosition); - assert( dealerPositionIt != seatsList->end() ); + if(dealerPositionIt == seatsList->end()) { + throw LocalException(ERR_SEAT_NOT_FOUND); + } for(i=0; isize(); i++) { @@ -434,7 +441,9 @@ void LocalHand::assignButtons() { } } - assert(nextActivePlayerFound); + if(!nextActivePlayerFound) { + throw LocalException(ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND); + } diff --git a/src/engine/network_engine/clientbero.cpp b/src/engine/network_engine/clientbero.cpp index 483cfb8a..d2670766 100644 --- a/src/engine/network_engine/clientbero.cpp +++ b/src/engine/network_engine/clientbero.cpp @@ -1,14 +1,22 @@ -// -// C++ Implementation: clientbero -// -// Description: -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #include "clientbero.h" ClientBeRo::ClientBeRo(HandInterface* hi, int /*id*/, unsigned dP, int sB, GameState gS) diff --git a/src/engine/network_engine/clientbero.h b/src/engine/network_engine/clientbero.h index e37e4682..a7679836 100644 --- a/src/engine/network_engine/clientbero.h +++ b/src/engine/network_engine/clientbero.h @@ -1,14 +1,22 @@ -// -// C++ Interface: clientbero -// -// Description: -// -// -// Author: FThauer FHammer , (C) 2007 -// -// Copyright: See COPYING file that comes with this distribution -// -// +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ #ifndef CLIENTBERO_H #define CLIENTBERO_H diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index 62b7a64d..b8037eab 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -7,7 +7,7 @@ * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * -` * but WITHOUT ANY WARRANTY; without even the implied warranty of * +`* but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * diff --git a/src/game.cpp b/src/game.cpp index e9819d5a..62afcde6 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -22,6 +22,9 @@ #include #include +#include "localexception.h" +#include "engine_msg.h" + #include #include @@ -199,7 +202,9 @@ void Game::initHand() // Dealer-Button weiterschieben --> Achtung inactive -> TODO exception-rule !!! bool nextDealerFound = false; PlayerListConstIterator dealerPositionIt = actualHand->getSeatIt(dealerPosition); - assert( dealerPositionIt != seatsList->end() ); + if(dealerPositionIt == seatsList->end()) { + throw LocalException(ERR_SEAT_NOT_FOUND); + } for(i=0; isize(); i++) { @@ -214,7 +219,9 @@ void Game::initHand() } } - assert(nextDealerFound); + if(!nextDealerFound) { + throw LocalException(ERR_NEXT_DEALER_NOT_FOUND); + } }