Structs.
FBullCowCount UBullCowCartridge::GetBullsAndCows(const FString& Guess) const
{
FBullCowCount BullCowCount;
BullCowCount.BullCount = 0;
BullCowCount.CowCount = 0;
for (int32 i = 0; i < Guess.Len(); i++) {
if (Guess[i] == HiddenWord[i]) {
BullCowCount.BullCount++; // Direct hit
}
else {
for (int32 j = 0; j < Guess.Len(); j++)
{ // See if char is repeated elsewhere.
if ((Guess[i]) == HiddenWord[j] && (i != j))
{
BullCowCount.CowCount++;
break;
}
}
}
}
return BullCowCount;
// VERSION WITH THE OUT PARAMETERS. MESSY IN MHO
//void UBullCowCartridge::GetBullsAndCows(const FString & Guess, int32 & BullCount, int32 & CowCount)
//{
// BullCount = 0;
// CowCount = 0;
//
// for (int32 i = 0; i < Guess.Len(); i++) {
// if (Guess[i] == HiddenWord[i]) {
// BullCount++; // Direct hit
// }
// else {
// for (int32 j = 0; j < Guess.Len(); j++)
// { // See if char is repeated elsewhere.
// if ((Guess[i]) == HiddenWord[j] && (i != j))
// {
// CowCount++;
// }
// }
// }
// }
//}
}