/**
 * Reads a game in XML representation from the given device and creates a game object for it.
 *
 * @param device Device to read the game from.
 * @return A game representing the state of the XML.
 */
QSharedPointer<Game> GameReader::readGame(QIODevice* device)
{
	this->xmlStream.setDevice(device);

	this->readXML(true);

	auto gameLogic = QSharedPointer< ::GameLogic::FourInALine::Game>::create(this->nRows,
	                                                                         this->nColumns,
	                                                                         this->firstMovePlayerId);
	gameLogic->setTimeLimit(this->timeLimit);
	gameLogic->setTimeoutAction(this->timeoutAction);

	auto game = QSharedPointer<Game>::create(gameLogic, this->firstPlayer, this->secondPlayer);
	game->setSaveHighscore(this->saveHighscore);
	game->setAllowUndo(this->allowUndo);
	game->setAllowHint(this->allowHint);

	for (auto i = this->moves.cbegin(); i != this->moves.cend(); ++i)
	{
		if (game->getCurrentPlayer()->getPlayer() != i->first)
		{
			throw ParseError("Expected other player in current move.");
		}

		game->getGameLogic()->makeMove(i->second);
	}

	return game;
}
Beispiel #2
0
void ListModel::applyParams(SolverParams &params) {
	LOG_I("Applying custom parameters");
	if (ls.getNbPhases() == 0) {
		auto phase = ls.createPhase();
		if(params.iterLimit != -1)
			phase.setIterationLimit(static_cast<long long>(params.iterLimit));
		if(params.timeLimit != -1.0)
			phase.setTimeLimit(static_cast<int>(params.timeLimit));
		auto param = ls.getParam();
		param.setNbThreads(params.threadCount);
		param.setSeed(params.seed);
		param.setVerbosity(params.verbosityLevel);
		if (params.traceobj) {
			int timeBetweenDisplays = static_cast<int>(ceil(MSECS_BETWEEN_TRACES_LONG / 1000.0));
			param.setTimeBetweenDisplays(timeBetweenDisplays);
		}
	}
}
Beispiel #3
0
/**
 * Creates a new game with the same settings as the given game but with the two given players.
 *
 * @param game Game to copy settings from.
 * @param firstPlayer First player of the new game.
 * @param secondPlayer Second player of the new game.
 * @return New game with the given players and the settings from the given game.
 */
QSharedPointer<Game> Game::CreateWithSettingsFrom(QSharedPointer<const Game> game,
                                                  PlayerPointerType firstPlayer,
                                                  PlayerPointerType secondPlayer)
{
	auto nRows = game->getGameLogic()->getBoard()->getNumberOfRows();
	auto nColumns = game->getGameLogic()->getBoard()->getNumberOfColumns();
	auto firstMovePlayerId = game->getGameLogic()->getPlayerWhoMakesFirstMove();

	auto gameEngine = QSharedPointer< ::GameLogic::FourInALine::Game>::create(nRows, nColumns, firstMovePlayerId);
	gameEngine->setTimeLimit(game->getGameLogic()->getTimeLimit());
	gameEngine->setTimeoutAction(game->getGameLogic()->getTimeoutAction());

	auto newGame = QSharedPointer<Game>::create(gameEngine, firstPlayer, secondPlayer);

	newGame->setAllowUndo(game->isUndoAllowed());
	newGame->setAllowHint(game->isHintAllowed());
	newGame->setSaveHighscore(game->isSavingHighscore());

	return newGame;
}
Beispiel #4
0
// Default constructor (called only indirectly via getMediaTask())
MpMediaTask::MpMediaTask(int maxFlowGraph)
:  OsServerTask("MpMedia", NULL, MPMEDIA_DEF_MAX_MSGS,
                MEDIA_TASK_PRIO_NORMAL),
   mMutex(OsMutex::Q_PRIORITY),  // create mutex for protecting data
   mDebugEnabled(FALSE),
   mTimeLimitCnt(0),
   mProcessedCnt(0),
   mManagedCnt(0),
   mStartedCnt(0),
   mSemTimeout(DEF_SEM_WAIT_MSECS / 1000, (DEF_SEM_WAIT_MSECS % 1000) * 1000),
   mSemTimeoutCnt(0),
   mWaitForSignal(TRUE),
   mpFocus(NULL),
   mHandleMsgErrs(0),
   mpBufferMsgPool(NULL),
   // numQueuedMsgs(0),
   mpSignalMsgPool(NULL)
#ifdef _PROFILE /* [ */
   ,
   mStartToEndTime(20, 0, 1000, " %4d", 5),
   mStartToStartTime(20, 0, 1000, " %4d", 5),
   mEndToStartTime(20, 0, 1000, " %4d", 5),
   mSignalTime(20, 0, 1000, " %4d", 5),
   mSignalToStartTime(20, 0, 1000, " %4d", 5),
   mOtherMessages(20, 0, 1000, " %4d", 5)
