asserts -> LocalExceptions

This commit is contained in:
floty
2007-10-14 11:01:44 +00:00
parent e54242b711
commit 7f07d066aa
11 changed files with 202 additions and 81 deletions
+19 -11
View File
@@ -1,14 +1,22 @@
//
// C++ Interface: berointerface
//
// Description: Betting rounds interface
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (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
+35
View File
@@ -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
+45 -20
View File
@@ -1,16 +1,27 @@
//
// C++ Implementation: localbero
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (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; i<myHand->getActivePlayerList()->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);
+19 -14
View File
@@ -1,14 +1,22 @@
//
// C++ Interface: localbero
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (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 <webmaster@pokerth.net>
*/
class LocalBeRo : public BeRoInterface{
public:
LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState gS);
+14 -5
View File
@@ -19,6 +19,9 @@
***************************************************************************/
#include "localberopreflop.h"
#include "localexception.h"
#include "engine_msg.h"
#include <handinterface.h>
#include <game_defs.h>
@@ -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);
+10 -3
View File
@@ -22,6 +22,7 @@
#include "handinterface.h"
#include <game_defs.h>
#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; j<potLevel.size(); j++) {
it = currentHand->getSeatIt(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(j<mod) {
(*it)->setMyCash( (*it)->getMyCash() + (int)((potLevel[1])/winnerCount) + 1);
} else {
+12 -3
View File
@@ -22,6 +22,9 @@
#include "cardsvalue.h"
#include <game_defs.h>
#include "localexception.h"
#include "engine_msg.h"
#include <iostream>
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; i<seatsList->size(); i++) {
@@ -434,7 +441,9 @@ void LocalHand::assignButtons() {
}
}
assert(nextActivePlayerFound);
if(!nextActivePlayerFound) {
throw LocalException(ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND);
}
+19 -11
View File
@@ -1,14 +1,22 @@
//
// C++ Implementation: clientbero
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (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)
+19 -11
View File
@@ -1,14 +1,22 @@
//
// C++ Interface: clientbero
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (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
+1 -1
View File
@@ -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. *
* *