Files
pokerth/src/engine/local_engine/localhand.cpp
T

387 lines
11 KiB
C++
Raw Normal View History

2007-01-13 02:40:33 +00:00
/***************************************************************************
* 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. *
***************************************************************************/
#include "localhand.h"
#include <game_defs.h>
2007-01-13 02:40:33 +00:00
using namespace std;
2007-03-09 03:53:39 +00:00
LocalHand::LocalHand(EngineFactory *f, GuiInterface *g, BoardInterface *b, PlayerInterface **p, int id, int sP, int aP, int dP, int sB,int sC) : HandInterface(), myFactory(f), myGui(g), myBoard(b), playerArray(p), myPreflop(0), myFlop(0), myTurn(0), myRiver(0), myID(id), actualQuantityPlayers(aP), startQuantityPlayers(sP), dealerPosition(dP), actualRound(0), smallBlind(sB), startCash(sC), allInCondition(0), bettingRoundsPlayed(0)
2007-01-13 02:40:33 +00:00
{
2007-01-28 00:17:49 +00:00
int i, j, k;
2007-03-29 22:58:04 +00:00
lastPlayersTurn = 0;
2007-01-13 02:40:33 +00:00
CardsValue myCardsValue;
myBoard->setHand(this);
for(i=0; i<startQuantityPlayers; i++) {
if(playerArray[i]->getMyActiveStatus() != 0) {
playerArray[i]->setHand(this);
}
}
2007-01-13 02:40:33 +00:00
// roundStartCashArray fllen
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash());
}
// Dealer, SB, BB bestimmen
assignButtons();
2007-03-29 22:58:04 +00:00
// myGui->refreshAll();
2007-01-13 02:40:33 +00:00
// Karten generieren und Board sowie Player zuweisen
Tools myTool;
int *cardsArray = new int[2*actualQuantityPlayers+5];
myTool.getRandNumber(0, 51, 2*actualQuantityPlayers+5, cardsArray, 1);
2007-01-13 02:40:33 +00:00
int tempBoardArray[5];
int tempPlayerArray[2];
int tempPlayerAndBoardArray[7];
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
k = 0;
2007-01-13 02:40:33 +00:00
myBoard->setMyCards(tempBoardArray);
for(i=0; i<startQuantityPlayers; i++) {
if(playerArray[i]->getMyActiveStatus() != 0) {
for(j=0; j<2; j++) {
tempPlayerArray[j] = cardsArray[2*k+j+5];
tempPlayerAndBoardArray[j] = cardsArray[2*k+j+5];
2007-01-28 00:17:49 +00:00
}
playerArray[i]->setMyCards(tempPlayerArray);
playerArray[i]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray,playerArray[i]->getMyBestHandPosition()));
2007-03-30 12:44:16 +00:00
// myBestHandPosition auf Fehler ueberpruefen
for(j=0; j<5; j++) {
if((playerArray[i]->getMyBestHandPosition())[j] == -1) {
2007-03-30 12:44:16 +00:00
cout << "ERROR get myBestHandPosition in localhand.cpp" << endl;
}
}
2007-03-30 12:44:16 +00:00
// sBluff für alle aktiver Spieler außer human player setzen
if(i) {
myTool.getRandNumber(1,100,1,&sBluff,0);
playerArray[i]->setSBluff(sBluff);
2007-03-30 13:03:04 +00:00
playerArray[i]->setSBluffStatus(0);
2007-03-30 12:44:16 +00:00
}
k++;
2007-01-28 00:17:49 +00:00
}
2007-01-13 02:40:33 +00:00
}
2007-04-30 11:53:40 +00:00
// // // !!!!!!!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
// // int *temp5Array;
// //
// // tempBoardArray[0] = 2;
// // tempBoardArray[1] = 15;
// // tempBoardArray[2] = 4;
// // tempBoardArray[3] = 28;
// // tempBoardArray[4] = 17;
// //
// // myBoard->setMyCards(tempBoardArray);
// //
// // tempPlayerAndBoardArray[2] = 2;
// // tempPlayerAndBoardArray[3] = 15;
// // tempPlayerAndBoardArray[4] = 4;
// // tempPlayerAndBoardArray[5] = 28;
// // tempPlayerAndBoardArray[6] = 17;
// //
// // tempPlayerArray[0] = 0;
// // tempPlayerArray[1] = 5;
// // tempPlayerAndBoardArray[0] = 0;
// // tempPlayerAndBoardArray[1] = 5;
// //
// // playerArray[0]->setMyCards(tempPlayerArray);
// // playerArray[0]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray,playerArray[0]->getMyBestHandPosition()));
// //
// // temp5Array = playerArray[0]->getMyBestHandPosition();
// //
// // for(i=0; i<5; i++) {
// // cout << temp5Array[i] << " ";
// // }
// // cout << endl;
// //
// // tempPlayerArray[0] = 12;
// // tempPlayerArray[1] = 24;
// // tempPlayerAndBoardArray[0] = 12;
// // tempPlayerAndBoardArray[1] = 24;
// //
// // playerArray[1]->setMyCards(tempPlayerArray);
// // playerArray[1]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray,playerArray[1]->getMyBestHandPosition()));
// //
// // tempPlayerArray[0] = 25;
// // tempPlayerArray[1] = 35;
// // tempPlayerAndBoardArray[0] = 25;
// // tempPlayerAndBoardArray[1] = 35;
// //
// // playerArray[2]->setMyCards(tempPlayerArray);
// // playerArray[2]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray,playerArray[2]->getMyBestHandPosition()));
// //
// // tempPlayerArray[0] = 51;
// // tempPlayerArray[1] = 33;
// // tempPlayerAndBoardArray[0] = 25;
// // tempPlayerAndBoardArray[1] = 35;
// //
// // playerArray[3]->setMyCards(tempPlayerArray);
// // playerArray[3]->setMyCardsValueInt(myCardsValue.cardsValue(tempPlayerAndBoardArray,playerArray[3]->getMyBestHandPosition()));
// // // seven-two, the others have Ace-King, Ace-Jack, Ace-Nine. The pot is obviously split.
/////////////////////
2007-01-13 02:40:33 +00:00
// Karten austeilen
2007-01-13 14:27:56 +00:00
myGui->dealHoleCards();
2007-01-13 02:40:33 +00:00
2007-02-28 20:51:43 +00:00
// myFlipCards auf 0 setzen
for(i=0; i<startQuantityPlayers; i++) {
2007-02-28 20:51:43 +00:00
playerArray[i]->setMyCardsFlip(0);
}
2007-01-13 02:40:33 +00:00
// Preflop, Flop, Turn und River erstellen
myPreflop = myFactory->createPreflop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
myFlop = myFactory->createFlop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
myTurn = myFactory->createTurn(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
myRiver = myFactory->createRiver(this, myID, actualQuantityPlayers, dealerPosition, smallBlind);
2007-01-13 02:40:33 +00:00
//Rundenwechsel | beim ersten Durchlauf --> Preflop starten
myGui->nextPlayerAnimation();
delete[] cardsArray;
2007-01-13 02:40:33 +00:00
}
LocalHand::~LocalHand()
{
delete myPreflop;
myPreflop = 0;
delete myFlop;
myFlop = 0;
delete myTurn;
myTurn = 0;
delete myRiver;
myRiver = 0;
}
void LocalHand::assignButtons() {
int i;
// alle Buttons loeschen
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { playerArray[i]->setMyButton(0); }
2007-01-13 02:40:33 +00:00
// DealerButton zuweisen
playerArray[dealerPosition]->setMyButton(1);
// Small Blind zuweisen und setzen
i = dealerPosition;
do {
i = (i+1)%(MAX_NUMBER_OF_PLAYERS);
2007-01-13 02:40:33 +00:00
if(playerArray[i]->getMyActiveStatus()) {
playerArray[i]->setMyButton(2);
// mit SmallBlind All In ?
if(playerArray[i]->getMyCash() <= smallBlind) {
playerArray[i]->setMySet(playerArray[i]->getMyCash());
playerArray[i]->setMyAction(6);
}
// sonst
else {
playerArray[i]->setMySet(smallBlind);
}
}
} while(!(playerArray[i]->getMyActiveStatus()));
// Big Blind zuweisen
do {
i = (i+1)%(MAX_NUMBER_OF_PLAYERS);
2007-01-13 02:40:33 +00:00
if(playerArray[i]->getMyActiveStatus()) {
playerArray[i]->setMyButton(3);
// mit BigBlind All In ?
if(playerArray[i]->getMyCash() <= 2*smallBlind) {
playerArray[i]->setMySet(playerArray[i]->getMyCash());
playerArray[i]->setMyAction(6);
}
// sonst
else {
playerArray[i]->setMySet(2*smallBlind);
}
}
} while(!(playerArray[i]->getMyActiveStatus()));
}
void LocalHand::switchRounds() {
int i;
2007-04-03 10:55:16 +00:00
// cout <<" ------- HandID: " << myID << " | actualround: " << actualRound << " ---------" << endl;
2007-01-13 02:40:33 +00:00
//Aktive Spieler zlen --> wenn nur noch einer nicht-folded dann gleich den Pot verteilen
activePlayersCounter = 0;
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
if (playerArray[i]->getMyAction() != 1 && playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++;
}
// Anzahl der Spieler ermitteln, welche All In sind
int allInPlayersCounter = 0;
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
if (playerArray[i]->getMyAction() == 6) allInPlayersCounter++;
}
if(activePlayersCounter==1) {
myBoard->collectPot();
2007-01-13 14:27:56 +00:00
myGui->refreshPot();
2007-01-13 02:40:33 +00:00
myGui->refreshSet();
actualRound = 4;
}
// prfen der All In Kondition
// fr All In Prozedur mssen mindestens zwei aktive Player vorhanden sein
else {
2007-04-03 10:55:16 +00:00
// cout << "activplayerscounter: " << activePlayersCounter << " | allInPlayersCounter: " << allInPlayersCounter << " | " << endl;
2007-01-13 02:40:33 +00:00
// 1) wenn alle All In
if(allInPlayersCounter == activePlayersCounter) {
2007-01-13 16:54:08 +00:00
allInCondition = 1;
2007-01-13 02:40:33 +00:00
}
// 2) alle bis auf einen All In und der hat HighestSet
int tempHighestSet;
if(allInPlayersCounter+1 == activePlayersCounter) {
// Spieler ermitteln, der noch nicht All In ist
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
2007-01-13 02:40:33 +00:00
if(playerArray[i]->getMyAction() != 1 && playerArray[i]->getMyAction() != 6 && playerArray[i]->getMyActiveStatus() == 1) {
tempHighestSet = 0;
switch (actualRound) {
case 0: {tempHighestSet = myPreflop->getHighestSet();}
break;
case 1: {tempHighestSet = myFlop->getHighestSet();}
break;
case 2: {tempHighestSet = myTurn->getHighestSet();}
break;
case 3: {tempHighestSet = myRiver->getHighestSet();}
break;
default: {}
}
2007-04-03 10:55:16 +00:00
// cout << "tempHighestSet: " << tempHighestSet << "playerArray[i]->getMySet(): " << playerArray[i]->getMySet() << endl;
2007-01-13 02:40:33 +00:00
if(playerArray[i]->getMySet() >= tempHighestSet) {
2007-01-13 16:54:08 +00:00
allInCondition = 1;
2007-01-13 02:40:33 +00:00
}
}
}
}
}
// beim Vorliegen einer All In Kondition -> Ausfhrung einer Sonderprozedur
if(allInCondition) {
myBoard->collectPot();
2007-01-13 14:27:56 +00:00
myGui->refreshPot();
myGui->refreshSet();
myGui->flipHolecardsAllIn();
2007-01-13 02:40:33 +00:00
actualRound++;
}
2007-03-29 22:58:04 +00:00
//unhighlight actual players groupbox
myGui->refreshGroupbox(lastPlayersTurn,1);
2007-01-13 02:40:33 +00:00
highlightRoundLabel();
// /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl;
//
// cout << "NextPlayerSpeed2 start" << endl;
switch(actualRound) {
case 0: {
// Preflop starten
myGui->preflopAnimation1();
} break;
case 1: {
// Flop starten
myGui->flopAnimation1();
} break;
case 2: {
// Turn starten
myGui->turnAnimation1();
} break;
case 3: {
// River starten
myGui->riverAnimation1();
} break;
case 4: {
// PostRiver starten
myGui->postRiverAnimation1();
} break;
default: {}
}
}
void LocalHand::highlightRoundLabel() {
switch(actualRound) {
case 0: {
2007-01-13 14:27:56 +00:00
myGui->highlightRoundLabel("Preflop");
2007-01-13 02:40:33 +00:00
} break;
case 1: {
2007-01-13 14:27:56 +00:00
myGui->highlightRoundLabel("Flop");
2007-01-13 02:40:33 +00:00
} break;
case 2: {
2007-01-13 14:27:56 +00:00
myGui->highlightRoundLabel("Turn");
2007-01-13 02:40:33 +00:00
} break;
case 3: {
2007-01-13 14:27:56 +00:00
myGui->highlightRoundLabel("River");
2007-01-13 02:40:33 +00:00
} break;
case 4: {
2007-01-13 14:27:56 +00:00
myGui->highlightRoundLabel("");
2007-01-13 02:40:33 +00:00
} break;
default: {
2007-01-13 14:27:56 +00:00
myGui->highlightRoundLabel("!!! FEHLER !!!");
2007-01-13 02:40:33 +00:00
}
}
}