コード例 #1
0
ファイル: gaddagfactory.cpp プロジェクト: domino14/quackle
bool GaddagFactory::pushWord(const Quackle::LetterString &word)
{
	++m_encodableWords;
	hashWord(word);
	// FIXME: This hash will fail if duplicate words are passed in.
	// But testing for duplicate words isn't so easy without keeping
	// an entirely separate list.

	for (unsigned i = 1; i <= word.length(); i++)
	{
		Quackle::LetterString newword;

		for (int j = i - 1; j >= 0; j--)
			newword.push_back(word[j]);

		if (i < word.length())
		{
			newword.push_back(internalSeparatorRepresentation);  // "^"
			for (unsigned j = i; j < word.length(); j++)
				newword.push_back(word[j]);
		}
		m_gaddagizedWords.push_back(newword);
	}
	return true;
}
コード例 #2
0
ファイル: boarddisplay.cpp プロジェクト: cdhowie/Quackle
void BoardWithQuickEntry::processCommand(const QString &command)
{
	QStringList items(command.split(" ", QString::SkipEmptyParts));
	Quackle::Move move(Quackle::Move::createNonmove());

	if (items.size() <= 0)
	{
		provideHelp();
		return;
	}

	const QString verb(items.first().toLower());

	if (verb.startsWith("pass"))
		move = Quackle::Move::createPassMove();
	else
	{
		if (items.size() != 2)
		{
			provideHelp();
			return;
		}

		if (verb.startsWith(tr("ex")))
		{
			QString letters = items.at(1);
			bool isIntConvertable = false;
			int exchangeLength = letters.toInt(&isIntConvertable);
			bool isPass = false;

			Quackle::LetterString encodedLetters;

			if (isIntConvertable)
			{
				if (exchangeLength == 0)
				{
					isPass = true;
				}
				else
				{
					for (int i = 0; i < exchangeLength; ++i)
						encodedLetters.push_back(QUACKLE_BLANK_MARK);
				}
			}
			else
			{
				encodedLetters = QuackleIO::Util::nonBlankEncode(letters);
			}

			if (isPass)
				move = Quackle::Move::createPassMove();
			else
				move = Quackle::Move::createExchangeMove(encodedLetters);
		}
		else
		{
			QString prettyLetters(items.at(1));
			QString letters;

			bool replace = false;
			for (int i = 0; i < prettyLetters.length(); ++i)
			{
				QChar character = prettyLetters.at(i);
				if (character == '(')
					replace = true;
				else if (character == ')')
					replace = false;
				else if (replace)
					letters += ".";
				else
					letters += character;
			}
			move = Quackle::Move::createPlaceMove(QuackleIO::Util::qstringToString(items.first()), QuackleIO::Util::encode(letters));
		}
	}

	if (move.isAMove())
		emit setCandidateMove(move);
}