コード例 #1
0
ファイル: xboardengine.cpp プロジェクト: eliaskousk/cutechess
void XboardEngine::initialize()
{
	if (state() == Starting)
	{
		onProtocolStart();
		emit ready();
	}
}
コード例 #2
0
ファイル: uciengine.cpp プロジェクト: ajithcj/cutechess
void UciEngine::parseLine(const QString& line)
{
	const QStringRef command(firstToken(line));

	if (command == "info")
	{
		parseInfo(command);
	}
	else if (command == "bestmove")
	{
		if (state() != Thinking)
		{
			if (state() == FinishingGame)
				pong();
			else
				qDebug() << "Unexpected move from" << name();
			return;
		}

		QString moveString(nextToken(command).toString());
		m_moveStrings += " " + moveString;
		Chess::Move move = board()->moveFromString(moveString);

		if (!move.isNull())
			emitMove(move);
		else
			forfeit(Chess::Result::IllegalMove, moveString);
	}
	else if (command == "readyok")
	{
		pong();
	}
	else if (command == "uciok")
	{
		if (state() == Starting)
		{
			onProtocolStart();
			ping();
		}
	}
	else if (command == "id")
	{
		QStringRef tag(nextToken(command));
		if (tag == "name" && name() == "UciEngine")
			setName(nextToken(tag, true).toString());
	}
	else if (command == "registration")
	{
		if (nextToken(command) == "error")
		{
			qDebug("Failed to register UCI engine %s", qPrintable(name()));
			write("register later");
		}
	}
	else if (command == "option")
	{
		EngineOption* option = parseOption(command);
		QString variant;

		if (option == 0 || !option->isValid())
			qDebug("Invalid UCI option from %s: %s",
				qPrintable(name()), qPrintable(line));
		else if (!(variant = variantFromUci(option->name())).isEmpty())
			addVariant(variant);
		else if (option->name() == "UCI_Opponent")
			m_sendOpponentsName = true;
		else if (option->name() == "Ponder"
		     ||  (option->name().startsWith("UCI_") &&
			  option->name() != "UCI_LimitStrength" &&
			  option->name() != "UCI_Elo"))
		{
			// TODO: Deal with UCI features
		}
		else
		{
			addOption(option);
			return;
		}

		delete option;
	}
}