It works (trust me)!
The code is below:
bool FBullCowGame::IsGuessIsogram(FString Guess) const
{
if (Guess.length() < 2) { return true; } //Treat 0- and 1-letter words as isograms
TMap<char, bool> LetterSeen; //Set up our TMap
for (auto Letter : Guess)
{
Letter = tolower(Letter); //Handle mixed case
if (LetterSeen[Letter])// If the letter is in the map
return false; // We do not have an isogram
else if (!LetterSeen[Letter]) // If the letter is not in the map
LetterSeen[Letter] = true; // Add it to map
}
return true;
}
//TODO write richer return value, write code so that the function has a basis upon which to decide whether or not a given answer is valid.
EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess) const
{
int32 GuessLength = Guess.length();
//if (false)
if (!IsGuessIsogram(Guess)) //if the guess isn't an isogram
{
return EGuessStatus::Not_Isogram; //TODO write function to return error
}
//else if (false)
else if (!IsGuessAlpha(Guess)) //if the guess is contains non-alphabetical characters
{
return EGuessStatus::Not_Alpha; //return an error
}
else if (GuessLength != GetHiddenWordLength()) //if the guess is the wrong length
{
return EGuessStatus::Wrong_Length;
}
else //otherwise
{
return EGuessStatus::OK; //return 'okiedokie' - the guess is valid and the program should accept it
}
}