Пример #1
0
void
ServerGame::InitRankingMap(const PlayerDataList &playerDataList)
{
	PlayerDataList::const_iterator i = playerDataList.begin();
	PlayerDataList::const_iterator end = playerDataList.end();
	while (i != end) {
		boost::shared_ptr<PlayerData> tmpPlayer(*i);
		RankingData tmpData(tmpPlayer->GetDBId());
		m_rankingMap[tmpPlayer->GetUniqueId()] = tmpData;
		++i;
	}
}
Пример #2
0
void
ServerGame::AssignPlayerNumbers(PlayerDataList &playerList)
{
	int playerNumber = 0;

	PlayerDataList::iterator player_i = playerList.begin();
	PlayerDataList::iterator player_end = playerList.end();

	while (player_i != player_end) {
		(*player_i)->SetNumber(playerNumber);
		++playerNumber;
		++player_i;
	}
}
Пример #3
0
Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
		   const PlayerDataList &playerDataList, const GameData &gameData,
		   const StartData &startData, int gameId, Log* log)
	: myFactory(factory), myGui(gui), myLog(log), startQuantityPlayers(startData.numberOfPlayers),
	  startCash(gameData.startMoney), startSmallBlind(gameData.firstSmallBlind),
	  myGameID(gameId), currentSmallBlind(gameData.firstSmallBlind), currentHandID(0), dealerPosition(0),
	  lastHandBlindsRaised(1), lastTimeBlindsRaised(0), myGameData(gameData),
	  blindsTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::manual_start)
{

	blindsList = myGameData.manualBlindsList;

	dealerPosition = startData.startDealerPlayerId;

	if(DEBUG_MODE) {
		startSmallBlind = 10;
		currentSmallBlind = startSmallBlind;
		dealerPosition = 4;
	}

	int i;

	// determine dealer position
	PlayerDataList::const_iterator player_i = playerDataList.begin();
	PlayerDataList::const_iterator player_end = playerDataList.end();

	while (player_i != player_end) {
		if ((*player_i)->GetUniqueId() == dealerPosition)
			break;
		++player_i;
	}
	if (player_i == player_end)
		throw LocalException(__FILE__, __LINE__, ERR_DEALER_NOT_FOUND);

	// create board
	currentBoard = myFactory->createBoard(dealerPosition);

	// create player lists
	seatsList.reset(new std::list<boost::shared_ptr<PlayerInterface> >);
	activePlayerList.reset(new std::list<boost::shared_ptr<PlayerInterface> >);
	runningPlayerList.reset(new std::list<boost::shared_ptr<PlayerInterface> >);

	// create player
	player_i = playerDataList.begin();
	player_end = playerDataList.end();
	for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {

		string myName;
		string myAvatarFile;
		string myGuid;
		unsigned uniqueId = 0;
		PlayerType type = PLAYER_TYPE_COMPUTER;
		int myStartCash = startCash;
		bool myStayOnTableStatus = false;

		if (player_i != player_end) {
			uniqueId = (*player_i)->GetUniqueId();
			type = (*player_i)->GetType();
			myName = (*player_i)->GetName();
			myAvatarFile = (*player_i)->GetAvatarFile();
			myGuid = (*player_i)->GetGuid();
			if ((*player_i)->GetStartCash() >= 0)
				myStartCash = (*player_i)->GetStartCash();
			myStayOnTableStatus = type == PLAYER_TYPE_HUMAN;
			++player_i;
		}

		// create player objects
		boost::shared_ptr<PlayerInterface> tmpPlayer = myFactory->createPlayer(i, uniqueId, type, myName, myAvatarFile, myStartCash, startQuantityPlayers > i, myStayOnTableStatus, 0);
		tmpPlayer->setIsSessionActive(true);
		tmpPlayer->setMyGuid(myGuid);

		// fill player lists
		seatsList->push_back(tmpPlayer);
		if(startQuantityPlayers > i) {
			activePlayerList->push_back(tmpPlayer);
		}
		(*runningPlayerList) = (*activePlayerList);

	}

	currentBoard->setPlayerLists(seatsList, activePlayerList, runningPlayerList);

	// log game data
	if(myLog) myLog->logNewGameMsg(myGameID, startCash, startSmallBlind, getPlayerByUniqueId(dealerPosition)->getMyID()+1, seatsList);

	//start timer
	blindsTimer.reset();
	blindsTimer.start();
}