2007-08-04 01:30:59 +00:00
//
// C++ Implementation: localbero
//
// Description:
//
//
// Author: FThauer FHammer <webmaster@pokerth.net>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "localbero.h"
2007-08-07 13:07:39 +00:00
using namespace std ;
2007-09-26 19:45:58 +00:00
LocalBeRo :: LocalBeRo ( HandInterface * hi , int id , unsigned dP , int sB , GameState gS )
: BeRoInterface (), myHand ( hi ), myBeRoID ( gS ), myID ( id ), dealerPosition ( dP ), smallBlindPosition ( 0 ), dealerPositionId ( dP ), smallBlindPositionId ( 0 ), bigBlindPositionId ( 0 ), smallBlind ( sB ), highestSet ( false ), minimumRaise ( 2 * sB ), firstRun ( true ), firstRound ( true ), firstHeadsUpRound ( true ), currentPlayersTurnId ( 0 ), firstRoundLastPlayersTurnId ( 0 ), logBoardCardsDone ( false )
2007-08-04 01:30:59 +00:00
{
2007-09-25 18:00:05 +00:00
currentPlayersTurnIt = myHand -> getRunningPlayerList () -> begin ();
lastPlayersTurnIt = myHand -> getRunningPlayerList () -> begin ();
2007-08-07 13:07:39 +00:00
2007-09-26 19:45:58 +00:00
PlayerListConstIterator it_c ;
// determine bigBlindPosition
for ( it_c = myHand -> getActivePlayerList () -> begin (); it_c != myHand -> getActivePlayerList () -> end (); it_c ++ ) {
if (( * it_c ) -> getMyButton () == BUTTON_BIG_BLIND ) {
bigBlindPositionId = ( * it_c ) -> getMyUniqueID ();
break ;
}
}
assert ( it_c != myHand -> getActivePlayerList () -> end ());
// determine smallBlindPosition
for ( it_c = myHand -> getActivePlayerList () -> begin (); it_c != myHand -> getActivePlayerList () -> end (); it_c ++ ) {
if (( * it_c ) -> getMyButton () == BUTTON_SMALL_BLIND ) {
smallBlindPositionId = ( * it_c ) -> getMyUniqueID ();
break ;
}
}
assert ( it_c != myHand -> getActivePlayerList () -> end ());
2007-09-25 21:46:38 +00:00
// int i;
2007-08-07 13:07:39 +00:00
//SmallBlind-Position ermitteln
2007-09-25 21:46:38 +00:00
// for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
// if (myHand->getPlayerArray()[i]->getMyButton() == 2) smallBlindPosition = i;
// }
2007-08-07 13:07:39 +00:00
}
2007-08-04 01:30:59 +00:00
LocalBeRo ::~ LocalBeRo ()
{
}
2007-08-07 13:07:39 +00:00
void LocalBeRo :: nextPlayer () {
2007-09-25 18:00:05 +00:00
// myHand->getPlayerArray()[playersTurn]->action();
2007-09-26 10:13:10 +00:00
// cout << "playerID in nextPlayer(): " << (*currentPlayersTurnIt)->getMyID() << endl;
2007-09-25 18:00:05 +00:00
2007-09-26 19:45:58 +00:00
PlayerListConstIterator currentPlayersTurnConstIt = myHand -> getRunningPlayerIt ( currentPlayersTurnId );
assert ( currentPlayersTurnConstIt != myHand -> getRunningPlayerList () -> end () );
( * currentPlayersTurnConstIt ) -> action ();
2007-08-07 13:07:39 +00:00
}
2007-08-07 00:05:29 +00:00
void LocalBeRo :: run () {
int i ;
2007-09-25 21:46:38 +00:00
PlayerListIterator it ;
2007-08-07 00:05:29 +00:00
if ( firstRun ) {
2007-09-26 20:11:49 +00:00
/*
// PlayerListIterator it;
// search bigBlindPosition in runningPlayerList -> old: delete
// it_1 = find(getMyHand()->getRunningPlayerList()->begin(), getMyHand()->getRunningPlayerList()->end(), *bigBlindPositionIt);
// search bigBlindPosition in runningPlayerList
// PlayerListIterator bigBlindPositionIt = getMyHand()->getRunningPlayerIt(getBigBlindPositionId());
// more than 2 players are still active -> runningPlayerList is not empty
if(getMyHand()->getActivePlayerList()->size() > 2) {
// bigBlindPlayer not found in runningPlayerList (he is all in) -> bigBlindPlayer is not the running player before first action player
if(bigBlindPositionIt == getMyHand()->getRunningPlayerList()->end()) {
// search smallBlindPosition in runningPlayerList
PlayerListIterator smallBlindPositionIt = getMyHand()->getRunningPlayerIt(getSmallBlindPositionId());
// if(smallBlindPositionIt == getMyHand()->getActivePlayerList()->begin()) smallBlindPositionIt = getMyHand()->getActivePlayerList()->end();
// smallBlindPositionIt--;
// it_2 = find(getMyHand()->getRunningPlayerList()->begin(), getMyHand()->getRunningPlayerList()->end(), *smallBlindPositionIt);
// smallBlindPlayer not found in runningPlayerList (he is all in) -> next active player before smallBlindPlayer is running player before first action player
if(smallBlindPositionIt == getMyHand()->getRunningPlayerList()->end()) {
it = getMyHand()->getActivePlayerIt(getSmallBlindPositionId());
assert(it != getMyHand()->getActivePlayerList()->end());
if(it == getMyHand()->getActivePlayerList()->begin()) it = getMyHand()->getActivePlayerList()->end();
it--;
setFirstRoundLastPlayersTurnId( (*it)->getMyUniqueID() );
// it_3 = find(getMyHand()->getRunningPlayerList()->begin(), getMyHand()->getRunningPlayerList()->end(), *it_2);
// if(it_3 == getMyHand()->getRunningPlayerList()->end()) {
// cout << "ERROR - lastPlayersTurnIt-detection in localBeRoPreflop" << endl;
// } else {
// setLastPlayersTurnIt(it_3);
// }
}
// smallBlindPlayer found in runningPlayerList -> running player before first action player
else {
setFirstRoundLastPlayersTurnId( getSmallBlindPositionId() );
}
}
// bigBlindPlayer found in runningPlayerList -> player before first action player
else {
setFirstRoundLastPlayersTurnId( getBigBlindPositionId() );
}
}
// heads up -> dealer/smallBlindPlayer is first action player and bigBlindPlayer is player before
else {
// bigBlindPlayer not found in runningPlayerList (he is all in) -> only smallBlind has to choose fold or call the bigBlindAmount
if(bigBlindPositionIt == getMyHand()->getRunningPlayerList()->end()) {
// search smallBlindPosition in runningPlayerList
PlayerListIterator smallBlindPositionIt = getMyHand()->getRunningPlayerIt(getSmallBlindPositionId());
// smallBlindPlayer not found in runningPlayerList (he is all in) -> no running player -> showdown and no firstRoundLastPlayersTurnId is used
if(smallBlindPositionIt == getMyHand()->getRunningPlayerList()->end()) {
}
// smallBlindPlayer found in runningPlayerList -> running player before first action player (himself)
else {
setFirstRoundLastPlayersTurnId( getSmallBlindPositionId() );
}
}
setFirstRoundLastPlayersTurnId( getBigBlindPositionId() );
}
setCurrentPlayersTurnId( getFirstRoundLastPlayersTurnId() );
2007-08-07 00:05:29 +00:00
2007-09-25 21:46:38 +00:00
// determine smallBlindPosition
PlayerListIterator smallBlindPositionIt;
for(smallBlindPositionIt=myHand->getActivePlayerList()->begin(); smallBlindPositionIt!=myHand->getActivePlayerList()->end(); smallBlindPositionIt++) {
if((*smallBlindPositionIt)->getMyButton() == BUTTON_SMALL_BLIND) break;
}
// determine running player before smallBlind (for heads up: determine dealer/smallblind)
PlayerListIterator it_1, it_2;
size_t i;
// running player before smallBlind
if(myHand->getActivePlayerList()->size() > 2) {
it_1 = smallBlindPositionIt;
for(i=0; i<myHand->getActivePlayerList()->size(); i++) {
if(it_1 == myHand->getActivePlayerList()->begin()) it_1 = myHand->getActivePlayerList()->end();
it_1--;
it_2 = find(myHand->getRunningPlayerList()->begin(), myHand->getRunningPlayerList()->end(), *it_1);
// running player found
if(it_2 != myHand->getRunningPlayerList()->end()) {
lastPlayersTurnIt = it_2;
break;
}
}
}
// heads up: bigBlind begins -> dealer/smallBlind is running player before bigBlind
else {
it_1 = find(myHand->getRunningPlayerList()->begin(), myHand->getRunningPlayerList()->end(), *smallBlindPositionIt);
if( it_1 == myHand->getRunningPlayerList()->end() ) {
cout << "ERROR - lastPlayersTurnIt-detection in localBeRo" << endl;
}
// smallBlind found
else {
lastPlayersTurnIt = it_1;
}
}
currentPlayersTurnIt = lastPlayersTurnIt;
2007-09-26 20:11:49 +00:00
*/
// determine smallBlindPosition
// PlayerListIterator smallBlindPositionIt;
// for(smallBlindPositionIt=myHand->getActivePlayerList()->begin(); smallBlindPositionIt!=myHand->getActivePlayerList()->end(); smallBlindPositionIt++) {
// if((*smallBlindPositionIt)->getMyButton() == BUTTON_SMALL_BLIND) break;
// }
// determine running player before smallBlind (for heads up: determine dealer/smallblind)
PlayerListIterator it_1 , it_2 ;
size_t i ;
// running player before smallBlind
if ( myHand -> getActivePlayerList () -> size () > 2 ) {
it_1 = myHand -> getActivePlayerIt ( smallBlindPositionId );
assert ( it_1 != myHand -> getActivePlayerList () -> end () );
for ( i = 0 ; i < myHand -> getActivePlayerList () -> size (); i ++ ) {
if ( it_1 == myHand -> getActivePlayerList () -> begin ()) it_1 = myHand -> getActivePlayerList () -> end ();
it_1 -- ;
it_2 = find ( myHand -> getRunningPlayerList () -> begin (), myHand -> getRunningPlayerList () -> end (), * it_1 );
// running player found
if ( it_2 != myHand -> getRunningPlayerList () -> end ()) {
lastPlayersTurnIt = it_2 ;
break ;
}
}
}
// heads up: bigBlind begins -> dealer/smallBlind is running player before bigBlind
else {
//TODO
// it_1 = find(myHand->getRunningPlayerList()->begin(), myHand->getRunningPlayerList()->end(), *smallBlindPositionIt);
if ( it_1 == myHand -> getRunningPlayerList () -> end () ) {
cout << "ERROR - lastPlayersTurnIt-detection in localBeRo" << endl ;
}
// smallBlind found
else {
lastPlayersTurnIt = it_1 ;
}
}
currentPlayersTurnIt = lastPlayersTurnIt ;
2007-08-07 00:05:29 +00:00
myHand -> getGuiInterface () -> dealBeRoCards ( myBeRoID );
2007-09-25 21:46:38 +00:00
firstRun = false ;
2007-08-07 00:05:29 +00:00
}
else {
//log the turned cards
if ( ! logBoardCardsDone ) {
int tempBoardCardsArray [ 5 ];
myHand -> getBoard () -> getMyCards ( tempBoardCardsArray );
2007-08-29 17:57:17 +00:00
switch ( myBeRoID ) {
case GAME_STATE_FLOP : myHand -> getGuiInterface () -> logDealBoardCardsMsg ( myBeRoID , tempBoardCardsArray [ 0 ], tempBoardCardsArray [ 1 ], tempBoardCardsArray [ 2 ]);
break ;
case GAME_STATE_TURN : myHand -> getGuiInterface () -> logDealBoardCardsMsg ( myBeRoID , tempBoardCardsArray [ 0 ], tempBoardCardsArray [ 1 ], tempBoardCardsArray [ 2 ], tempBoardCardsArray [ 3 ]);
break ;
case GAME_STATE_RIVER : myHand -> getGuiInterface () -> logDealBoardCardsMsg ( myBeRoID , tempBoardCardsArray [ 0 ], tempBoardCardsArray [ 1 ], tempBoardCardsArray [ 2 ], tempBoardCardsArray [ 3 ], tempBoardCardsArray [ 4 ]);
break ;
2007-08-31 13:09:07 +00:00
default : { cout << "ERROR in localbero.cpp - wrong myBeRoID" << endl ;}
2007-08-29 17:57:17 +00:00
}
2007-09-25 21:46:38 +00:00
logBoardCardsDone = true ;
2007-08-07 00:05:29 +00:00
}
2007-09-25 21:46:38 +00:00
bool allHighestSet = true ;
2007-08-07 00:05:29 +00:00
// prfe, ob alle Sets gleich sind ( falls nicht, dann allHighestSet = 0 )
2007-09-25 21:46:38 +00:00
// for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
// if(myHand->getPlayerArray()[i]->getMyActiveStatus() && myHand->getPlayerArray()[i]->getMyAction() != 1 && myHand->getPlayerArray()[i]->getMyAction() != 6) {
// if(highestSet != myHand->getPlayerArray()[i]->getMySet()) { allHighestSet=0; }
// }
// }
// test if all running players have same sets (else allHighestSet = false)
for ( it = myHand -> getRunningPlayerList () -> begin (); it != myHand -> getRunningPlayerList () -> end (); it ++ ) {
if ( highestSet != ( * it ) -> getMySet ()) {
allHighestSet = false ;
2007-08-07 00:05:29 +00:00
}
}
2007-09-25 21:46:38 +00:00
// prfen, ob aktuelle bero wirklich dran ist
2007-08-07 00:05:29 +00:00
if ( ! firstRound && allHighestSet ) {
2007-09-25 21:46:38 +00:00
// aktuelle bero nicht dran, weil alle Sets gleich sind
//also gehe in naechste bero
2007-08-07 00:05:29 +00:00
myHand -> setActualRound ( myBeRoID + 1 );
//Action loeschen und ActionButtons refresh
2007-09-25 21:46:38 +00:00
// for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
// if(myHand->getPlayerArray()[i]->getMyAction() != 1 && myHand->getPlayerArray()[i]->getMyAction() != 6) myHand->getPlayerArray()[i]->setMyAction(0);
// }
//Action loeschen und ActionButtons refresh
for ( it = myHand -> getRunningPlayerList () -> begin (); it != myHand -> getRunningPlayerList () -> end (); it ++ ) {
( * it ) -> setMyAction ( PLAYER_ACTION_NONE );
2007-08-07 00:05:29 +00:00
}
2007-09-25 21:46:38 +00:00
2007-08-07 00:05:29 +00:00
//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 ();
2007-09-25 21:46:38 +00:00
for ( i = 0 ; i < MAX_NUMBER_OF_PLAYERS ; i ++ ) { myHand -> getGuiInterface () -> refreshAction ( i , PLAYER_ACTION_NONE ); }
2007-08-07 00:05:29 +00:00
myHand -> switchRounds ();
}
else {
2007-09-25 21:46:38 +00:00
// aktuelle bero ist wirklich dran
2007-08-07 00:05:29 +00:00
// Anzahl der effektiv gespielten Runden (des human player) erhöhen
if ( myHand -> getPlayerArray ()[ 0 ] -> getMyActiveStatus () && myHand -> getPlayerArray ()[ 0 ] -> getMyAction () != 1 ) {
myHand -> setBettingRoundsPlayed ( myBeRoID );
}
2007-09-02 15:38:08 +00:00
//// !!!!!!!!!!!!!!!!1!!!! very buggy, rule breaking -> TODO !!!!!!!!!!!!11!!!!!!!! //////////////
2007-08-31 13:09:07 +00:00
2007-09-02 15:38:08 +00:00
//// headsup:
//// preflop: dealer is small blind and begins
//// flop, trun, river: big blind begins
//// !!!!!!!!! attention: exception if player failed before !!!!!!!!
// if( !(myHand->getActualQuantityPlayers() < 3 && firstHeadsUpRound == 1) || myHand->getPlayerArray()[playersTurn]->getMyActiveStatus() == 0 ) {
2007-08-07 00:05:29 +00:00
// not first round in heads up (for headsup dealer is smallblind so it is dealers turn)
// naechsten Spieler ermitteln
2007-09-25 21:46:38 +00:00
// int i;
// for(i=0; (i<MAX_NUMBER_OF_PLAYERS && ((myHand->getPlayerArray()[playersTurn]->getMyActiveStatus()) == 0 || (myHand->getPlayerArray()[playersTurn]->getMyAction())==1 || (myHand->getPlayerArray()[playersTurn]->getMyAction())==6)) || i==0; i++) {
// playersTurn = (playersTurn+1)%(MAX_NUMBER_OF_PLAYERS);
// }
// firstHeadsUpRound = 0;
// determine next running player
currentPlayersTurnIt ++ ;
if ( currentPlayersTurnIt == myHand -> getRunningPlayerList () -> end ()) currentPlayersTurnIt = myHand -> getRunningPlayerList () -> begin ();
2007-09-02 15:38:08 +00:00
// }
// else { firstHeadsUpRound = 0; }
2007-08-07 00:05:29 +00:00
2007-09-02 15:38:08 +00:00
////// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ////////////////
2007-08-31 13:09:07 +00:00
2007-08-07 00:05:29 +00:00
//Spieler-Position vor SmallBlind-Position ermitteln
2007-09-25 21:46:38 +00:00
// int activePlayerBeforeSmallBlind = smallBlindPosition;
2007-08-08 12:54:20 +00:00
2007-09-25 21:46:38 +00:00
// for(i=0; (i<MAX_NUMBER_OF_PLAYERS && !(myHand->getPlayerArray()[activePlayerBeforeSmallBlind]->getMyActiveStatus()) || (myHand->getPlayerArray()[activePlayerBeforeSmallBlind]->getMyAction())==1 || (myHand->getPlayerArray()[activePlayerBeforeSmallBlind]->getMyAction())==6) || i==0; i++) {
// activePlayerBeforeSmallBlind = (activePlayerBeforeSmallBlind + MAX_NUMBER_OF_PLAYERS - 1 ) % (MAX_NUMBER_OF_PLAYERS);
// }
// myHand->getPlayerArray()[playersTurn]->setMyTurn(1);
( * currentPlayersTurnIt ) -> setMyTurn ( true );
2007-08-08 12:54:20 +00:00
2007-08-07 00:05:29 +00:00
//highlight active players groupbox and clear action
2007-09-25 21:46:38 +00:00
myHand -> getGuiInterface () -> refreshGroupbox (( * currentPlayersTurnIt ) -> getMyID (), 2 );
myHand -> getGuiInterface () -> refreshAction (( * currentPlayersTurnIt ) -> getMyID (), 0 );
2007-08-07 00:05:29 +00:00
// wenn wir letzter aktiver Spieler vor SmallBlind sind, dann flopFirstRound zuende
2007-09-01 16:32:36 +00:00
// ausnahme bei heads up !!! --> TODO
2007-09-25 21:46:38 +00:00
// if(myHand->getPlayerArray()[playersTurn]->getMyID() == activePlayerBeforeSmallBlind && myHand->getActivePlayerList()->size() >= 3) { firstRound = 0; }
// if(myHand->getActivePlayerList()->size() < 3 && (myHand->getPlayerArray()[playersTurn]->getMyID() == dealerPosition || myHand->getPlayerArray()[playersTurn]->getMyID() == smallBlindPosition)) { firstRound = 0; }
2007-08-07 00:05:29 +00:00
2007-09-25 21:46:38 +00:00
if ( ( * currentPlayersTurnIt ) == ( * lastPlayersTurnIt ) ) {
firstRound = false ;
}
if (( * currentPlayersTurnIt ) -> getMyID () == 0 ) {
2007-08-07 00:05:29 +00:00
// Wir sind dran
myHand -> getGuiInterface () -> meInAction ();
}
else {
//Gegner sind dran
2007-08-07 13:07:39 +00:00
myHand -> getGuiInterface () -> beRoAnimation2 ( myBeRoID );
2007-08-07 00:05:29 +00:00
}
}
}
}
2007-08-04 01:30:59 +00:00