1 /*****************************************************************************
2  * PokerTH - The open source texas holdem engine                             *
3  * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May          *
4  *                                                                           *
5  * This program is free software: you can redistribute it and/or modify      *
6  * it under the terms of the GNU Affero General Public License as            *
7  * published by the Free Software Foundation, either version 3 of the        *
8  * License, or (at your option) any later version.                           *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU Affero General Public License for more details.                       *
14  *                                                                           *
15  * You should have received a copy of the GNU Affero General Public License  *
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.     *
17  *                                                                           *
18  *                                                                           *
19  * Additional permission under GNU AGPL version 3 section 7                  *
20  *                                                                           *
21  * If you modify this program, or any covered work, by linking or            *
22  * combining it with the OpenSSL project's OpenSSL library (or a             *
23  * modified version of that library), containing parts covered by the        *
24  * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH           *
25  * (Felix Hammer, Florian Thauer, Lothar May) grant you additional           *
26  * permission to convey the resulting work.                                  *
27  * Corresponding Source for a non-source form of such a combination          *
28  * shall include the source code for the parts of OpenSSL used as well       *
29  * as that of the covered work.                                              *
30  *****************************************************************************/
31 
32 #include "localhand.h"
33 #include "tools.h"
34 #include "cardsvalue.h"
35 #include <game_defs.h>
36 #include <core/loghelper.h>
37 
38 #include "localexception.h"
39 #include "engine_msg.h"
40 
41 #include <iostream>
42 
43 using namespace std;
44 
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)45 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)
46 	: 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),
47 	  cardsShown(false)
48 {
49 
50 	int i, j, k;
51 	PlayerListIterator it;
52 
53 	for(it=seatsList->begin(); it!=seatsList->end(); ++it) {
54 		(*it)->setHand(this);
55 		// set myFlipCards 0
56 		(*it)->setMyCardsFlip(0, 0);
57 	}
58 
59 	// generate cards and assign to board and player
60 	const int NumCards = 52;
61 	int cardsArray[NumCards] = {
62 		0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
63 		10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
64 		20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
65 		30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
66 		40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
67 		50, 51
68 	};
69 	Tools::ShuffleArrayNonDeterministic(cardsArray, NumCards);
70 	int tempBoardArray[5];
71 	int tempPlayerArray[2];
72 	int tempPlayerAndBoardArray[7];
73 	int bestHandPos[5];
74 	int sBluff;
75 	for(i=0; i<5; i++) {
76 		tempBoardArray[i] = cardsArray[i];
77 		tempPlayerAndBoardArray[i+2] = cardsArray[i];
78 	}
79 
80 	k = 0;
81 	myBoard->setMyCards(tempBoardArray);
82 	for(it=activePlayerList->begin(); it!=activePlayerList->end(); ++it, k++) {
83 
84 		(*it)->getMyBestHandPosition(bestHandPos);
85 
86 		for(j=0; j<2; j++) {
87 			tempPlayerArray[j] = cardsArray[2*k+j+5];
88 			tempPlayerAndBoardArray[j] = cardsArray[2*k+j+5];
89 		}
90 
91 		(*it)->setMyCards(tempPlayerArray);
92 		(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray, bestHandPos));
93 		(*it)->setMyBestHandPosition(bestHandPos);
94 		(*it)->setMyRoundStartCash((*it)->getMyCash());
95 
96 		// error-check
97 		for(j=0; j<5; j++) {
98 			if (bestHandPos[j] == -1) {
99 				LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR getMyBestHandPosition");
100 			}
101 		}
102 
103 		// set sBluff for all players --> TODO for ai-player in internet
104 		if((*it)->getMyID() != 0) {
105 			Tools::GetRand(1, 100, 1, &sBluff);
106 			(*it)->setSBluff(sBluff);
107 			(*it)->setSBluffStatus(0);
108 		}
109 	}
110 
111 	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!   DEBUGGER   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
112 
113 	if(DEBUG_MODE) {
114 
115 		//QSqlDatabase *mySqliteLogDb;
116 
117 
118 
119 		// myGui->getMyW()->getSession();
120 
121 		//QSqlDatabase * test = myGui->getMyLog()->getMySqliteLogDb();
122 
123 //           if(!mySqliteLogDb->open()) {
124 //               MyMessageBox::critical(0, tr("ERROR"),mySqliteLogDb->lastError().text().toUtf8().c_str(), QMessageBox::Cancel);
125 //           }
126 
127 
128 
129 		int temp5Array[5];
130 
131 		switch(myID) {
132 
133 		case 1: {
134 
135 			tempBoardArray[0] = 4;
136 			tempBoardArray[1] = 19;
137 			tempBoardArray[2] = 20;
138 			tempBoardArray[3] = 43;
139 			tempBoardArray[4] = 49;
140 
141 			myBoard->setMyCards(tempBoardArray);
142 
143 			tempPlayerAndBoardArray[2] = tempBoardArray[0];
144 			tempPlayerAndBoardArray[3] = tempBoardArray[1];
145 			tempPlayerAndBoardArray[4] = tempBoardArray[2];
146 			tempPlayerAndBoardArray[5] = tempBoardArray[3];
147 			tempPlayerAndBoardArray[6] = tempBoardArray[4];
148 
149 			// player0
150 			it = seatsList->begin();
151 
152 			tempPlayerArray[0] = 18;
153 			tempPlayerArray[1] = 17;
154 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
155 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
156 
157 			(*it)->setMyCards(tempPlayerArray);
158 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
159 
160 			(*it)->setMyBestHandPosition(temp5Array);
161 
162 			// player1
163 			++it;
164 
165 			tempPlayerArray[0] = 31;
166 			tempPlayerArray[1] = 8;
167 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
168 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
169 
170 			(*it)->setMyCards(tempPlayerArray);
171 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
172 
173 			(*it)->setMyBestHandPosition(temp5Array);
174 
175 			// player2
176 			++it;
177 
178 			tempPlayerArray[0] = 26;
179 			tempPlayerArray[1] = 27;
180 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
181 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
182 
183 			(*it)->setMyCards(tempPlayerArray);
184 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
185 
186 			(*it)->setMyBestHandPosition(temp5Array);
187 
188 			// player3
189 			++it;
190 
191 			tempPlayerArray[0] = 31;
192 			tempPlayerArray[1] = 30;
193 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
194 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
195 
196 			(*it)->setMyCards(tempPlayerArray);
197 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
198 
199 			(*it)->setMyBestHandPosition(temp5Array);
200 
201 			// player4
202 			++it;
203 
204 			tempPlayerArray[0] = 50;
205 			tempPlayerArray[1] = 51;
206 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
207 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
208 
209 			(*it)->setMyCards(tempPlayerArray);
210 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
211 
212 			(*it)->setMyBestHandPosition(temp5Array);
213 
214 			// player5
215 			++it;
216 
217 			tempPlayerArray[0] = 25;
218 			tempPlayerArray[1] = 24;
219 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
220 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
221 
222 			(*it)->setMyCards(tempPlayerArray);
223 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
224 
225 			(*it)->setMyBestHandPosition(temp5Array);
226 
227 			// player6
228 			++it;
229 
230 			tempPlayerArray[0] = 38;
231 			tempPlayerArray[1] = 37;
232 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
233 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
234 
235 			(*it)->setMyCards(tempPlayerArray);
236 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
237 
238 			(*it)->setMyBestHandPosition(temp5Array);
239 
240 			// player7
241 			++it;
242 
243 			tempPlayerArray[0] = 32;
244 			tempPlayerArray[1] = 33;
245 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
246 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
247 
248 			(*it)->setMyCards(tempPlayerArray);
249 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
250 
251 			(*it)->setMyBestHandPosition(temp5Array);
252 
253 			// player8
254 			++it;
255 
256 			tempPlayerArray[0] = 19;
257 			tempPlayerArray[1] = 20;
258 			tempPlayerAndBoardArray[0] = tempPlayerArray[0];
259 			tempPlayerAndBoardArray[1] = tempPlayerArray[1];
260 
261 			(*it)->setMyCards(tempPlayerArray);
262 			(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
263 
264 			(*it)->setMyBestHandPosition(temp5Array);
265 
266 
267 		}
268 		break;
269 		case 2: {
270 
271 			/*				tempBoardArray[0] = 48;
272 							tempBoardArray[1] = 21;
273 							tempBoardArray[2] = 4;
274 							tempBoardArray[3] = 9;
275 							tempBoardArray[4] = 0;
276 
277 							myBoard->setMyCards(tempBoardArray);
278 
279 							tempPlayerAndBoardArray[2] = tempBoardArray[0];
280 							tempPlayerAndBoardArray[3] = tempBoardArray[1];
281 							tempPlayerAndBoardArray[4] = tempBoardArray[2];
282 							tempPlayerAndBoardArray[5] = tempBoardArray[3];
283 							tempPlayerAndBoardArray[6] = tempBoardArray[4];*/
284 
285 			// player0
286 			it = seatsList->begin();
287 
288 // 				tempPlayerArray[0] = 9;
289 // 				tempPlayerArray[1] = 5;
290 // 				tempPlayerAndBoardArray[0] = tempPlayerArray[0];
291 // 				tempPlayerAndBoardArray[1] = tempPlayerArray[1];
292 //
293 // 				(*it)->setMyCards(tempPlayerArray);
294 // 				(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
295 //
296 // 				(*it)->setMyBestHandPosition(temp5Array);
297 
298 			// player1
299 			++it;
300 
301 // 				tempPlayerArray[0] = 47;
302 // 				tempPlayerArray[1] = 22;
303 // 				tempPlayerAndBoardArray[0] = tempPlayerArray[0];
304 // 				tempPlayerAndBoardArray[1] = tempPlayerArray[1];
305 //
306 // 				(*it)->setMyCards(tempPlayerArray);
307 // 				(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
308 //
309 // 				(*it)->setMyBestHandPosition(temp5Array);
310 
311 			// player2
312 			++it;
313 
314 // 				tempPlayerArray[0] = 33;
315 // 				tempPlayerArray[1] = 27;
316 // 				tempPlayerAndBoardArray[0] = tempPlayerArray[0];
317 // 				tempPlayerAndBoardArray[1] = tempPlayerArray[1];
318 //
319 // 				(*it)->setMyCards(tempPlayerArray);
320 // 				(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
321 //
322 // 				(*it)->setMyBestHandPosition(temp5Array);
323 
324 			// player3
325 			++it;
326 
327 // 				tempPlayerArray[0] = 38;
328 // 				tempPlayerArray[1] = 22;
329 // 				tempPlayerAndBoardArray[0] = tempPlayerArray[0];
330 // 				tempPlayerAndBoardArray[1] = tempPlayerArray[1];
331 //
332 // 				(*it)->setMyCards(tempPlayerArray);
333 // 				(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
334 //
335 // 				(*it)->setMyBestHandPosition(temp5Array);
336 
337 			// player4
338 			++it;
339 
340 // 				tempPlayerArray[0] = 25;
341 // 				tempPlayerArray[1] = 16;
342 // 				tempPlayerAndBoardArray[0] = tempPlayerArray[0];
343 // 				tempPlayerAndBoardArray[1] = tempPlayerArray[1];
344 //
345 // 				(*it)->setMyCards(tempPlayerArray);
346 // 				(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
347 //
348 // 				(*it)->setMyBestHandPosition(temp5Array);
349 
350 			// player5
351 			++it;
352 
353 // 				tempPlayerArray[0] = 27;
354 // 				tempPlayerArray[1] = 10;
355 // 				tempPlayerAndBoardArray[0] = tempPlayerArray[0];
356 // 				tempPlayerAndBoardArray[1] = tempPlayerArray[1];
357 //
358 // 				(*it)->setMyCards(tempPlayerArray);
359 // 				(*it)->setMyCardsValueInt(CardsValue::cardsValue(tempPlayerAndBoardArray,temp5Array));
360 //
361 // 				(*it)->setMyBestHandPosition(temp5Array);
362 
363 		}
364 		break;
365 		default: {
366 		}
367 
368 		}
369 
370 
371 
372 	}
373 // ----------------------------------------
374 
375 	// determine dealer, SB, BB
376 
377 	assignButtons();
378 
379 	setBlinds();
380 
381 	if(myLog) myLog->logNewHandMsg(myID, dealerPosition+1, smallBlind, smallBlindPosition+1, 2*smallBlind, bigBlindPosition+1, seatsList);
382 
383 	myBeRo = myFactory->createBeRo(this, dealerPosition, smallBlind);
384 }
385 
386 
387 
~LocalHand()388 LocalHand::~LocalHand()
389 {
390 }
391 
start()392 void LocalHand::start()
393 {
394 
395 	//Log blinds sets for new Hand
396 	PlayerListConstIterator it_sB, it_bB;
397 	it_sB = getActivePlayerIt(getCurrentBeRo()->getSmallBlindPositionId());
398 	it_bB = getActivePlayerIt(getCurrentBeRo()->getBigBlindPositionId());
399 	if(it_sB != getActivePlayerList()->end() && it_bB != getActivePlayerList()->end()) {
400 		myGui->logNewBlindsSetsMsg((*it_sB)->getMySet(), (*it_bB)->getMySet(), (*it_sB)->getMyName().c_str(), (*it_bB)->getMyName().c_str());
401 	} else {
402 		LOG_ERROR(__FILE__ << " (" << __LINE__ << "): Log Error: cannot find sBID or bBID");
403 	}
404 	myGui->flushLogAtHand();
405 
406 	// deal cards
407 	myGui->dealHoleCards();
408 
409 	getBoard()->collectSets();
410 	getGuiInterface()->refreshPot();
411 
412 	// change rounds | first start preflop
413 	myGui->nextPlayerAnimation();
414 }
415 
assignButtons()416 void LocalHand::assignButtons()
417 {
418 
419 	size_t i;
420 	PlayerListIterator it;
421 
422 	// delete all buttons
423 	for (it=seatsList->begin(); it!=seatsList->end(); ++it) {
424 		(*it)->setMyButton(BUTTON_NONE);
425 	}
426 
427 	// assign dealer button
428 	it = getSeatIt(dealerPosition);
429 	if(it == seatsList->end()) {
430 		throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND);
431 	}
432 	(*it)->setMyButton(BUTTON_DEALER);
433 
434 
435 	// assign Small Blind next to dealer. ATTENTION: in heads up it is big blind
436 	// assign big blind next to small blind. ATTENTION: in heads up it is small blind
437 	bool nextActivePlayerFound = false;
438 	PlayerListIterator dealerPositionIt = getSeatIt(dealerPosition);
439 	if(dealerPositionIt == seatsList->end()) {
440 		throw LocalException(__FILE__, __LINE__, ERR_SEAT_NOT_FOUND);
441 	}
442 
443 	for(i=0; i<seatsList->size(); i++) {
444 
445 		++dealerPositionIt;
446 		if(dealerPositionIt == seatsList->end()) dealerPositionIt = seatsList->begin();
447 
448 		it = getActivePlayerIt( (*dealerPositionIt)->getMyUniqueID() );
449 		if(it != activePlayerList->end() ) {
450 			nextActivePlayerFound = true;
451 			if(activePlayerList->size() > 2) {
452 				//small blind normal
453 				(*it)->setMyButton(2);
454 				smallBlindPosition = (*it)->getMyUniqueID();
455 			} else {
456 				//big blind in heads up
457 				(*it)->setMyButton(3);
458 				bigBlindPosition = (*it)->getMyUniqueID();
459 				// lastPlayerAction for showing cards
460 			}
461 
462 			// first player after dealer have to show his cards first (in showdown)
463 			lastActionPlayerID = (*it)->getMyUniqueID();
464 			myBoard->setLastActionPlayerID(lastActionPlayerID);
465 
466 			++it;
467 			if(it == activePlayerList->end()) it = activePlayerList->begin();
468 
469 			if(activePlayerList->size() > 2) {
470 				//big blind normal
471 				(*it)->setMyButton(3);
472 				bigBlindPosition = (*it)->getMyUniqueID();
473 			} else {
474 				//small blind in heads up
475 				(*it)->setMyButton(2);
476 				smallBlindPosition = (*it)->getMyUniqueID();
477 			}
478 
479 			break;
480 		}
481 
482 	}
483 	if(!nextActivePlayerFound) {
484 		throw LocalException(__FILE__, __LINE__, ERR_NEXT_ACTIVE_PLAYER_NOT_FOUND);
485 	}
486 
487 //        cout << "lAP-Button: " << lastActionPlayer << endl;
488 }
489 
setBlinds()490 void LocalHand::setBlinds()
491 {
492 
493 	PlayerListConstIterator it_c;
494 
495 	//do sets --> TODO switch?
496 	for (it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); ++it_c) {
497 
498 		//small blind
499 		if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND) {
500 
501 			// All in ?
502 			if((*it_c)->getMyCash() <= smallBlind) {
503 
504 				(*it_c)->setMySet((*it_c)->getMyCash());
505 				// 1 to do not log this
506 				(*it_c)->setMyAction(PLAYER_ACTION_ALLIN);
507 
508 			} else {
509 				(*it_c)->setMySet(smallBlind);
510 			}
511 		}
512 
513 	}
514 
515 	//do sets --> TODO switch?
516 	for (it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); ++it_c) {
517 
518 		//big blind
519 		if((*it_c)->getMyButton() == BUTTON_BIG_BLIND) {
520 
521 			// all in ?
522 			if((*it_c)->getMyCash() <= 2*smallBlind) {
523 
524 				(*it_c)->setMySet((*it_c)->getMyCash());
525 				// 1 to do not log this
526 				(*it_c)->setMyAction(PLAYER_ACTION_ALLIN);
527 
528 			} else {
529 				(*it_c)->setMySet(2*smallBlind);
530 			}
531 		}
532 	}
533 }
534 
535 
switchRounds()536 void LocalHand::switchRounds()
537 {
538 
539 	// logging last player action
540 	PlayerListConstIterator previousPlayerIt = getRunningPlayerIt(previousPlayerID);
541 	if(previousPlayerIt != runningPlayerList->end()) {
542 		if(myLog) myLog->logPlayerAction((*previousPlayerIt)->getMyName(),myLog->transformPlayerActionLog((*previousPlayerIt)->getMyAction()),(*previousPlayerIt)->getMyLastRelativeSet());
543 	}
544 
545 	PlayerListIterator it, it_1;
546 	PlayerListConstIterator it_c;
547 
548 	// refresh runningPlayerList
549 	for(it=runningPlayerList->begin(); it!=runningPlayerList->end(); ) {
550 		if((*it)->getMyAction() == PLAYER_ACTION_FOLD || (*it)->getMyAction() == PLAYER_ACTION_ALLIN) {
551 
552 			it = runningPlayerList->erase(it);
553 			if(!(runningPlayerList->empty())) {
554 
555 				it_1 = it;
556 				if(it_1 == runningPlayerList->begin()) it_1 = runningPlayerList->end();
557 				--it_1;
558 				getCurrentBeRo()->setCurrentPlayersTurnId((*it_1)->getMyUniqueID());
559 
560 			}
561 		} else {
562 			++it;
563 		}
564 	}
565 
566 	// determine number of all in players
567 	int allInPlayersCounter = 0;
568 	for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
569 		if ((*it_c)->getMyAction() == PLAYER_ACTION_ALLIN) allInPlayersCounter++;
570 	}
571 
572 	// determine number of non-fold players
573 	int nonFoldPlayerCounter = 0;
574 	for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
575 		if ((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) nonFoldPlayerCounter++;
576 	}
577 
578 	// if only one player non-fold -> distribute pot
579 	if(nonFoldPlayerCounter==1) {
580 		myBoard->collectPot();
581 		myGui->refreshPot();
582 		myGui->refreshSet();
583 		currentRound = GAME_STATE_POST_RIVER;
584 		if(myLog) myLog->setCurrentRound(currentRound);
585 	}
586 
587 	// check for all in condition
588 	// for all in condition at least two active players have to remain
589 	else {
590 
591 		// 1) all players all in
592 		if(allInPlayersCounter == nonFoldPlayerCounter) {
593 			allInCondition = true;
594 			myBoard->setAllInCondition(true);
595 		}
596 
597 		// 2) all players but one all in and he has highest set
598 		if(allInPlayersCounter+1 == nonFoldPlayerCounter) {
599 
600 			for(it_c=runningPlayerList->begin(); it_c!=runningPlayerList->end(); ++it_c) {
601 
602 				if((*it_c)->getMySet() >= myBeRo[currentRound]->getHighestSet()) {
603 					allInCondition = true;
604 					myBoard->setAllInCondition(true);
605 				}
606 
607 			}
608 
609 			// exception
610 			// 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
611 			PlayerListConstIterator smallBlindIt_c = getRunningPlayerIt(myBeRo[currentRound]->getSmallBlindPositionId());
612 			PlayerListConstIterator bigBlindIt_c = getActivePlayerIt(myBeRo[currentRound]->getBigBlindPositionId());
613 			if(smallBlindIt_c!=runningPlayerList->end() &&  bigBlindIt_c!=activePlayerList->end() && currentRound == GAME_STATE_PREFLOP && myBeRo[currentRound]->getFirstRound()) {
614 				// determine player who are all in with less than small blind amount
615 				int tempCounter = 0;
616 				for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
617 					if((*it_c)->getMyAction() == PLAYER_ACTION_ALLIN && (*it_c)->getMySet() <= smallBlind) {
618 						tempCounter++;
619 					}
620 				}
621 				if( (*bigBlindIt_c)->getMySet() <= smallBlind  && tempCounter == allInPlayersCounter) {
622 					allInCondition = true;
623 					myBoard->setAllInCondition(true);
624 				}
625 			}
626 
627 			// no.2: heads up -> detect player who is all in and bb but could set less than sb
628 			for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) {
629 
630 				if(activePlayerList->size()==2 && (*it_c)->getMyAction() == PLAYER_ACTION_ALLIN && (*it_c)->getMyButton()==BUTTON_BIG_BLIND && (*it_c)->getMySet()<=smallBlind && currentRound == GAME_STATE_PREFLOP) {
631 					allInCondition = true;
632 					myBoard->setAllInCondition(true);
633 				}
634 			}
635 		}
636 	}
637 
638 	// special routine
639 	if(allInCondition) {
640 		myBoard->collectPot();
641 		myGui->refreshPot();
642 		myGui->refreshSet();
643 		myGui->flipHolecardsAllIn();
644 		// Logging HoleCards
645 		if(currentRound<GAME_STATE_RIVER) {
646 			if(myLog) myLog->logHoleCardsHandName(activePlayerList);
647 		}
648 
649 		if (currentRound < GAME_STATE_POST_RIVER) { // do not increment past 4
650 			currentRound = GameState(currentRound + 1);
651 			if(myLog) myLog->setCurrentRound(currentRound);
652 		}
653 
654 		//log board cards for allin
655 		if(currentRound >= GAME_STATE_FLOP) {
656 			int tempBoardCardsArray[5];
657 
658 			myBoard->getMyCards(tempBoardCardsArray);
659 			myGui->logDealBoardCardsMsg(currentRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]);
660 			if(myLog) myLog->logBoardCards(tempBoardCardsArray);
661 		}
662 
663 	}
664 
665 	//unhighlight current players groupbox
666 	it_c = getActivePlayerIt(previousPlayerID);
667 	if( it_c != activePlayerList->end() ) {
668 		// lastPlayersTurn is active
669 		myGui->refreshGroupbox(previousPlayerID,1);
670 	}
671 
672 	myGui->refreshGameLabels((GameState)getCurrentRound());
673 
674 	if(currentRound < GAME_STATE_POST_RIVER) {
675 		roundBeforePostRiver = currentRound;
676 	}
677 
678 	switch(currentRound) {
679 	case GAME_STATE_PREFLOP: {
680 		myGui->preflopAnimation1();
681 	}
682 	break;
683 	case GAME_STATE_FLOP: {
684 		myGui->flopAnimation1();
685 	}
686 	break;
687 	case GAME_STATE_TURN: {
688 		myGui->turnAnimation1();
689 	}
690 	break;
691 	case GAME_STATE_RIVER: {
692 		myGui->riverAnimation1();
693 	}
694 	break;
695 	case GAME_STATE_POST_RIVER: {
696 		myGui->postRiverAnimation1();
697 	}
698 	break;
699 	default: {
700 	}
701 
702 	}
703 
704 }
705 
getSeatIt(unsigned uniqueId) const706 PlayerListIterator LocalHand::getSeatIt(unsigned uniqueId) const
707 {
708 
709 	PlayerListIterator it;
710 
711 	for(it=seatsList->begin(); it!=seatsList->end(); ++it) {
712 		if((*it)->getMyUniqueID() == uniqueId) {
713 			break;
714 		}
715 	}
716 
717 	return it;
718 
719 }
720 
getActivePlayerIt(unsigned uniqueId) const721 PlayerListIterator LocalHand::getActivePlayerIt(unsigned uniqueId) const
722 {
723 
724 	PlayerListIterator it;
725 
726 	for(it=activePlayerList->begin(); it!=activePlayerList->end(); ++it) {
727 		if((*it)->getMyUniqueID() == uniqueId) {
728 			break;
729 		}
730 	}
731 
732 	return it;
733 
734 }
735 
getRunningPlayerIt(unsigned uniqueId) const736 PlayerListIterator LocalHand::getRunningPlayerIt(unsigned uniqueId) const
737 {
738 
739 	PlayerListIterator it;
740 
741 	for(it=runningPlayerList->begin(); it!=runningPlayerList->end(); ++it) {
742 
743 		if((*it)->getMyUniqueID() == uniqueId) {
744 			break;
745 		}
746 	}
747 
748 	return it;
749 
750 }
751 
setLastActionPlayerID(unsigned theValue)752 void LocalHand::setLastActionPlayerID(unsigned theValue)
753 {
754 	lastActionPlayerID = theValue;
755 	myBoard->setLastActionPlayerID(theValue);
756 }
757