Esempio n. 1
0
void ThreadPool::startThinking(
  const Position& pos,
  const LimitsType& limits,
  const std::vector<Move>& searchMoves,
  const std::chrono::time_point<std::chrono::system_clock>& goReceivedTime)
{
  waitForThinkFinished();
  pos.searcher()->searchTimer.set(goReceivedTime);

  pos.searcher()->signals.stopOnPonderHit = pos.searcher()->signals.firstRootMove = false;
  pos.searcher()->signals.stop = pos.searcher()->signals.failedLowAtRoot = false;

  pos.searcher()->rootPosition = pos;
  pos.searcher()->limits.set(limits);
  pos.searcher()->rootMoves.clear();

#if defined LEARN
  const MoveType MT = LegalAll;
#else
  const MoveType MT = Legal;
#endif

  for (MoveList<MT> ml(pos); !ml.end(); ++ml) {
    if (searchMoves.empty()
      || std::find(searchMoves.begin(), searchMoves.end(), ml.move()) != searchMoves.end())
    {
      pos.searcher()->rootMoves.push_back(RootMove(ml.move()));
    }
  }

  mainThread()->thinking = true;
  mainThread()->notifyOne();
}
Esempio n. 2
0
void ThreadPool::startThinking(const Position& pos, const LimitsType& limits,
							   const std::vector<Move>& searchMoves)
{
#if defined LEARN
#else
	waitForThinkFinished();
#endif
	pos.searcher()->searchTimer.restart();

	pos.searcher()->signals.stopOnPonderHit = pos.searcher()->signals.firstRootMove = false;
	pos.searcher()->signals.stop = pos.searcher()->signals.failedLowAtRoot = false;

	pos.searcher()->rootPosition = pos;
	pos.searcher()->limits = limits;
	pos.searcher()->rootMoves.clear();

#if defined LEARN
	// searchMoves を直接使う。
	pos.searcher()->rootMoves.push_back(RootMove(searchMoves[0]));
#else
	const MoveType MT = Legal;
	for (MoveList<MT> ml(pos); !ml.end(); ++ml) {
		if (searchMoves.empty()
			|| std::find(searchMoves.begin(), searchMoves.end(), ml.move()) != searchMoves.end())
		{
			pos.searcher()->rootMoves.push_back(RootMove(ml.move()));
		}
	}
#endif

#if defined LEARN
	// 浅い探索なので、thread 生成、破棄のコストが高い。余分な thread を生成せずに直接探索を呼び出す。
	pos.searcher()->think();
#else
	mainThread()->thinking = true;
	mainThread()->notifyOne();
#endif
}