Count Bulls and Cows without out parameters using FString.Contains function

Here is mi Count Bulls and Cows function definition using the Contians function of FString

/**
 * \brief Counts howmany Bulls and Cows has the guess word
 * \param Guess The guess word to search for Bull and Cows
 * \param Isogram The isogram word to compare
 * \return A binary tuple of int32 where the first value are Bulls and second are Cows conts
 */
TTuple<int32, int32> UBullCowCartridge::CountBullsAndCows(const FString& Guess, const FString& Isogram)
{
	auto Bulls = 0;
	auto Cows = 0;
	for (auto GuessIndex = 0; GuessIndex < Isogram.Len(); GuessIndex++)
	{
		const TCHAR ISOLatter = Isogram[GuessIndex];
		const TCHAR GuessLetter = Guess[GuessIndex];

		if (GuessLetter == ISOLatter)
		{
			++Bulls;
		}
		else if (Isogram.Contains(GuessLetter + ""))
		{
			++Cows;
		}

	}
	return  MakeTuple(Bulls, Cows);
}

1 Like

Awesome job posting this!

Cool, I did the same thing, except I wasn’t sure how to convert a tchar to a fstring, so I did

const TCHAR GuessLetter = Guess[GuessIndex];
const TCHAR HiddenLetter = HiddenWord[GuessIndex];
FString Temp = “”;
Temp.AppendChar(GuessLetter);

But is your way the best way to convert a tchar to a fstring?

(Also what’s the markdown to make a code block on here?)

Privacy & Terms