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 "game.h"
|
2007-04-26 23:07:08 +00:00
|
|
|
#include "gamedata.h"
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-05-18 17:13:27 +00:00
|
|
|
#include <enginefactory.h>
|
2007-05-15 20:37:37 +00:00
|
|
|
#include <guiinterface.h>
|
2007-05-18 17:13:27 +00:00
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
2007-01-13 20:47:48 +00:00
|
|
|
|
2007-01-13 02:40:33 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2007-05-18 17:13:27 +00:00
|
|
|
Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
|
2007-05-20 00:16:29 +00:00
|
|
|
const PlayerDataList &playerDataList, const GameData &gameData,
|
|
|
|
|
const StartData &startData, int gameId)
|
2007-05-21 19:52:26 +00:00
|
|
|
: myFactory(factory), myGui(gui), actualHand(0), actualBoard(0),
|
2007-06-11 19:46:18 +00:00
|
|
|
startQuantityPlayers(startData.numberOfPlayers),
|
2007-05-23 22:31:56 +00:00
|
|
|
startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind),
|
2007-04-26 23:07:08 +00:00
|
|
|
startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise),
|
2007-06-11 19:46:18 +00:00
|
|
|
myGameID(gameId), actualQuantityPlayers(startData.numberOfPlayers),
|
2007-05-21 19:00:06 +00:00
|
|
|
actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0)
|
2007-01-13 02:40:33 +00:00
|
|
|
{
|
2007-01-23 00:49:45 +00:00
|
|
|
// cout << "Create Game Object" << "\n";
|
2007-01-13 02:40:33 +00:00
|
|
|
int i;
|
|
|
|
|
|
2007-01-28 21:19:00 +00:00
|
|
|
actualHandID = 0;
|
|
|
|
|
|
2007-08-10 23:16:21 +00:00
|
|
|
// for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
|
|
|
|
// playerArray[i] = 0;
|
|
|
|
|
// }
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-05-21 19:00:06 +00:00
|
|
|
// Dealer Position bestimmen
|
|
|
|
|
PlayerDataList::const_iterator player_i = playerDataList.begin();
|
|
|
|
|
PlayerDataList::const_iterator player_end = playerDataList.end();
|
|
|
|
|
|
2007-05-22 23:27:21 +00:00
|
|
|
bool dealerFound = false;
|
2007-06-15 23:00:11 +00:00
|
|
|
i = 0;
|
2007-05-21 19:00:06 +00:00
|
|
|
while (player_i != player_end)
|
|
|
|
|
{
|
|
|
|
|
if ((*player_i)->GetUniqueId() == startData.startDealerPlayerId)
|
|
|
|
|
{
|
2007-06-15 23:00:11 +00:00
|
|
|
dealerPosition = i;
|
2007-05-22 23:27:21 +00:00
|
|
|
dealerFound = true;
|
2007-05-21 19:00:06 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++player_i;
|
2007-06-15 23:00:11 +00:00
|
|
|
++i;
|
2007-05-21 19:00:06 +00:00
|
|
|
}
|
2007-05-22 23:27:21 +00:00
|
|
|
assert(dealerFound);
|
2007-01-13 02:40:33 +00:00
|
|
|
|
|
|
|
|
// Board erstellen
|
2007-01-13 22:29:17 +00:00
|
|
|
actualBoard = myFactory->createBoard();
|
|
|
|
|
|
2007-01-13 02:40:33 +00:00
|
|
|
|
|
|
|
|
// Player erstellen
|
2007-05-21 19:00:06 +00:00
|
|
|
player_i = playerDataList.begin();
|
|
|
|
|
player_end = playerDataList.end();
|
2007-04-17 07:28:32 +00:00
|
|
|
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
2007-01-19 19:13:59 +00:00
|
|
|
|
2007-04-26 21:11:13 +00:00
|
|
|
string myName;
|
|
|
|
|
string myAvatarFile;
|
2007-05-08 06:45:46 +00:00
|
|
|
unsigned uniqueId = 0;
|
|
|
|
|
PlayerType type = PLAYER_TYPE_COMPUTER;
|
2007-05-13 22:25:59 +00:00
|
|
|
boost::shared_ptr<SessionData> myNetSession;
|
2007-04-26 21:11:13 +00:00
|
|
|
|
|
|
|
|
if (player_i != player_end)
|
|
|
|
|
{
|
2007-05-08 06:45:46 +00:00
|
|
|
uniqueId = (*player_i)->GetUniqueId();
|
|
|
|
|
type = (*player_i)->GetType();
|
2007-04-26 21:11:13 +00:00
|
|
|
myName = (*player_i)->GetName();
|
|
|
|
|
myAvatarFile = (*player_i)->GetAvatarFile();
|
2007-05-13 22:25:59 +00:00
|
|
|
myNetSession = (*player_i)->GetNetSessionData();
|
2007-04-26 21:11:13 +00:00
|
|
|
// TODO: set player type
|
|
|
|
|
++player_i;
|
|
|
|
|
}
|
2007-01-19 19:13:59 +00:00
|
|
|
|
2007-01-22 22:25:58 +00:00
|
|
|
//PlayerObjekte erzeugen
|
2007-08-10 23:16:21 +00:00
|
|
|
playerArray.push_back(myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// playerArray[i] = myFactory->createPlayer(actualBoard, i, uniqueId, type, myName, myAvatarFile, startCash, startQuantityPlayers > i, 0);
|
2007-05-13 22:25:59 +00:00
|
|
|
playerArray[i]->setNetSessionData(myNetSession);
|
2007-01-13 02:40:33 +00:00
|
|
|
}
|
|
|
|
|
actualBoard->setPlayer(playerArray);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Game::~Game()
|
|
|
|
|
{
|
2007-01-23 00:49:45 +00:00
|
|
|
// cout << "Delete Game Object" << "\n";
|
2007-01-13 02:40:33 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
delete actualBoard;
|
|
|
|
|
actualBoard = 0;
|
|
|
|
|
delete actualHand;
|
|
|
|
|
actualHand = 0;
|
|
|
|
|
|
2007-08-10 23:16:21 +00:00
|
|
|
// PlayerInterface *tempPlayer;
|
|
|
|
|
// for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
|
|
|
|
// tempPlayer = playerArray[i];
|
|
|
|
|
// playerArray[i] = 0;
|
|
|
|
|
// delete tempPlayer;
|
|
|
|
|
// }
|
2007-01-13 02:40:33 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-11 12:01:13 +00:00
|
|
|
HandInterface * Game::getCurrentHand()
|
|
|
|
|
{
|
|
|
|
|
return actualHand;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-12 22:00:59 +00:00
|
|
|
void Game::initHand()
|
2007-01-13 02:40:33 +00:00
|
|
|
{
|
2007-05-03 22:44:08 +00:00
|
|
|
|
2007-01-13 02:40:33 +00:00
|
|
|
int i;
|
|
|
|
|
|
2007-04-17 07:28:32 +00:00
|
|
|
// eventuell vorhandene Hand löschen
|
2007-01-13 02:40:33 +00:00
|
|
|
if(actualHand) {
|
|
|
|
|
delete actualHand;
|
|
|
|
|
actualHand = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actualHandID++;
|
|
|
|
|
|
2007-01-23 19:20:18 +00:00
|
|
|
// smallBlind alle x Runden erhöhen
|
2007-05-03 22:44:08 +00:00
|
|
|
if(actualHandID%(startHandsBeforeRaiseSmallBlind+1) == 0) { actualSmallBlind *= 2; }
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-05-26 12:40:45 +00:00
|
|
|
|
2007-01-13 02:40:33 +00:00
|
|
|
|
|
|
|
|
// Spieler mit leerem Cash auf inactive setzen
|
2007-04-17 07:28:32 +00:00
|
|
|
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
2007-01-13 02:40:33 +00:00
|
|
|
if(playerArray[i]->getMyCash() == 0) playerArray[i]->setMyActiveStatus(0);
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-05 23:55:06 +00:00
|
|
|
// Anzahl noch aktiver Spieler ermitteln
|
|
|
|
|
actualQuantityPlayers = 0;
|
2007-04-17 07:28:32 +00:00
|
|
|
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
2007-06-15 10:38:41 +00:00
|
|
|
if(playerArray[i]->getMyActiveStatus()) actualQuantityPlayers++;
|
2007-03-05 23:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-26 12:40:45 +00:00
|
|
|
//Spieler Action auf 0 setzen
|
|
|
|
|
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
|
|
|
|
|
playerArray[i]->setMyAction(0);
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-08 19:37:21 +00:00
|
|
|
// Hand erstellen
|
|
|
|
|
actualHand = myFactory->createHand(myFactory, myGui, actualBoard, playerArray, actualHandID, startQuantityPlayers, actualQuantityPlayers, dealerPosition, actualSmallBlind, startCash);
|
|
|
|
|
|
|
|
|
|
|
2007-01-13 02:40:33 +00:00
|
|
|
// Dealer-Button weiterschieben --> Achtung inactive
|
2007-08-10 22:39:44 +00:00
|
|
|
for(i=0; (i<MAX_NUMBER_OF_PLAYERS && !(playerArray[dealerPosition]->getMyActiveStatus())) || i==0; i++) {
|
|
|
|
|
|
2007-04-17 07:28:32 +00:00
|
|
|
dealerPosition = (dealerPosition+1)%(MAX_NUMBER_OF_PLAYERS);
|
2007-08-10 22:39:44 +00:00
|
|
|
}
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-05-12 22:00:59 +00:00
|
|
|
// Abfrage Cash==0 -> player inactive -> actualQuantityPlayer--
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Game::startHand()
|
|
|
|
|
{
|
|
|
|
|
assert(actualHand);
|
|
|
|
|
|
|
|
|
|
//GUI bereinigen
|
|
|
|
|
myGui->nextRoundCleanGui();
|
2007-01-13 02:40:33 +00:00
|
|
|
|
2007-02-04 13:46:27 +00:00
|
|
|
myGui->logNewGameHandMsg(myGameID, actualHandID);
|
|
|
|
|
|
2007-05-12 22:00:59 +00:00
|
|
|
actualHand->start();
|
2007-01-13 02:40:33 +00:00
|
|
|
}
|
2007-05-21 22:16:32 +00:00
|
|
|
|
2007-08-10 23:16:21 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> Game::getPlayerByUniqueId(unsigned id)
|
2007-05-21 22:16:32 +00:00
|
|
|
{
|
2007-08-10 23:16:21 +00:00
|
|
|
boost::shared_ptr<PlayerInterface> tmpPlayer;
|
2007-05-21 22:16:32 +00:00
|
|
|
for (int i = 0; i < startQuantityPlayers; i++)
|
|
|
|
|
{
|
|
|
|
|
if (playerArray[i]->getMyUniqueID() == id)
|
|
|
|
|
{
|
|
|
|
|
tmpPlayer = playerArray[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tmpPlayer;
|
|
|
|
|
}
|