Refactoring code for Bull Cows with const functions

Hello

I’ve been working through the Bull Cow section of the Unreal course over on Udemy and currently on video 64, Const member functions. In the video it states we could move the following three validity checks out into another const function:

void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Guess == HiddenWord)
    {
        PrintLine(TEXT("That is correct, you win!"));
        EndGame();
        return;
    }

    if(HiddenWord.Len() != Guess.Len())     
    {
        PrintLine(TEXT("The hidden word is %i characters long, try again!"), HiddenWord.Len());
        PrintLine(TEXT("You have %i lives remaining."), Lives);
        return;
    }
    
    if (!IsIsogram(Guess))
    {
        /* code */
        PrintLine(TEXT("No repeating letters allowed, guess again."));
        return;
    }

However, examining the first if statement block where it checks if the HiddenWord has been guessed, this calls the non-const function EndGame() which modifies a member variable. Therefore, I believe this could not be moved to a const member function. Just something to look out for if anyone refactors this code. As stated in the video, in this particular example refactoring would be over engineering for such a simple program.

Privacy & Terms