2007-08-04 22:05:12 +00:00
/***************************************************************************
* 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"
2007-10-14 11:01:44 +00:00
#include "localexception.h"
#include "engine_msg.h"
2007-08-04 22:05:12 +00:00
#include <handinterface.h>
#include <game_defs.h>
using namespace std ;
2007-09-26 19:45:58 +00:00
LocalBeRoPreflop :: LocalBeRoPreflop ( HandInterface * hi , int id , unsigned dP , int sB ) : LocalBeRo ( hi , id , dP , sB , GAME_STATE_PREFLOP )
2007-08-04 22:05:12 +00:00
{
2007-08-07 23:59:34 +00:00
setHighestSet ( 2 * getSmallBlind ());
2007-09-29 13:22:00 +00:00
}
LocalBeRoPreflop ::~ LocalBeRoPreflop ()
{
}
void LocalBeRoPreflop :: run () {
if ( getFirstRun ()) {
2007-10-19 14:03:12 +00:00
PlayerListIterator it ;
// 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 ());
// 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 ());
if ( it == getMyHand () -> getActivePlayerList () -> end ()) {
throw LocalException ( __FILE__ , __LINE__ , ERR_ACTIVE_PLAYER_NOT_FOUND );
}
if ( it == getMyHand () -> getActivePlayerList () -> begin ()) it = getMyHand () -> getActivePlayerList () -> end ();
it -- ;
setFirstRoundLastPlayersTurnId ( ( * it ) -> getMyUniqueID () );
}
// smallBlindPlayer found in runningPlayerList -> running player before first action player
else {
setFirstRoundLastPlayersTurnId ( getSmallBlindPositionId () );
2007-10-14 11:01:44 +00:00
}
2007-09-25 18:00:05 +00:00
}
2007-10-19 14:03:12 +00:00
// bigBlindPlayer found in runningPlayerList -> player before first action player
2007-09-25 18:00:05 +00:00
else {
2007-10-19 14:03:12 +00:00
setFirstRoundLastPlayersTurnId ( getBigBlindPositionId () );
2007-09-25 18:00:05 +00:00
}
}
2007-10-19 14:03:12 +00:00
// heads up -> dealer/smallBlindPlayer is first action player and bigBlindPlayer is player before
2007-09-25 18:00:05 +00:00
else {
2007-10-19 14:03:12 +00:00
// 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 () );
}
} else {
setFirstRoundLastPlayersTurnId ( getBigBlindPositionId () );
2007-09-26 19:45:58 +00:00
}
}
2007-10-19 14:03:12 +00:00
setCurrentPlayersTurnId ( getFirstRoundLastPlayersTurnId () );
2007-09-29 13:22:00 +00:00
setFirstRun ( false );
2007-10-19 14:03:12 +00:00
2007-09-29 13:22:00 +00:00
}
2007-08-04 22:05:12 +00:00
int i ;
2007-09-25 09:07:36 +00:00
bool allHighestSet = true ;
2007-09-26 19:45:58 +00:00
PlayerListConstIterator it_c ;
2007-08-04 22:05:12 +00:00
2007-10-19 14:03:12 +00:00
// check if all running players have same sets (else allHighestSet = false)
2007-09-26 19:45:58 +00:00
for ( it_c = getMyHand () -> getRunningPlayerList () -> begin (); it_c != getMyHand () -> getRunningPlayerList () -> end (); it_c ++ ) {
if ( getHighestSet () != ( * it_c ) -> getMySet ()) {
2007-09-25 09:07:36 +00:00
allHighestSet = false ;
2007-09-26 22:27:05 +00:00
break ;
2007-08-04 22:05:12 +00:00
}
}
2007-09-25 09:07:36 +00:00
// determine next player
2007-09-26 22:27:05 +00:00
PlayerListConstIterator currentPlayersTurnIt = getMyHand () -> getRunningPlayerIt ( getCurrentPlayersTurnId () );
2007-10-14 11:01:44 +00:00
if ( currentPlayersTurnIt == getMyHand () -> getRunningPlayerList () -> end ()) {
2007-10-18 20:36:49 +00:00
throw LocalException ( __FILE__ , __LINE__ , ERR_RUNNING_PLAYER_NOT_FOUND );
2007-10-14 11:01:44 +00:00
}
2007-09-25 18:00:05 +00:00
2007-09-26 19:45:58 +00:00
currentPlayersTurnIt ++ ;
if ( currentPlayersTurnIt == getMyHand () -> getRunningPlayerList () -> end ()) currentPlayersTurnIt = getMyHand () -> getRunningPlayerList () -> begin ();
2007-09-25 18:00:05 +00:00
2007-09-26 19:45:58 +00:00
setCurrentPlayersTurnId ( ( * currentPlayersTurnIt ) -> getMyUniqueID () );
2007-09-29 13:22:00 +00:00
2007-08-04 22:05:12 +00:00
// prfen, ob Preflop wirklich dran ist
2007-08-07 23:59:34 +00:00
if ( ! getFirstRound () && allHighestSet ) {
2007-08-04 22:05:12 +00:00
// Preflop nicht dran, weil wir nicht mehr in erster PreflopRunde und alle Sets gleich sind
//also gehe in Flop
2007-10-18 17:40:12 +00:00
getMyHand () -> setCurrentRound ( GAME_STATE_FLOP );
2007-09-28 00:16:11 +00:00
2007-08-04 22:05:12 +00:00
//Action loeschen und ActionButtons refresh
2007-09-26 19:45:58 +00:00
for ( it_c = getMyHand () -> getRunningPlayerList () -> begin (); it_c != getMyHand () -> getRunningPlayerList () -> end (); it_c ++ ) {
( * it_c ) -> setMyAction ( PLAYER_ACTION_NONE );
2007-08-04 22:05:12 +00:00
}
2007-09-25 18:00:05 +00:00
2007-08-04 22:05:12 +00:00
//Sets in den Pot verschieben und Sets = 0 und Pot-refresh
2007-08-07 23:59:34 +00:00
getMyHand () -> getBoard () -> collectSets ();
getMyHand () -> getBoard () -> collectPot ();
getMyHand () -> getGuiInterface () -> refreshPot ();
2007-08-04 22:05:12 +00:00
2007-08-07 23:59:34 +00:00
getMyHand () -> getGuiInterface () -> refreshSet ();
getMyHand () -> getGuiInterface () -> refreshCash ();
for ( i = 0 ; i < MAX_NUMBER_OF_PLAYERS ; i ++ ) { getMyHand () -> getGuiInterface () -> refreshAction ( i , PLAYER_ACTION_NONE ); }
2007-08-04 22:05:12 +00:00
2007-08-07 23:59:34 +00:00
getMyHand () -> switchRounds ();
2007-08-04 22:05:12 +00:00
}
else {
2007-09-26 19:45:58 +00:00
// lastPlayersTurn -> PreflopFirstRound is over
if ( getCurrentPlayersTurnId () == getFirstRoundLastPlayersTurnId () ) {
2007-09-25 18:00:05 +00:00
setFirstRound ( false );
}
2007-10-14 11:01:44 +00:00
currentPlayersTurnIt = getMyHand () -> getRunningPlayerIt ( getCurrentPlayersTurnId () );
if ( currentPlayersTurnIt == getMyHand () -> getRunningPlayerList () -> end ()) {
2007-10-18 20:36:49 +00:00
throw LocalException ( __FILE__ , __LINE__ , ERR_RUNNING_PLAYER_NOT_FOUND );
2007-10-14 11:01:44 +00:00
}
( * currentPlayersTurnIt ) -> setMyTurn ( true );
2007-09-26 19:45:58 +00:00
2007-09-25 18:00:05 +00:00
//highlight active players groupbox and clear action
2007-09-26 19:45:58 +00:00
getMyHand () -> getGuiInterface () -> refreshGroupbox ( getCurrentPlayersTurnId () , 2 );
getMyHand () -> getGuiInterface () -> refreshAction ( getCurrentPlayersTurnId () , PLAYER_ACTION_NONE );
2007-09-25 18:00:05 +00:00
2007-09-26 19:45:58 +00:00
if ( getCurrentPlayersTurnId () == 0 ) {
2007-08-04 22:05:12 +00:00
// Wir sind dran
2007-08-07 23:59:34 +00:00
getMyHand () -> getGuiInterface () -> meInAction ();
2007-08-04 22:05:12 +00:00
}
else {
//Gegner sind dran
2007-08-07 23:59:34 +00:00
getMyHand () -> getGuiInterface () -> beRoAnimation2 ( getMyBeRoID ());
2007-08-04 22:05:12 +00:00
}
}
}