Having Trouble with Bull Cow Count

The Game keeps telling me that there is only 1 Bull and the Cows change depending on how many charaters are in the “Guess”

heres my code so far:

    #include "FBullCowGame.h"
using in32 = int;


int FBullCowGame::GetMaxTries() const { return MyMaxTries;}
int FBullCowGame::GetCurrentTries() const { return MyCurrentTries;}


FBullCowGame::FBullCowGame() { Reset(); }

void FBullCowGame::Reset()
{
	constexpr int MAX_TRIES = 10;
	MyMaxTries = MAX_TRIES;

	const FString HIDDEN_WORD = "planet";
	MyHiddenWord = HIDDEN_WORD;
	MyCurrentTries = 1;
	
	return;
}



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

bool FBullCowGame::CheckGuessValidity(FString)
{
	return false;
}
//receives a valid guess, incriments turn, and returns count
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
	//incriment the turn number
	MyCurrentTries++;
	// set up a return variable
	FBullCowCount BullCowCount;
	//loop through all letters in the guess
	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;
	}
}
1 Like

Worked it out hand the return Value for BullCowCount one line too high.

1 Like

Hello @Bailey_Hidalgo,

don’t forget to set the status of the topic to ‘solved’.

Cheers
Oten

Privacy & Terms