#endif /* _PROFILE ] */
{
   mMaxFlowGraph = maxFlowGraph;

   int      i;
   OsStatus res;

   res = setTimeLimit(DEF_TIME_LIMIT_USECS);
   assert(res == OS_SUCCESS);

   assert(mMaxFlowGraph > 0); // mMaxFlowGraph must be greater than zero
   if (mMaxFlowGraph > 0)
   {
      mManagedFGs = new MpFlowGraphBase*[mMaxFlowGraph];
      if (mManagedFGs)
      {
         for (i=0; i < mMaxFlowGraph; i++)
         {
            mManagedFGs[i] = NULL;
         }
      }
   }
   {
      int totalNumBufs = MpBuf_getTotalBufferCount();
      int soft;
      int incr;
      MpBufferMsg* pMsg = new MpBufferMsg(MpBufferMsg::AUD_RECORDED);

      soft = totalNumBufs/20;
      if (soft < 8) soft = 8;
      incr = soft / 2 + 1;
      mpBufferMsgPool = new OsMsgPool("MediaBuffers", (*(OsMsg*)pMsg),
                          incr, soft, totalNumBufs, incr,
                          OsMsgPool::MULTIPLE_CLIENTS);
   }

   {
      MpMediaTaskMsg* pMsg =
         new MpMediaTaskMsg(MpMediaTaskMsg::WAIT_FOR_SIGNAL);
      mpSignalMsgPool = new OsMsgPool("MediaSignals", (*(OsMsg*)pMsg),
                          2, 2*mMaxFlowGraph, 4*mMaxFlowGraph, 1,
                          OsMsgPool::MULTIPLE_CLIENTS);
   }

   mpCodecFactory = MpCodecFactory::getMpCodecFactory();
#ifdef _PROFILE /* [ */
   mStartTicks = 0;
   mStopTicks = 0;
   sSignalTicks = 0;
   sMinTicks = 0;
   sMaxTicks = 0;
#endif /* _PROFILE ] */
}
Beispiel #5
0
int Simulation::setTimeLimit(lua_State* luaState)
{
    int limit = luaL_checkint(luaState, 1);
    setTimeLimit(limit);
    return 0;
}
Beispiel #6
0
// Default constructor (called only indirectly via getMediaTask())
MpMediaTask::MpMediaTask()
:  OsServerTask("MpMedia", NULL, MPMEDIA_DEF_MAX_MSGS,
                MEDIA_TASK_PRIORITY),
   mMutex(OsMutex::Q_PRIORITY),  // create mutex for protecting data
   mDebugEnabled(FALSE),
   mTimeLimitCnt(0),
   mProcessedCnt(0),
   mStartedCnt(0),
   mSemTimeout(DEF_SEM_WAIT_MSECS / 1000, (DEF_SEM_WAIT_MSECS % 1000) * 1000),
   mSemTimeoutCnt(0),
   mWaitForSignal(TRUE),
   mpFocus(NULL),
   mHandleMsgErrs(0),
   mpBufferMsgPool(NULL),
   mManagedFlowGraphs(),
   // numQueuedMsgs(0),
   mpSignalMsgPool(NULL),
   nFrameStartMsgs(0),
   m_pFrameStartCallback(NULL),
   m_pFrameStartTimer(NULL),
   m_bTaskOverloaded(FALSE)
{
   OsStatus res;

#if FRAME_PROCESSING_THREADS > 0
   char frameProcessorTaskName[20];
   for (int i = 0; i < FRAME_PROCESSING_THREADS; i++)
   {
      SNPRINTF(frameProcessorTaskName, sizeof(frameProcessorTaskName), "FrameProcessor-%d", i);
      m_processingThreads[i] = new MpMediaTaskHelper(frameProcessorTaskName, NULL, MEDIA_TASK_PRIORITY);
      // start threads
      UtlBoolean res = m_processingThreads[i]->start();
      assert(res);
   }
#endif

   // maximum time in us frame processing can take
   double timeLimitUs = ((1 / (double)MpMisc.m_audioSamplesPerSec) * MpMisc.m_audioSamplesPerFrame * 1000000) * 0.7;

   res = setTimeLimit((int)timeLimitUs);
   assert(res == OS_SUCCESS);

   int totalNumBufs = MpMisc.m_pRtpHeadersPool->getNumBlocks() * 2;
   int soft = totalNumBufs/20;
   if (soft < 8) soft = 8;
   {
      MpBufferMsg msg(MpBufferMsg::AUD_RECORDED);
      mpBufferMsgPool = new OsMsgPool("MediaBuffers", msg,
                          soft, soft,
                          OsMsgPool::MULTIPLE_CLIENTS);
   }

   {
      MpMediaTaskMsg msg(MpMediaTaskMsg::WAIT_FOR_SIGNAL);
      mpSignalMsgPool = new OsMsgPool("MediaSignals", msg,
                          soft, soft, 
                          OsMsgPool::MULTIPLE_CLIENTS);
   }

   mpCodecFactory = MpCodecFactory::getMpCodecFactory();
}