From 0a0a24433e4f9a320f16d71c41c7d05c2ece53a6 Mon Sep 17 00:00:00 2001 From: doitux Date: Sat, 4 Aug 2007 22:05:12 +0000 Subject: [PATCH] more polymorphie steps for BeRo - local game --> unstable --- src/engine/enginefactory.h | 2 +- src/engine/local_engine/localberofactory.cpp | 4 +- src/engine/local_engine/localberofactory.h | 13 +- src/engine/local_engine/localberopreflop.cpp | 127 ++++++++++++++++++ src/engine/local_engine/localberopreflop.h | 66 +++++++++ .../local_engine/localenginefactory.cpp | 5 +- src/engine/local_engine/localenginefactory.h | 4 +- src/engine/local_engine/localhand.cpp | 2 +- .../network_engine/clientberofactory.cpp | 2 +- src/engine/network_engine/clientberofactory.h | 2 +- .../network_engine/clientenginefactory.cpp | 10 +- .../network_engine/clientenginefactory.h | 4 +- 12 files changed, 216 insertions(+), 25 deletions(-) create mode 100644 src/engine/local_engine/localberopreflop.cpp create mode 100644 src/engine/local_engine/localberopreflop.h diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index fda370f3..e3e8aea2 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -46,7 +46,7 @@ public: virtual TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB) =0; virtual RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB) =0; // virtual BeRoInterface* createBeRo() =0; - virtual BeRoFactoryInterface* createBeRoFactory(HandInterface* hi) =0; + virtual BeRoFactoryInterface* createBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB) =0; }; #endif diff --git a/src/engine/local_engine/localberofactory.cpp b/src/engine/local_engine/localberofactory.cpp index f4ac46d0..e47ecdf0 100644 --- a/src/engine/local_engine/localberofactory.cpp +++ b/src/engine/local_engine/localberofactory.cpp @@ -11,8 +11,8 @@ // #include "localberofactory.h" -LocalBeRoFactory::LocalBeRoFactory ( HandInterface* hi ) - : BeRoFactoryInterface() , myHand ( hi ) +LocalBeRoFactory::LocalBeRoFactory (HandInterface* hi, int id, int aP, int dP, int sB) + : BeRoFactoryInterface() , myHand(hi), myID(id), actualQuantityPlayers(aP), dealerPosition(dP), smallBlind(sB) {} diff --git a/src/engine/local_engine/localberofactory.h b/src/engine/local_engine/localberofactory.h index c71fd532..7785a005 100644 --- a/src/engine/local_engine/localberofactory.h +++ b/src/engine/local_engine/localberofactory.h @@ -23,7 +23,7 @@ class LocalBeRoFactory : public BeRoFactoryInterface { public: - LocalBeRoFactory(HandInterface* hi); + LocalBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB); ~LocalBeRoFactory(); @@ -33,6 +33,17 @@ private: HandInterface* myHand; + int myID; + int actualQuantityPlayers; + int dealerPosition; + int bigBlindPosition; + + int smallBlind; + int highestSet; + + bool preflopFirstRound; + int playersTurn; + }; #endif diff --git a/src/engine/local_engine/localberopreflop.cpp b/src/engine/local_engine/localberopreflop.cpp new file mode 100644 index 00000000..29727839 --- /dev/null +++ b/src/engine/local_engine/localberopreflop.cpp @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de *Irische Segenswnsche, + * * + * 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 "localberopreflop.h" + +#include +#include + +using namespace std; + +LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* bR, int id, int qP, int dP, int sB) : LocalBeRo(), myHand(bR), myID(id), actualQuantityPlayers(qP), dealerPosition(dP), bigBlindPosition(0), smallBlind(sB), highestSet(2*sB), preflopFirstRound(1), playersTurn(0) + +{ +// // BigBlind ermitteln + bigBlindPosition = dealerPosition; + while (myHand->getPlayerArray()[bigBlindPosition]->getMyButton() != 3) { + bigBlindPosition = (bigBlindPosition+1)%(MAX_NUMBER_OF_PLAYERS); + } + +// // erste Spielernummer fr preflopRun() setzen + playersTurn = bigBlindPosition; + + cout << "LocalBeroPreflop erstellt" << endl; +} + + + +LocalBeRoPreflop::~LocalBeRoPreflop() +{ + + + +} + +void LocalBeRoPreflop::preflopRun() { + + cout << "LocalBeroPreflopRun!!!" << endl; + +// cout << "NextPlayerSpeed2 stop" << endl; + int i; + bool allHighestSet = 1; + + // prfe, ob alle Sets gleich sind ( falls nicht, dann allHighestSet = 0 ) + for(i=0; igetPlayerArray()[i]->getMyActiveStatus() && myHand->getPlayerArray()[i]->getMyAction() != 1 && myHand->getPlayerArray()[i]->getMyAction() != 6) { + if(highestSet != myHand->getPlayerArray()[i]->getMySet()) { allHighestSet=0; } + } + } + + // BigBlind ermitteln + bigBlindPosition = dealerPosition; + while (myHand->getPlayerArray()[bigBlindPosition]->getMyButton() != 3) { + bigBlindPosition = (bigBlindPosition+1)%(MAX_NUMBER_OF_PLAYERS); + } + + // prfen, ob Preflop wirklich dran ist + if(!preflopFirstRound && allHighestSet) { + + // Preflop nicht dran, weil wir nicht mehr in erster PreflopRunde und alle Sets gleich sind + //also gehe in Flop + myHand->setActualRound(1); + + //Action loeschen und ActionButtons refresh + for(i=0; igetPlayerArray()[i]->getMyAction() != 1 && myHand->getPlayerArray()[i]->getMyAction() != 6) myHand->getPlayerArray()[i]->setMyAction(0); + } + //Sets in den Pot verschieben und Sets = 0 und Pot-refresh + myHand->getBoard()->collectSets(); + myHand->getBoard()->collectPot(); + myHand->getGuiInterface()->refreshPot(); + + myHand->getGuiInterface()->refreshSet(); + myHand->getGuiInterface()->refreshCash(); + for(i=0; igetGuiInterface()->refreshAction(i,0); } + + myHand->switchRounds(); + } + else { + // Preflop ist wirklich dran + + // naechsten Spieler ermitteln + do { + + playersTurn = (playersTurn+1)%(MAX_NUMBER_OF_PLAYERS); + // falls BigBlind, dann PreflopFirstRound zuende + if(myHand->getPlayerArray()[playersTurn]->getMyButton() == 3) preflopFirstRound = 0; + + } while(!(myHand->getPlayerArray()[playersTurn]->getMyActiveStatus()) || myHand->getPlayerArray()[playersTurn]->getMyAction() == 1 || myHand->getPlayerArray()[playersTurn]->getMyAction() == 6); + + myHand->getPlayerArray()[playersTurn]->setMyTurn(1); + //highlight active players groupbox and clear action + myHand->getGuiInterface()->refreshGroupbox(playersTurn,2); + myHand->getGuiInterface()->refreshAction(playersTurn,0); + + if(playersTurn == 0) { + // Wir sind dran + myHand->getGuiInterface()->meInAction(); + } + else { + //Gegner sind dran +// cout << "NextPlayerSpeed3 start" << endl; + myHand->getGuiInterface()->preflopAnimation2(); + } + } +} + +void LocalBeRoPreflop::nextPlayer2() { +// cout << "NextPlayerSpeed3 stop" << endl; + myHand->getPlayerArray()[playersTurn]->action(); + +} diff --git a/src/engine/local_engine/localberopreflop.h b/src/engine/local_engine/localberopreflop.h new file mode 100644 index 00000000..1bcda052 --- /dev/null +++ b/src/engine/local_engine/localberopreflop.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * 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 LOCALBEROPREFLOP_H +#define LOCALBEROPREFLOP_H + +#include +#include + +class HandInterface; + +class LocalBeRoPreflop : public LocalBeRo{ + +public: + LocalBeRoPreflop(HandInterface*, int, int, int, int); + ~LocalBeRoPreflop(); + + + void setPlayersTurn(int theValue) { playersTurn = theValue; } + int getPlayersTurn() const { return playersTurn; } + + void setHighestSet(int theValue) { highestSet = theValue; } + int getHighestSet() const { return highestSet;} + + void setPreflopFirstRound(bool theValue) { preflopFirstRound = theValue; } + bool setPreflopFirstRound() const { return preflopFirstRound; } + + void preflopRun(); + void nextPlayer2(); + + + +private: + HandInterface *myHand; + + int myID; + int actualQuantityPlayers; + int dealerPosition; + int bigBlindPosition; + + int smallBlind; + int highestSet; + + bool preflopFirstRound; + int playersTurn; + + +}; + +#endif diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index d9f202ee..13c0baff 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -26,7 +26,6 @@ #include "localflop.h" #include "localturn.h" #include "localriver.h" -#include "localbero.h" #include "localberofactory.h" #include @@ -57,7 +56,5 @@ TurnInterface* LocalEngineFactory::createTurn(HandInterface* hi, int id, int aP, RiverInterface* LocalEngineFactory::createRiver(HandInterface* hi, int id, int aP, int dP, int sB) { return new LocalRiver(hi, id, aP, dP, sB); } -// BeRoInterface* LocalEngineFactory::createBeRo() { return new LocalBeRo(); } - -BeRoFactoryInterface* LocalEngineFactory::createBeRoFactory(HandInterface* hi) { return new LocalBeRoFactory(hi); } +BeRoFactoryInterface* LocalEngineFactory::createBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB) { return new LocalBeRoFactory(hi, id, aP, dP, sB); } diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index fd23a939..e1ab7180 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -29,7 +29,6 @@ #include #include #include -// #include #include class ConfigFile; @@ -47,8 +46,7 @@ public: FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB); TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB); RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB); -// BeRoInterface* createBeRo(); - BeRoFactoryInterface* createBeRoFactory(HandInterface* hi); + BeRoFactoryInterface* createBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB); private: ConfigFile *myConfig; diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 756aa3c6..d6762bc2 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -172,7 +172,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI myTurn = myFactory->createTurn(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); myRiver = myFactory->createRiver(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); - myBeRoFactory = myFactory->createBeRoFactory(this); + myBeRoFactory = myFactory->createBeRoFactory(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); myBeRo = myBeRoFactory->switchRounds(); } diff --git a/src/engine/network_engine/clientberofactory.cpp b/src/engine/network_engine/clientberofactory.cpp index a8b6fac2..c14acabd 100644 --- a/src/engine/network_engine/clientberofactory.cpp +++ b/src/engine/network_engine/clientberofactory.cpp @@ -11,7 +11,7 @@ // #include "clientberofactory.h" -ClientBeRoFactory::ClientBeRoFactory(HandInterface* hi) +ClientBeRoFactory::ClientBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB) : BeRoFactoryInterface() { } diff --git a/src/engine/network_engine/clientberofactory.h b/src/engine/network_engine/clientberofactory.h index 427ca025..160ef1d1 100644 --- a/src/engine/network_engine/clientberofactory.h +++ b/src/engine/network_engine/clientberofactory.h @@ -21,7 +21,7 @@ class ClientBeRoFactory : public BeRoFactoryInterface { public: - ClientBeRoFactory(HandInterface* hi); + ClientBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB); ~ClientBeRoFactory(); diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index 500fce29..2551ffd2 100644 --- a/src/engine/network_engine/clientenginefactory.cpp +++ b/src/engine/network_engine/clientenginefactory.cpp @@ -25,7 +25,6 @@ #include "clientflop.h" #include "clientturn.h" #include "clientriver.h" -#include "clientbero.h" #include "clientberofactory.h" @@ -75,12 +74,7 @@ RiverInterface* ClientEngineFactory::createRiver(HandInterface* hi, int id, int return new ClientRiver(hi, id, aP, dP, sB); } -// BeRoInterface* ClientEngineFactory::createBeRo() -// { -// return new ClientBeRo(); -// } - -BeRoFactoryInterface* ClientEngineFactory::createBeRoFactory(HandInterface* hi) +BeRoFactoryInterface* ClientEngineFactory::createBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB) { - return new ClientBeRoFactory(hi); + return new ClientBeRoFactory(hi, id, aP, dP, sB); } diff --git a/src/engine/network_engine/clientenginefactory.h b/src/engine/network_engine/clientenginefactory.h index 70d1bfc3..41bff97c 100644 --- a/src/engine/network_engine/clientenginefactory.h +++ b/src/engine/network_engine/clientenginefactory.h @@ -28,7 +28,6 @@ #include #include #include -// #include #include @@ -47,8 +46,7 @@ public: FlopInterface* createFlop(HandInterface* hi, int id, int aP, int dP, int sB); TurnInterface* createTurn(HandInterface* hi, int id, int aP, int dP, int sB); RiverInterface* createRiver(HandInterface* hi, int id, int aP, int dP, int sB); -// BeRoInterface* createBeRo(); - BeRoFactoryInterface* createBeRoFactory(HandInterface* hi); + BeRoFactoryInterface* createBeRoFactory(HandInterface* hi, int id, int aP, int dP, int sB); };