Bull and Cow Logic (since course is incomplete)

below is my code for the completion of the Bull Cows game. Since it is still currently being remastered, I thought I would post in case anyone is having problems with the logic. Cheers!

int32 UBullCowCartridge::Bulls(FString BAnswer, FString BWord) const
{
    int32 Bull=0;
    for (int32 Index = 0; Index < BWord.Len(); Index++)
    {
       if (BAnswer[Index]==BWord[Index])
        {
            Bull=Bull+1;
        }
    }
    return Bull;
}
int32 UBullCowCartridge::Cows(FString CAnswer, FString CWord) const
{
    int32 Cow=0;
    for(int32 Index=0; Index < CWord.Len(); Index++)
    {
        if(CAnswer[Index]!=CWord[Index])
        {
            for(int32 Comp=0; Comp < CWord.Len(); Comp++)
            {
                if (Comp!=Index && CAnswer[Index]==CWord[Comp])
                {
                    Cow=Cow+1;
                }
            }
        }
    }
    return Cow;
}
2 Likes

Privacy & Terms