I changed the function GetBullCows to GetPattern so instead of telling Bulls and Cows it shows @
for the correct letter and index and shows ?
for the letter that exists but not in right place.
FString UBullCowCartridge::GetPattern(const FString& Guess) const
{
// Setting up hidden pattern
FString HiddenPattern = HiddenWord;
for (int32 index = 0; index < HiddenPattern.Len(); index++)
{
HiddenPattern[index] = 'X';
}
// for every index Guess is same as index Hidden, Shows @
// if not a bull was it a cow? if yes Show ?
for (int32 GuessIndex = 0; GuessIndex < Guess.Len(); GuessIndex++)
{
if (Guess[GuessIndex] == HiddenWord[GuessIndex])
{
HiddenPattern[GuessIndex] = '@'; //
continue;
}
for (int32 HiddenIndex = 0; HiddenIndex < HiddenWord.Len(); HiddenIndex++)
{
if (Guess[GuessIndex] == HiddenWord[HiddenIndex])
{
HiddenPattern[GuessIndex] = '?';
break;
}
}
}
return HiddenPattern;
}