2011-07-03 22:27:36 +00:00
/*****************************************************************************
* PokerTH - The open source texas holdem engine *
* Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
2007-01-13 02:40:33 +00:00
#include "localhand.h"
2007-05-15 20:37:37 +00:00
#include "tools.h"
#include "cardsvalue.h"
2007-04-17 07:28:32 +00:00
#include <game_defs.h>
2007-10-23 21:26:07 +00:00
#include <core/loghelper.h>
2007-01-13 02:40:33 +00:00
2007-10-14 11:01:44 +00:00
#include "localexception.h"
#include "engine_msg.h"
2007-06-07 19:37:35 +00:00
#include <iostream>
2007-01-13 02:40:33 +00:00
using namespace std ;
2011-01-09 14:16:20 +00:00
LocalHand :: LocalHand ( boost :: shared_ptr < EngineFactory > f , GuiInterface * g , boost :: shared_ptr < BoardInterface > b , Log * l , PlayerList sl , PlayerList apl , PlayerList rpl , int id , int sP , unsigned dP , int sB , int sC )
2011-11-13 16:00:19 +00:00
: myFactory ( f ), myGui ( g ), myBoard ( b ), myLog ( l ), seatsList ( sl ), activePlayerList ( apl ), runningPlayerList ( rpl ), myBeRo ( 0 ), myID ( id ), startQuantityPlayers ( sP ), dealerPosition ( dP ), smallBlindPosition ( dP ), bigBlindPosition ( dP ), currentRound ( GAME_STATE_PREFLOP ), roundBeforePostRiver ( GAME_STATE_PREFLOP ), smallBlind ( sB ), startCash ( sC ), previousPlayerID ( - 1 ), lastActionPlayerID ( 0 ), allInCondition ( false ),
cardsShown ( false )
2007-01-13 02:40:33 +00:00
{
2007-01-28 00:17:49 +00:00
2007-03-05 23:25:34 +00:00
int i , j , k ;
2007-09-27 00:37:01 +00:00
PlayerListIterator it ;
2007-03-29 22:58:04 +00:00
2011-02-09 14:33:39 +00:00
for ( it = seatsList -> begin (); it != seatsList -> end (); ++ it ) {
2007-09-27 00:37:01 +00:00
( * it ) -> setHand ( this );
2007-10-19 14:03:12 +00:00
// set myFlipCards 0
2007-09-27 00:37:01 +00:00
( * it ) -> setMyCardsFlip ( 0 , 0 );
2007-03-05 23:25:34 +00:00
}
2007-01-13 02:40:33 +00:00
2007-10-19 14:03:12 +00:00
// generate cards and assign to board and player
2011-10-11 15:15:22 +00:00
const int NumCards = 52 ;
int cardsArray [ NumCards ] = {
2011-10-26 22:29:47 +00:00
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,
2011-10-11 15:15:22 +00:00
10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 18 , 19 ,
20 , 21 , 22 , 23 , 24 , 25 , 26 , 27 , 28 , 29 ,
30 , 31 , 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 ,
40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 ,
50 , 51
};
Tools :: ShuffleArrayNonDeterministic ( cardsArray , NumCards );
2007-01-13 02:40:33 +00:00
int tempBoardArray [ 5 ];
int tempPlayerArray [ 2 ];
int tempPlayerAndBoardArray [ 7 ];
2007-09-24 10:02:17 +00:00
int bestHandPos [ 5 ];
2007-03-30 12:44:16 +00:00
int sBluff ;
2007-01-13 02:40:33 +00:00
for ( i = 0 ; i < 5 ; i ++ ) {
tempBoardArray [ i ] = cardsArray [ i ];
tempPlayerAndBoardArray [ i + 2 ] = cardsArray [ i ];
}
2007-04-03 10:55:16 +00:00
2007-03-05 23:25:34 +00:00
k = 0 ;
2007-01-13 02:40:33 +00:00
myBoard -> setMyCards ( tempBoardArray );
2011-02-09 14:33:39 +00:00
for ( it = activePlayerList -> begin (); it != activePlayerList -> end (); ++ it , k ++ ) {
2007-06-11 17:48:22 +00:00
2007-09-27 14:17:07 +00:00
( * it ) -> getMyBestHandPosition ( bestHandPos );
2007-06-11 17:48:22 +00:00
2007-09-24 10:02:17 +00:00
for ( j = 0 ; j < 2 ; j ++ ) {
tempPlayerArray [ j ] = cardsArray [ 2 * k + j + 5 ];
tempPlayerAndBoardArray [ j ] = cardsArray [ 2 * k + j + 5 ];
}
2007-09-27 14:17:07 +00:00
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , bestHandPos ));
2007-09-27 14:17:07 +00:00
( * it ) -> setMyBestHandPosition ( bestHandPos );
( * it ) -> setMyRoundStartCash (( * it ) -> getMyCash ());
2007-09-24 10:02:17 +00:00
2007-10-19 14:03:12 +00:00
// error-check
2007-09-24 10:02:17 +00:00
for ( j = 0 ; j < 5 ; j ++ ) {
if ( bestHandPos [ j ] == - 1 ) {
2007-10-23 21:26:07 +00:00
LOG_ERROR ( __FILE__ << " (" << __LINE__ << "): ERROR getMyBestHandPosition" );
2007-01-28 00:17:49 +00:00
}
2007-09-24 10:02:17 +00:00
}
2007-03-30 12:44:16 +00:00
2007-10-19 14:03:12 +00:00
// set sBluff for all players --> TODO for ai-player in internet
2007-09-27 14:17:07 +00:00
if (( * it ) -> getMyID () != 0 ) {
2011-10-11 15:15:22 +00:00
Tools :: GetRand ( 1 , 100 , 1 , & sBluff );
2007-09-27 14:17:07 +00:00
( * it ) -> setSBluff ( sBluff );
( * it ) -> setSBluffStatus ( 0 );
2007-01-28 00:17:49 +00:00
}
2007-01-13 02:40:33 +00:00
}
2007-09-24 10:02:17 +00:00
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!! DEBUGGER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
2007-04-30 11:53:40 +00:00
2011-02-11 20:02:08 +00:00
if ( DEBUG_MODE ) {
2007-08-24 15:15:01 +00:00
2011-02-11 20:02:08 +00:00
//QSqlDatabase *mySqliteLogDb;
2010-05-29 14:05:41 +00:00
2011-02-11 20:02:08 +00:00
// myGui->getMyW()->getSession();
2010-05-29 14:05:41 +00:00
2011-02-11 20:02:08 +00:00
//QSqlDatabase * test = myGui->getMyLog()->getMySqliteLogDb();
2010-05-29 14:05:41 +00:00
2011-02-11 20:02:08 +00:00
// if(!mySqliteLogDb->open()) {
2012-05-17 01:35:59 +02:00
// MyMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().c_str(), QMessageBox::Cancel);
2011-02-11 20:02:08 +00:00
// }
2010-05-29 14:05:41 +00:00
2007-09-27 20:36:02 +00:00
int temp5Array [ 5 ];
2007-09-01 16:32:36 +00:00
switch ( myID ) {
2011-02-11 20:02:08 +00:00
case 1 : {
2007-09-27 20:36:02 +00:00
2011-02-11 20:02:08 +00:00
tempBoardArray [ 0 ] = 4 ;
tempBoardArray [ 1 ] = 19 ;
tempBoardArray [ 2 ] = 20 ;
tempBoardArray [ 3 ] = 43 ;
tempBoardArray [ 4 ] = 49 ;
2007-09-28 15:04:52 +00:00
2011-02-11 20:02:08 +00:00
myBoard -> setMyCards ( tempBoardArray );
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
tempPlayerAndBoardArray [ 2 ] = tempBoardArray [ 0 ];
tempPlayerAndBoardArray [ 3 ] = tempBoardArray [ 1 ];
tempPlayerAndBoardArray [ 4 ] = tempBoardArray [ 2 ];
tempPlayerAndBoardArray [ 5 ] = tempBoardArray [ 3 ];
tempPlayerAndBoardArray [ 6 ] = tempBoardArray [ 4 ];
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
// player0
it = seatsList -> begin ();
2007-09-23 17:07:52 +00:00
2011-02-11 20:02:08 +00:00
tempPlayerArray [ 0 ] = 18 ;
tempPlayerArray [ 1 ] = 17 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
2007-09-28 15:04:52 +00:00
2011-02-11 20:02:08 +00:00
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
// player1
++ it ;
2007-09-28 15:04:52 +00:00
2011-02-11 20:02:08 +00:00
tempPlayerArray [ 0 ] = 31 ;
tempPlayerArray [ 1 ] = 8 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
2007-09-29 17:08:05 +00:00
2011-02-11 20:02:08 +00:00
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
2010-07-22 06:03:11 +00:00
2011-02-11 20:02:08 +00:00
// player2
++ it ;
2010-07-22 06:03:11 +00:00
2011-02-11 20:02:08 +00:00
tempPlayerArray [ 0 ] = 26 ;
tempPlayerArray [ 1 ] = 27 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
2010-07-22 06:03:11 +00:00
2011-02-11 20:02:08 +00:00
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2010-07-22 06:03:11 +00:00
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
// player3
++ it ;
2010-01-02 18:10:36 +00:00
2011-02-11 20:02:08 +00:00
tempPlayerArray [ 0 ] = 31 ;
tempPlayerArray [ 1 ] = 30 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
// player4
++ it ;
tempPlayerArray [ 0 ] = 50 ;
tempPlayerArray [ 1 ] = 51 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
// player5
++ it ;
tempPlayerArray [ 0 ] = 25 ;
tempPlayerArray [ 1 ] = 24 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
// player6
++ it ;
tempPlayerArray [ 0 ] = 38 ;
tempPlayerArray [ 1 ] = 37 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
// player7
++ it ;
tempPlayerArray [ 0 ] = 32 ;
tempPlayerArray [ 1 ] = 33 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
// player8
++ it ;
tempPlayerArray [ 0 ] = 19 ;
tempPlayerArray [ 1 ] = 20 ;
tempPlayerAndBoardArray [ 0 ] = tempPlayerArray [ 0 ];
tempPlayerAndBoardArray [ 1 ] = tempPlayerArray [ 1 ];
( * it ) -> setMyCards ( tempPlayerArray );
2011-03-06 15:22:13 +00:00
( * it ) -> setMyCardsValueInt ( CardsValue :: cardsValue ( tempPlayerAndBoardArray , temp5Array ));
2011-02-11 20:02:08 +00:00
( * it ) -> setMyBestHandPosition ( temp5Array );
2010-01-02 18:10:36 +00:00
2007-09-23 17:07:52 +00:00
2011-02-11 20:02:08 +00:00
}
break ;
case 2 : {
/* tempBoardArray[0] = 48;
tempBoardArray[1] = 21;
tempBoardArray[2] = 4;
tempBoardArray[3] = 9;
tempBoardArray[4] = 0;
myBoard->setMyCards(tempBoardArray);
tempPlayerAndBoardArray[2] = tempBoardArray[0];
tempPlayerAndBoardArray[3] = tempBoardArray[1];
tempPlayerAndBoardArray[4] = tempBoardArray[2];
tempPlayerAndBoardArray[5] = tempBoardArray[3];
tempPlayerAndBoardArray[6] = tempBoardArray[4];*/
// player0
it = seatsList -> begin ();
2007-09-28 00:16:11 +00:00
// tempPlayerArray[0] = 9;
// tempPlayerArray[1] = 5;
// tempPlayerAndBoardArray[0] = tempPlayerArray[0];
// tempPlayerAndBoardArray[1] = tempPlayerArray[1];
2011-02-11 20:02:08 +00:00
//
2007-09-28 00:16:11 +00:00
// (*it)->setMyCards(tempPlayerArray);
2011-03-06 15:22:13 +00:00
// (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
2011-02-11 20:02:08 +00:00
//
2007-09-28 00:16:11 +00:00
// (*it)->setMyBestHandPosition(temp5Array);
2007-09-27 20:36:02 +00:00
2011-02-11 20:02:08 +00:00
// player1
++ it ;
2007-09-28 15:04:52 +00:00
// tempPlayerArray[0] = 47;
// tempPlayerArray[1] = 22;
// tempPlayerAndBoardArray[0] = tempPlayerArray[0];
// tempPlayerAndBoardArray[1] = tempPlayerArray[1];
2011-02-11 20:02:08 +00:00
//
2007-09-28 15:04:52 +00:00
// (*it)->setMyCards(tempPlayerArray);
2011-03-06 15:22:13 +00:00
// (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
2011-02-11 20:02:08 +00:00
//
2007-09-28 15:04:52 +00:00
// (*it)->setMyBestHandPosition(temp5Array);
2011-02-11 20:02:08 +00:00
// player2
++ it ;
2007-09-28 00:16:11 +00:00
// tempPlayerArray[0] = 33;
// tempPlayerArray[1] = 27;
// tempPlayerAndBoardArray[0] = tempPlayerArray[0];
// tempPlayerAndBoardArray[1] = tempPlayerArray[1];
2011-02-11 20:02:08 +00:00
//
2007-09-28 00:16:11 +00:00
// (*it)->setMyCards(tempPlayerArray);
2011-03-06 15:22:13 +00:00
// (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
2011-02-11 20:02:08 +00:00
//
2007-09-28 00:16:11 +00:00
// (*it)->setMyBestHandPosition(temp5Array);
2011-02-11 20:02:08 +00:00
// player3
++ it ;
2007-09-27 20:36:02 +00:00
// tempPlayerArray[0] = 38;
// tempPlayerArray[1] = 22;
2007-09-02 19:20:49 +00:00
// tempPlayerAndBoardArray[0] = tempPlayerArray[0];
// tempPlayerAndBoardArray[1] = tempPlayerArray[1];
2011-02-11 20:02:08 +00:00
//
2007-09-27 20:36:02 +00:00
// (*it)->setMyCards(tempPlayerArray);
2011-03-06 15:22:13 +00:00
// (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
2011-02-11 20:02:08 +00:00
//
2007-09-27 20:36:02 +00:00
// (*it)->setMyBestHandPosition(temp5Array);
2011-02-11 20:02:08 +00:00
// player4
++ it ;
2007-09-27 20:36:02 +00:00
// tempPlayerArray[0] = 25;
// tempPlayerArray[1] = 16;
2007-09-02 19:20:49 +00:00
// tempPlayerAndBoardArray[0] = tempPlayerArray[0];
// tempPlayerAndBoardArray[1] = tempPlayerArray[1];
2011-02-11 20:02:08 +00:00
//
2007-09-27 20:36:02 +00:00
// (*it)->setMyCards(tempPlayerArray);
2011-03-06 15:22:13 +00:00
// (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
2011-02-11 20:02:08 +00:00
//
2007-09-27 20:36:02 +00:00
// (*it)->setMyBestHandPosition(temp5Array);
2011-02-11 20:02:08 +00:00
// player5
++ it ;
2007-09-28 15:04:52 +00:00
// tempPlayerArray[0] = 27;
// tempPlayerArray[1] = 10;
// tempPlayerAndBoardArray[0] = tempPlayerArray[0];
// tempPlayerAndBoardArray[1] = tempPlayerArray[1];
2011-02-11 20:02:08 +00:00
//
2007-09-28 15:04:52 +00:00
// (*it)->setMyCards(tempPlayerArray);
2011-03-06 15:22:13 +00:00
// (*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
2011-02-11 20:02:08 +00:00
//
2007-09-28 15:04:52 +00:00
// (*it)->setMyBestHandPosition(temp5Array);
2007-09-01 16:32:36 +00:00
2011-02-11 20:02:08 +00:00
}
break ;
default :
{}
2007-08-24 15:15:01 +00:00
2007-08-25 20:09:40 +00:00
}
2007-08-11 14:36:20 +00:00
2007-09-01 16:32:36 +00:00
2007-08-11 14:36:20 +00:00
}
2007-08-10 18:44:41 +00:00
// ----------------------------------------
2007-04-30 11:53:40 +00:00
2007-10-19 14:03:12 +00:00
// determine dealer, SB, BB
2011-02-25 21:21:36 +00:00
2007-05-12 22:00:59 +00:00
assignButtons ();
2007-01-13 02:40:33 +00:00
2011-02-26 10:09:45 +00:00
setBlinds ();
2011-02-25 21:21:36 +00:00
2012-01-02 22:07:25 +00:00
if ( myLog ) myLog -> logNewHandMsg ( myID , dealerPosition + 1 , smallBlind , smallBlindPosition + 1 , 2 * smallBlind , bigBlindPosition + 1 , seatsList );
2011-11-09 21:39:37 +00:00
2011-10-26 22:29:47 +00:00
myBeRo = myFactory -> createBeRo ( this , dealerPosition , smallBlind );
2007-01-13 02:40:33 +00:00
}
LocalHand ::~ LocalHand ()
{
}
2011-02-11 20:02:08 +00:00
void LocalHand :: start ()
{
2007-05-12 22:00:59 +00:00
2007-10-03 22:42:24 +00:00
//Log blinds sets for new Hand
PlayerListConstIterator it_sB , it_bB ;
it_sB = getActivePlayerIt ( getCurrentBeRo () -> getSmallBlindPositionId ());
it_bB = getActivePlayerIt ( getCurrentBeRo () -> getBigBlindPositionId ());
if ( it_sB != getActivePlayerList () -> end () && it_bB != getActivePlayerList () -> end ()) {
2011-02-11 20:02:08 +00:00
myGui -> logNewBlindsSetsMsg (( * it_sB ) -> getMySet (), ( * it_bB ) -> getMySet (), ( * it_sB ) -> getMyName (). c_str (), ( * it_bB ) -> getMyName (). c_str ());
} else {
LOG_ERROR ( __FILE__ << " (" << __LINE__ << "): Log Error: cannot find sBID or bBID" );
}
myGui -> flushLogAtHand ();
2007-05-12 22:00:59 +00:00
2007-10-19 14:03:12 +00:00
// deal cards
2007-05-12 22:00:59 +00:00
myGui -> dealHoleCards ();
getBoard () -> collectSets ();
getGuiInterface () -> refreshPot ();
2011-02-11 20:02:08 +00:00
2007-10-19 14:03:12 +00:00
// change rounds | first start preflop
2007-05-12 22:00:59 +00:00
myGui -> nextPlayerAnimation ();
}
2011-02-11 20:02:08 +00:00
void LocalHand :: assignButtons ()
{
2007-01-13 02:40:33 +00:00
2007-09-27 09:47:02 +00:00
size_t i ;
2007-09-27 00:37:01 +00:00
PlayerListIterator it ;
2007-05-18 11:38:37 +00:00
2007-10-19 14:03:12 +00:00
// delete all buttons
2011-02-09 14:33:39 +00:00
for ( it = seatsList -> begin (); it != seatsList -> end (); ++ it ) {
2007-09-27 00:37:01 +00:00
( * it ) -> setMyButton ( BUTTON_NONE );
}
2007-01-13 02:40:33 +00:00
2007-10-19 14:03:12 +00:00
// assign dealer button
2007-09-27 00:37:01 +00:00
it = getSeatIt ( dealerPosition );
2007-10-14 11:01:44 +00:00
if ( it == seatsList -> end ()) {
2007-10-18 20:36:49 +00:00
throw LocalException ( __FILE__ , __LINE__ , ERR_SEAT_NOT_FOUND );
2007-10-14 11:01:44 +00:00
}
2007-09-27 00:37:01 +00:00
( * it ) -> setMyButton ( BUTTON_DEALER );
2007-01-13 02:40:33 +00:00
2007-09-27 00:37:01 +00:00
// assign Small Blind next to dealer. ATTENTION: in heads up it is big blind
// assign big blind next to small blind. ATTENTION: in heads up it is small blind
bool nextActivePlayerFound = false ;
PlayerListIterator dealerPositionIt = getSeatIt ( dealerPosition );
2007-10-14 11:01:44 +00:00
if ( dealerPositionIt == seatsList -> end ()) {
2007-10-18 20:36:49 +00:00
throw LocalException ( __FILE__ , __LINE__ , ERR_SEAT_NOT_FOUND );
2007-10-14 11:01:44 +00:00
}
2007-09-27 00:37:01 +00:00
for ( i = 0 ; i < seatsList -> size (); i ++ ) {
2011-02-09 14:33:39 +00:00
++ dealerPositionIt ;
2007-09-27 00:37:01 +00:00
if ( dealerPositionIt == seatsList -> end ()) dealerPositionIt = seatsList -> begin ();
it = getActivePlayerIt ( ( * dealerPositionIt ) -> getMyUniqueID () );
if ( it != activePlayerList -> end () ) {
nextActivePlayerFound = true ;
2011-02-11 20:02:08 +00:00
if ( activePlayerList -> size () > 2 ) {
//small blind normal
( * it ) -> setMyButton ( 2 );
smallBlindPosition = ( * it ) -> getMyUniqueID ();
} else {
//big blind in heads up
( * it ) -> setMyButton ( 3 );
bigBlindPosition = ( * it ) -> getMyUniqueID ();
// lastPlayerAction for showing cards
}
2007-09-27 00:37:01 +00:00
2011-02-11 20:02:08 +00:00
// first player after dealer have to show his cards first (in showdown)
2011-10-26 22:29:47 +00:00
lastActionPlayerID = ( * it ) -> getMyUniqueID ();
myBoard -> setLastActionPlayerID ( lastActionPlayerID );
2010-09-08 19:21:15 +00:00
2011-02-09 14:33:39 +00:00
++ it ;
2007-09-27 00:37:01 +00:00
if ( it == activePlayerList -> end ()) it = activePlayerList -> begin ();
2011-02-11 20:02:08 +00:00
if ( activePlayerList -> size () > 2 ) {
//big blind normal
( * it ) -> setMyButton ( 3 );
bigBlindPosition = ( * it ) -> getMyUniqueID ();
} else {
//small blind in heads up
( * it ) -> setMyButton ( 2 );
smallBlindPosition = ( * it ) -> getMyUniqueID ();
}
2007-09-27 00:37:01 +00:00
break ;
2007-05-18 11:38:37 +00:00
}
2007-09-27 00:37:01 +00:00
2007-08-08 12:54:20 +00:00
}
2007-10-14 11:01:44 +00:00
if ( ! nextActivePlayerFound ) {
2007-10-18 20:36:49 +00:00
throw LocalException ( __FILE__ , __LINE__ , ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND );
2007-10-14 11:01:44 +00:00
}
2007-09-27 00:37:01 +00:00
2010-07-22 21:17:22 +00:00
// cout << "lAP-Button: " << lastActionPlayer << endl;
2011-02-25 21:21:36 +00:00
}
2010-07-22 21:17:22 +00:00
2011-02-25 21:21:36 +00:00
void LocalHand :: setBlinds ()
{
2007-05-18 11:38:37 +00:00
2011-02-26 10:09:45 +00:00
PlayerListConstIterator it_c ;
2007-01-13 02:40:33 +00:00
2011-02-26 10:09:45 +00:00
//do sets --> TODO switch?
for ( it_c = runningPlayerList -> begin (); it_c != runningPlayerList -> end (); ++ it_c ) {
2007-09-24 10:02:17 +00:00
2011-02-26 10:09:45 +00:00
//small blind
if (( * it_c ) -> getMyButton () == BUTTON_SMALL_BLIND ) {
2007-01-13 02:40:33 +00:00
2011-02-26 10:09:45 +00:00
// All in ?
if (( * it_c ) -> getMyCash () <= smallBlind ) {
2007-06-08 19:37:21 +00:00
2011-02-26 10:09:45 +00:00
( * it_c ) -> setMySet (( * it_c ) -> getMyCash ());
// 1 to do not log this
( * it_c ) -> setMyAction ( PLAYER_ACTION_ALLIN , 1 );
2011-02-11 20:02:08 +00:00
2011-02-26 10:09:45 +00:00
} else {
( * it_c ) -> setMySet ( smallBlind );
}
}
2007-09-26 10:13:10 +00:00
2011-02-27 00:03:39 +00:00
}
//do sets --> TODO switch?
for ( it_c = runningPlayerList -> begin (); it_c != runningPlayerList -> end (); ++ it_c ) {
2011-02-26 10:09:45 +00:00
//big blind
if (( * it_c ) -> getMyButton () == BUTTON_BIG_BLIND ) {
2011-02-11 20:02:08 +00:00
2011-02-26 10:09:45 +00:00
// all in ?
if (( * it_c ) -> getMyCash () <= 2 * smallBlind ) {
2011-02-25 21:21:36 +00:00
2011-02-26 10:09:45 +00:00
( * it_c ) -> setMySet (( * it_c ) -> getMyCash ());
// 1 to do not log this
( * it_c ) -> setMyAction ( PLAYER_ACTION_ALLIN , 1 );
2011-02-25 21:21:36 +00:00
2011-02-26 10:09:45 +00:00
} else {
( * it_c ) -> setMySet ( 2 * smallBlind );
}
}
}
2007-01-13 02:40:33 +00:00
}
2011-02-11 20:02:08 +00:00
void LocalHand :: switchRounds ()
{
2007-01-13 02:40:33 +00:00
2011-10-29 14:41:17 +00:00
// logging last player action
PlayerListConstIterator previousPlayerIt = getRunningPlayerIt ( previousPlayerID );
if ( previousPlayerIt != runningPlayerList -> end ()) {
2012-01-07 18:42:24 +00:00
if ( myLog ) myLog -> logPlayerAction (( * previousPlayerIt ) -> getMyName (), myLog -> transformPlayerActionLog (( * previousPlayerIt ) -> getMyAction ()),( * previousPlayerIt ) -> getMySet ());
2011-10-29 14:41:17 +00:00
}
2011-10-26 19:34:57 +00:00
2007-09-26 22:27:05 +00:00
PlayerListIterator it , it_1 ;
2007-09-26 10:13:10 +00:00
PlayerListConstIterator it_c ;
2007-01-13 02:40:33 +00:00
2007-09-25 09:52:58 +00:00
// refresh runningPlayerList
2007-09-25 12:43:58 +00:00
for ( it = runningPlayerList -> begin (); it != runningPlayerList -> end (); ) {
2007-09-27 09:47:02 +00:00
if (( * it ) -> getMyAction () == PLAYER_ACTION_FOLD || ( * it ) -> getMyAction () == PLAYER_ACTION_ALLIN ) {
2007-09-29 13:22:00 +00:00
2007-09-25 09:52:58 +00:00
it = runningPlayerList -> erase ( it );
2007-09-26 22:27:05 +00:00
if ( ! ( runningPlayerList -> empty ())) {
it_1 = it ;
if ( it_1 == runningPlayerList -> begin ()) it_1 = runningPlayerList -> end ();
2011-02-09 14:33:39 +00:00
-- it_1 ;
2007-09-26 22:27:05 +00:00
getCurrentBeRo () -> setCurrentPlayersTurnId (( * it_1 ) -> getMyUniqueID ());
}
2007-09-25 12:43:58 +00:00
} else {
2011-02-09 14:33:39 +00:00
++ it ;
2007-09-25 09:52:58 +00:00
}
}
2007-10-19 14:03:12 +00:00
// determine number of all in players
2007-01-13 02:40:33 +00:00
int allInPlayersCounter = 0 ;
2011-02-09 14:33:39 +00:00
for ( it_c = activePlayerList -> begin (); it_c != activePlayerList -> end (); ++ it_c ) {
2007-09-27 09:47:02 +00:00
if (( * it_c ) -> getMyAction () == PLAYER_ACTION_ALLIN ) allInPlayersCounter ++ ;
2007-01-13 02:40:33 +00:00
}
2007-09-24 14:57:37 +00:00
2007-10-19 14:03:12 +00:00
// determine number of non-fold players
2007-09-24 14:57:37 +00:00
int nonFoldPlayerCounter = 0 ;
2011-02-09 14:33:39 +00:00
for ( it_c = activePlayerList -> begin (); it_c != activePlayerList -> end (); ++ it_c ) {
2007-09-27 09:47:02 +00:00
if (( * it_c ) -> getMyAction () != PLAYER_ACTION_FOLD ) nonFoldPlayerCounter ++ ;
2007-09-24 14:57:37 +00:00
}
2007-10-19 14:03:12 +00:00
// if only one player non-fold -> distribute pot
2007-09-24 14:57:37 +00:00
if ( nonFoldPlayerCounter == 1 ) {
2011-02-11 20:02:08 +00:00
myBoard -> collectPot ();
2007-01-13 14:27:56 +00:00
myGui -> refreshPot ();
2007-01-13 02:40:33 +00:00
myGui -> refreshSet ();
2011-10-26 22:29:47 +00:00
currentRound = GAME_STATE_POST_RIVER ;
2012-01-07 20:46:30 +00:00
if ( myLog ) myLog -> setCurrentRound ( currentRound );
2007-01-13 02:40:33 +00:00
}
2007-10-19 14:03:12 +00:00
// check for all in condition
// for all in condition at least two active players have to remain
2007-01-13 02:40:33 +00:00
else {
2007-04-03 10:55:16 +00:00
2007-10-19 14:03:12 +00:00
// 1) all players all in
2007-09-24 14:57:37 +00:00
if ( allInPlayersCounter == nonFoldPlayerCounter ) {
2007-09-24 10:02:17 +00:00
allInCondition = true ;
2011-02-11 20:02:08 +00:00
myBoard -> setAllInCondition ( true );
2007-01-13 02:40:33 +00:00
}
2007-10-19 14:03:12 +00:00
// 2) all players but one all in and he has highest set
2007-09-24 14:57:37 +00:00
if ( allInPlayersCounter + 1 == nonFoldPlayerCounter ) {
2011-02-09 14:33:39 +00:00
for ( it_c = runningPlayerList -> begin (); it_c != runningPlayerList -> end (); ++ it_c ) {
2007-09-27 09:47:02 +00:00
2007-10-18 17:40:12 +00:00
if (( * it_c ) -> getMySet () >= myBeRo [ currentRound ] -> getHighestSet ()) {
2011-02-11 20:02:08 +00:00
allInCondition = true ;
myBoard -> setAllInCondition ( true );
2007-09-24 14:57:37 +00:00
}
2007-05-23 20:03:10 +00:00
2007-09-24 10:02:17 +00:00
}
2007-05-23 20:03:10 +00:00
2007-09-28 00:16:11 +00:00
// exception
2011-02-11 20:02:08 +00:00
// no.1: if in first Preflop Round next player is small blind and only all-in-big-blind with less than smallblind amount and other all-in players with less than small blind are nonfold too -> preflop is over
PlayerListConstIterator smallBlindIt_c = getRunningPlayerIt ( myBeRo [ currentRound ] -> getSmallBlindPositionId ());
PlayerListConstIterator bigBlindIt_c = getActivePlayerIt ( myBeRo [ currentRound ] -> getBigBlindPositionId ());
if ( smallBlindIt_c != runningPlayerList -> end () && bigBlindIt_c != activePlayerList -> end () && currentRound == GAME_STATE_PREFLOP && myBeRo [ currentRound ] -> getFirstRound ()) {
// determine player who are all in with less than small blind amount
int tempCounter = 0 ;
2011-02-09 14:33:39 +00:00
for ( it_c = activePlayerList -> begin (); it_c != activePlayerList -> end (); ++ it_c ) {
2011-02-11 20:02:08 +00:00
if (( * it_c ) -> getMyAction () == PLAYER_ACTION_ALLIN && ( * it_c ) -> getMySet () <= smallBlind ) {
tempCounter ++ ;
2007-10-19 14:03:12 +00:00
}
2007-09-28 00:16:11 +00:00
}
2011-02-11 20:02:08 +00:00
if ( ( * bigBlindIt_c ) -> getMySet () <= smallBlind && tempCounter == allInPlayersCounter ) {
allInCondition = true ;
myBoard -> setAllInCondition ( true );
}
}
// no.2: heads up -> detect player who is all in and bb but could set less than sb
for ( it_c = activePlayerList -> begin (); it_c != activePlayerList -> end (); ++ it_c ) {
if ( activePlayerList -> size () == 2 && ( * it_c ) -> getMyAction () == PLAYER_ACTION_ALLIN && ( * it_c ) -> getMyButton () == BUTTON_BIG_BLIND && ( * it_c ) -> getMySet () <= smallBlind && currentRound == GAME_STATE_PREFLOP ) {
allInCondition = true ;
myBoard -> setAllInCondition ( true );
}
}
2007-01-13 02:40:33 +00:00
}
}
2007-10-19 14:03:12 +00:00
// special routine
2007-01-13 02:40:33 +00:00
if ( allInCondition ) {
2011-02-11 20:02:08 +00:00
myBoard -> collectPot ();
2007-01-13 14:27:56 +00:00
myGui -> refreshPot ();
myGui -> refreshSet ();
2007-01-29 09:11:44 +00:00
myGui -> flipHolecardsAllIn ();
2011-10-26 22:29:47 +00:00
// Logging HoleCards
if ( currentRound < GAME_STATE_RIVER ) {
2012-01-07 18:42:24 +00:00
if ( myLog ) myLog -> logHoleCardsHandName ( activePlayerList );
2011-10-26 22:29:47 +00:00
}
2011-02-11 20:02:08 +00:00
2012-01-07 18:42:24 +00:00
if ( currentRound < GAME_STATE_POST_RIVER ) { // do not increment past 4
2011-10-26 22:29:47 +00:00
currentRound = GameState ( currentRound + 1 );
2012-01-07 20:46:30 +00:00
if ( myLog ) myLog -> setCurrentRound ( currentRound );
2012-01-07 18:42:24 +00:00
}
2011-02-11 20:02:08 +00:00
2007-06-13 20:02:40 +00:00
//log board cards for allin
2011-10-26 22:29:47 +00:00
if ( currentRound >= GAME_STATE_FLOP ) {
2007-06-13 20:02:40 +00:00
int tempBoardCardsArray [ 5 ];
2011-02-11 20:02:08 +00:00
2007-06-13 20:02:40 +00:00
myBoard -> getMyCards ( tempBoardCardsArray );
2007-10-18 17:40:12 +00:00
myGui -> logDealBoardCardsMsg ( currentRound , tempBoardCardsArray [ 0 ], tempBoardCardsArray [ 1 ], tempBoardCardsArray [ 2 ], tempBoardCardsArray [ 3 ], tempBoardCardsArray [ 4 ]);
2012-01-07 18:42:24 +00:00
if ( myLog ) myLog -> logBoardCards ( tempBoardCardsArray );
2007-06-13 20:02:40 +00:00
}
2011-02-11 20:02:08 +00:00
2007-01-13 02:40:33 +00:00
}
2007-09-27 09:47:02 +00:00
//unhighlight current players groupbox
2011-10-26 22:29:47 +00:00
it_c = getActivePlayerIt ( previousPlayerID );
2011-02-11 20:02:08 +00:00
if ( it_c != activePlayerList -> end () ) {
2007-09-27 09:47:02 +00:00
// lastPlayersTurn is active
2011-10-26 22:29:47 +00:00
myGui -> refreshGroupbox ( previousPlayerID , 1 );
2007-09-27 09:47:02 +00:00
}
2007-10-18 17:40:12 +00:00
myGui -> refreshGameLabels (( GameState ) getCurrentRound ());
2007-08-05 23:57:16 +00:00
2011-11-13 16:00:19 +00:00
if ( currentRound < GAME_STATE_POST_RIVER ) {
roundBeforePostRiver = currentRound ;
}
2007-10-18 17:40:12 +00:00
switch ( currentRound ) {
2011-11-13 16:00:19 +00:00
case GAME_STATE_PREFLOP : {
2011-02-11 20:02:08 +00:00
myGui -> preflopAnimation1 ();
}
break ;
2011-11-13 16:00:19 +00:00
case GAME_STATE_FLOP : {
2011-02-11 20:02:08 +00:00
myGui -> flopAnimation1 ();
}
break ;
2011-11-13 16:00:19 +00:00
case GAME_STATE_TURN : {
2011-02-11 20:02:08 +00:00
myGui -> turnAnimation1 ();
}
break ;
2011-11-13 16:00:19 +00:00
case GAME_STATE_RIVER : {
2011-02-11 20:02:08 +00:00
myGui -> riverAnimation1 ();
}
break ;
2011-11-13 16:00:19 +00:00
case GAME_STATE_POST_RIVER : {
2011-02-11 20:02:08 +00:00
myGui -> postRiverAnimation1 ();
}
break ;
default :
{}
2007-01-13 02:40:33 +00:00
}
}
2007-09-26 19:45:58 +00:00
2011-02-11 20:02:08 +00:00
PlayerListIterator LocalHand :: getSeatIt ( unsigned uniqueId ) const
{
2007-09-27 00:37:01 +00:00
PlayerListIterator it ;
2011-02-09 14:33:39 +00:00
for ( it = seatsList -> begin (); it != seatsList -> end (); ++ it ) {
2007-09-27 00:37:01 +00:00
if (( * it ) -> getMyUniqueID () == uniqueId ) {
break ;
}
}
return it ;
}
2011-02-11 20:02:08 +00:00
PlayerListIterator LocalHand :: getActivePlayerIt ( unsigned uniqueId ) const
{
2007-09-26 19:45:58 +00:00
PlayerListIterator it ;
2011-02-09 14:33:39 +00:00
for ( it = activePlayerList -> begin (); it != activePlayerList -> end (); ++ it ) {
2007-09-26 19:45:58 +00:00
if (( * it ) -> getMyUniqueID () == uniqueId ) {
break ;
}
}
return it ;
}
2011-02-11 20:02:08 +00:00
PlayerListIterator LocalHand :: getRunningPlayerIt ( unsigned uniqueId ) const
{
2007-09-26 19:45:58 +00:00
PlayerListIterator it ;
2011-02-09 14:33:39 +00:00
for ( it = runningPlayerList -> begin (); it != runningPlayerList -> end (); ++ it ) {
2007-09-26 22:27:05 +00:00
2007-09-26 19:45:58 +00:00
if (( * it ) -> getMyUniqueID () == uniqueId ) {
break ;
}
}
return it ;
}
2011-01-06 22:00:52 +00:00
2011-10-26 19:34:57 +00:00
void LocalHand :: setLastActionPlayerID ( unsigned theValue )
2011-02-11 20:02:08 +00:00
{
2011-10-26 22:29:47 +00:00
lastActionPlayerID = theValue ;
myBoard -> setLastActionPlayerID ( theValue );
2011-01-06 22:00:52 +00:00
}