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-08-04 01:30:59 +00:00
|
|
|
#include "localbero.h"
|
|
|
|
|
|
2007-10-14 11:01:44 +00:00
|
|
|
#include "localexception.h"
|
|
|
|
|
#include "engine_msg.h"
|
2007-10-23 21:26:07 +00:00
|
|
|
#include <core/loghelper.h>
|
2007-10-14 11:01:44 +00:00
|
|
|
|
2007-08-07 13:07:39 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2011-10-21 00:16:43 +00:00
|
|
|
LocalBeRo::LocalBeRo(HandInterface* hi, unsigned dP, int sB, GameState gS)
|
|
|
|
|
: BeRoInterface(), myHand(hi), myBeRoID(gS), dealerPosition(dP), smallBlindPosition(0), dealerPositionId(dP), smallBlindPositionId(0), bigBlindPositionId(0), smallBlind(sB), highestSet(0), minimumRaise(2*sB), fullBetRule(false), firstRun(true), firstRunGui(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
|
2011-02-09 14:33:39 +00:00
|
|
|
for(it_c=myHand->getActivePlayerList()->begin(); it_c!=myHand->getActivePlayerList()->end(); ++it_c) {
|
2007-09-26 19:45:58 +00:00
|
|
|
if((*it_c)->getMyButton() == BUTTON_BIG_BLIND) {
|
|
|
|
|
bigBlindPositionId = (*it_c)->getMyUniqueID();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-14 11:01:44 +00:00
|
|
|
if(it_c == myHand->getActivePlayerList()->end()) {
|
2007-10-18 20:36:49 +00:00
|
|
|
throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND);
|
2007-10-14 11:01:44 +00:00
|
|
|
}
|
2007-09-26 19:45:58 +00:00
|
|
|
|
|
|
|
|
// determine smallBlindPosition
|
2011-02-09 14:33:39 +00:00
|
|
|
for(it_c=myHand->getActivePlayerList()->begin(); it_c!=myHand->getActivePlayerList()->end(); ++it_c) {
|
2007-09-26 19:45:58 +00:00
|
|
|
if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND) {
|
|
|
|
|
smallBlindPositionId = (*it_c)->getMyUniqueID();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-14 11:01:44 +00:00
|
|
|
if(it_c == myHand->getActivePlayerList()->end()) {
|
2007-10-18 20:36:49 +00:00
|
|
|
throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND);
|
2007-10-14 11:01:44 +00:00
|
|
|
}
|
2007-09-26 19:45:58 +00:00
|
|
|
|
2007-10-19 14:03:12 +00:00
|
|
|
}
|
2007-08-04 01:30:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
LocalBeRo::~LocalBeRo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-23 21:26:07 +00:00
|
|
|
int LocalBeRo::getHighestCardsValue() const
|
|
|
|
|
{
|
|
|
|
|
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): getHighestCardsValue() in wrong BeRo");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void LocalBeRo::nextPlayer()
|
|
|
|
|
{
|
2007-08-07 13:07:39 +00:00
|
|
|
|
2007-09-26 19:45:58 +00:00
|
|
|
PlayerListConstIterator currentPlayersTurnConstIt = myHand->getRunningPlayerIt(currentPlayersTurnId);
|
2007-10-14 11:01:44 +00:00
|
|
|
if(currentPlayersTurnConstIt == myHand->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-26 19:45:58 +00:00
|
|
|
|
|
|
|
|
(*currentPlayersTurnConstIt)->action();
|
2007-08-07 13:07:39 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
void LocalBeRo::run()
|
|
|
|
|
{
|
2007-08-07 00:05:29 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
if(firstRunGui) {
|
|
|
|
|
firstRunGui = false;
|
2007-11-01 21:34:06 +00:00
|
|
|
myHand->setLastPlayersTurn(-1);
|
2007-10-07 12:00:34 +00:00
|
|
|
myHand->getGuiInterface()->dealBeRoCards(myBeRoID);
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2007-10-07 11:12:02 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
if(firstRun) {
|
2007-09-26 20:11:49 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
firstRun = false;
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
if(!(myHand->getAllInCondition())) {
|
2007-10-19 14:03:12 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
PlayerListIterator it_1, it_2;
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
// running player before smallBlind
|
2007-10-14 11:01:44 +00:00
|
|
|
bool formerRunningPlayerFound = false;
|
2007-10-07 12:00:34 +00:00
|
|
|
if(myHand->getActivePlayerList()->size() > 2) {
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
it_1 = myHand->getActivePlayerIt(smallBlindPositionId);
|
2007-10-14 11:01:44 +00:00
|
|
|
if(it_1 == myHand->getActivePlayerList()->end()) {
|
2007-10-18 20:36:49 +00:00
|
|
|
throw LocalException(__FILE__, __LINE__, ERR_ACTIVE_PLAYER_NOT_FOUND);
|
2007-10-14 11:01:44 +00:00
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2010-10-28 08:04:36 +00:00
|
|
|
for(size_t i=0; i<myHand->getActivePlayerList()->size(); i++) {
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
if(it_1 == myHand->getActivePlayerList()->begin()) it_1 = myHand->getActivePlayerList()->end();
|
2011-02-09 14:33:39 +00:00
|
|
|
--it_1;
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-10-07 12:00:34 +00:00
|
|
|
it_2 = myHand->getRunningPlayerIt((*it_1)->getMyUniqueID());
|
|
|
|
|
// running player found
|
|
|
|
|
if(it_2 != myHand->getRunningPlayerList()->end()) {
|
|
|
|
|
firstRoundLastPlayersTurnId = (*it_2)->getMyUniqueID();
|
2007-10-14 11:01:44 +00:00
|
|
|
formerRunningPlayerFound = true;
|
2007-10-07 12:00:34 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-14 11:01:44 +00:00
|
|
|
if(!formerRunningPlayerFound) {
|
2007-10-18 20:36:49 +00:00
|
|
|
throw LocalException(__FILE__, __LINE__, ERR_FORMER_RUNNING_PLAYER_NOT_FOUND);
|
2007-10-14 11:01:44 +00:00
|
|
|
}
|
2007-10-07 12:00:34 +00:00
|
|
|
}
|
|
|
|
|
// heads up: bigBlind begins -> dealer/smallBlind is running player before bigBlind
|
|
|
|
|
else {
|
|
|
|
|
firstRoundLastPlayersTurnId = smallBlindPositionId;
|
2011-02-11 20:02:08 +00:00
|
|
|
}
|
2007-10-07 12:00:34 +00:00
|
|
|
currentPlayersTurnId = firstRoundLastPlayersTurnId;
|
|
|
|
|
}
|
2007-09-26 22:27:05 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-07 00:05:29 +00:00
|
|
|
//log the turned cards
|
|
|
|
|
if(!logBoardCardsDone) {
|
|
|
|
|
|
|
|
|
|
int tempBoardCardsArray[5];
|
|
|
|
|
|
|
|
|
|
myHand->getBoard()->getMyCards(tempBoardCardsArray);
|
2007-08-29 17:57:17 +00:00
|
|
|
|
|
|
|
|
switch(myBeRoID) {
|
2011-02-11 20:02:08 +00:00
|
|
|
case GAME_STATE_FLOP:
|
|
|
|
|
myHand->getGuiInterface()->logDealBoardCardsMsg(myBeRoID, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2]);
|
2007-08-29 17:57:17 +00:00
|
|
|
break;
|
2011-02-11 20:02:08 +00:00
|
|
|
case GAME_STATE_TURN:
|
|
|
|
|
myHand->getGuiInterface()->logDealBoardCardsMsg(myBeRoID, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3]);
|
2007-08-29 17:57:17 +00:00
|
|
|
break;
|
2011-02-11 20:02:08 +00:00
|
|
|
case GAME_STATE_RIVER:
|
|
|
|
|
myHand->getGuiInterface()->logDealBoardCardsMsg(myBeRoID, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]);
|
2011-02-27 16:34:39 +00:00
|
|
|
|
2007-08-29 17:57:17 +00:00
|
|
|
break;
|
2011-02-11 20:02:08 +00:00
|
|
|
default: {
|
|
|
|
|
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID");
|
|
|
|
|
}
|
2007-08-29 17:57:17 +00:00
|
|
|
}
|
2011-02-27 16:34:39 +00:00
|
|
|
myHand->getLog()->logBoardCards(myBeRoID+1, tempBoardCardsArray);
|
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
|
|
|
|
2007-09-26 22:27:05 +00:00
|
|
|
PlayerListIterator it;
|
|
|
|
|
PlayerListIterator it_c;
|
|
|
|
|
|
|
|
|
|
|
2007-10-19 14:03:12 +00:00
|
|
|
// check if all running players have same sets (else allHighestSet = false)
|
2011-02-09 14:33:39 +00:00
|
|
|
for( it_c = myHand->getRunningPlayerList()->begin(); it_c != myHand->getRunningPlayerList()->end(); ++it_c) {
|
2007-09-26 22:27:05 +00:00
|
|
|
if(highestSet != (*it_c)->getMySet()) {
|
2007-09-25 21:46:38 +00:00
|
|
|
allHighestSet = false;
|
2007-09-26 22:27:05 +00:00
|
|
|
break;
|
2007-08-07 00:05:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-25 21:46:38 +00:00
|
|
|
// prfen, ob aktuelle bero wirklich dran ist
|
2011-02-11 20:02:08 +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
|
2011-10-22 23:57:02 +00:00
|
|
|
myHand->setCurrentRound(GameState(myBeRoID+1));
|
2007-08-07 00:05:29 +00:00
|
|
|
|
2007-09-25 21:46:38 +00:00
|
|
|
//Action loeschen und ActionButtons refresh
|
2011-02-09 14:33:39 +00:00
|
|
|
for(it_c=myHand->getRunningPlayerList()->begin(); it_c!=myHand->getRunningPlayerList()->end(); ++it_c) {
|
2007-09-26 22:27:05 +00:00
|
|
|
(*it_c)->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();
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-08-07 00:05:29 +00:00
|
|
|
myHand->getGuiInterface()->refreshSet();
|
|
|
|
|
myHand->getGuiInterface()->refreshCash();
|
2011-02-11 20:02:08 +00:00
|
|
|
for(int 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();
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2007-09-25 21:46:38 +00:00
|
|
|
// aktuelle bero ist wirklich dran
|
2007-08-07 00:05:29 +00:00
|
|
|
|
2007-09-27 18:07:03 +00:00
|
|
|
// Anzahl der effektiv gespielten Runden (des human player) erhöhen
|
|
|
|
|
it_c = myHand->getActivePlayerIt(0);
|
|
|
|
|
if( it_c != myHand->getActivePlayerList()->end() ) {
|
|
|
|
|
// human player is active
|
|
|
|
|
if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD ) {
|
|
|
|
|
myHand->setBettingRoundsPlayed(myBeRoID);
|
|
|
|
|
}
|
2007-08-07 00:05:29 +00:00
|
|
|
}
|
2007-10-19 14:03:12 +00:00
|
|
|
|
|
|
|
|
// determine next running player
|
|
|
|
|
PlayerListConstIterator currentPlayersTurnIt = myHand->getRunningPlayerIt( currentPlayersTurnId );
|
|
|
|
|
if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) {
|
|
|
|
|
throw LocalException(__FILE__, __LINE__, ERR_RUNNING_PLAYER_NOT_FOUND);
|
|
|
|
|
}
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2011-02-09 14:33:39 +00:00
|
|
|
++currentPlayersTurnIt;
|
2007-10-19 14:03:12 +00:00
|
|
|
if(currentPlayersTurnIt == myHand->getRunningPlayerList()->end()) currentPlayersTurnIt = myHand->getRunningPlayerList()->begin();
|
2011-02-11 20:02:08 +00:00
|
|
|
|
2007-10-19 14:03:12 +00:00
|
|
|
currentPlayersTurnId = (*currentPlayersTurnIt)->getMyUniqueID();
|
2007-08-07 00:05:29 +00:00
|
|
|
|
|
|
|
|
//highlight active players groupbox and clear action
|
2007-09-26 22:27:05 +00:00
|
|
|
myHand->getGuiInterface()->refreshGroupbox(currentPlayersTurnId,2);
|
|
|
|
|
myHand->getGuiInterface()->refreshAction(currentPlayersTurnId,0);
|
2007-08-07 00:05:29 +00:00
|
|
|
|
2007-09-26 22:27:05 +00:00
|
|
|
currentPlayersTurnIt = myHand->getRunningPlayerIt( currentPlayersTurnId );
|
2007-10-14 11:01:44 +00:00
|
|
|
if(currentPlayersTurnIt == myHand->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-26 22:27:05 +00:00
|
|
|
|
|
|
|
|
(*currentPlayersTurnIt)->setMyTurn(true);
|
2007-09-25 21:46:38 +00:00
|
|
|
|
|
|
|
|
|
2007-09-26 22:27:05 +00:00
|
|
|
if( currentPlayersTurnId == firstRoundLastPlayersTurnId ) {
|
2007-09-25 21:46:38 +00:00
|
|
|
firstRound = false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-09-26 22:27:05 +00:00
|
|
|
if( currentPlayersTurnId == 0) {
|
2007-08-07 00:05:29 +00:00
|
|
|
// Wir sind dran
|
|
|
|
|
myHand->getGuiInterface()->meInAction();
|
2011-02-11 20:02:08 +00:00
|
|
|
} else {
|
2007-10-09 21:19:22 +00:00
|
|
|
|
2007-08-07 00:05:29 +00:00
|
|
|
//Gegner sind dran
|
2007-08-07 13:07:39 +00:00
|
|
|
myHand->getGuiInterface()->beRoAnimation2(myBeRoID);
|
2007-08-07 00:05:29 +00:00
|
|
|
}
|
2011-10-24 20:44:22 +00:00
|
|
|
|
|
|
|
|
// logging action
|
|
|
|
|
PlayerActionLog myActionLog = LOG_ACTION_NONE;
|
|
|
|
|
switch((*currentPlayersTurnIt)->getMyAction()) {
|
|
|
|
|
case PLAYER_ACTION_FOLD: {
|
|
|
|
|
myActionLog = LOG_ACTION_FOLD;
|
|
|
|
|
} break;
|
|
|
|
|
case PLAYER_ACTION_CHECK: {
|
|
|
|
|
myActionLog = LOG_ACTION_CHECK;
|
|
|
|
|
} break;
|
|
|
|
|
case PLAYER_ACTION_CALL: {
|
|
|
|
|
myActionLog = LOG_ACTION_CALL;
|
|
|
|
|
} break;
|
|
|
|
|
case PLAYER_ACTION_BET:
|
|
|
|
|
case PLAYER_ACTION_RAISE: {
|
|
|
|
|
myActionLog = LOG_ACTION_BET;
|
|
|
|
|
} break;
|
|
|
|
|
case PLAYER_ACTION_ALLIN: {
|
|
|
|
|
myActionLog = LOG_ACTION_ALL_IN;
|
|
|
|
|
} break;
|
|
|
|
|
default: {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(myActionLog) {
|
|
|
|
|
// myHand->getLog()->logPlayerAction(myBeRoID+1,(*currentPlayersTurnIt)->getMyID()+1,myActionLog);
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-07 00:05:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|