My Bulls and Cows are always the same

Hey, i have a problem of making the code work properly,
the Bulls and Cows always stay at the same count depending on the Hidden Word. When the Hidden Word is 1 letter - there are 1 Bull 0 Cows, when the Hidden Word is 4 letters - there are 4 Bulls and 12 Cows, and so on, and it is like the Guess is not even taken into account.
I would appreciate the help,
Thank You.

Here is The Code

void FBullCowGame::Reset()
{
    constexpr int32 MAX_TRIES = 8;
    const FString HIDDEN_WORD = "death";
    MyHiddenWord = HIDDEN_WORD;
    MyMaxTries = MAX_TRIES;
    MyCurrentTries = 1;

    }

bool FBullCowGame::IsGameWon() const
{
    return false;
}


FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
MyCurrentTries++;
//okresla jaki dostaje return
FBullCowCount BullCowCount;
//loopuje kazda litere w slowie
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++)
{
	for (int32 GChar = 0; GChar < HiddenWordLength; GChar++)
	{
		if (Guess[MHWChar] = MyHiddenWord[MHWChar]);
		{ if (MHWChar == GChar) {
			BullCowCount.Bulls++;
		}
		else
		{
			BullCowCount.Cows++;

		}
		}

	}

}


    return BullCowCount;
}

You need to remove a semicolon in this line. Also, you want to compate two values in this line, but in fact you are assigning one to another. So also change ‘=’ to ‘==’

It’s always the simplest things I overlook. Thank you very much

Glad to help :slight_smile:
Have a nice day

You can Optimise your code like this

FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
    {
    	MyCurrentTry++;
    	FBullCowCount BullCowCount;
    	int32 HiddenWordLength = MyHiddenWord.length();
    	for(int32 i=0;i<HiddenWordLength;i++)
    	{	
    		if(Guess[i]==MyHiddenWord[i])
    		{
    			BullCowCount.Bulls++;
    		}
    		else
    		{
    			for (int32 j = 0; j<HiddenWordLength; j++)
    			{
    				if (MyHiddenWord[i] == Guess[j])
    				{
    					BullCowCount.Cows++;
    				}


    			}
    		}
    		
    	}
    	return BullCowCount;

Privacy & Terms