Struggled, but managed SubmitGuess challenge!

Being new to programming I really struggled with this challenge, but I was determined not to unpause the video! After a while of being confused and trying to decipher the code, I remembered that we had done:

	return (Response[0] == 'y') || (Response[0] == 'Y');

to access letters of a string and it clicked in my head what I needed to do and I wrote:

// receives a VALID guess, increments turns, and returns count
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
	// increment the turn number
	MyCurrentTry++;

	// setup a return variable
	FBullCowCount BullCowCount;

	// loop through all letters in the guess.
	// [i] starts as 0 (first letter of Guess) and compares to letter [j]
	// of MyHiddenWord, with [j] starting as 0 (first letter of MyHiddenWord)
	// and being incremented until every letter of MyHiddenWord has been checked.
	// [i] then increments (second letter of Guess) and these are then checked against
	// all the letters of MyHiddenWord again
	int32 HiddenWordLength = MyHiddenWord.length();
	for (int32 i = 0; i < HiddenWordLength; i++)
	{
		// compare letters against the hidden word
		for (int32 j = 0; j < HiddenWordLength; j++)
		{
			// if they match then
			if (Guess[i] == MyHiddenWord[j])
			{
				// if they're in the same place
				if (i == j)
				{
					//increment bulls
					BullCowCount.Bulls++;
				}
				else
				{
					// increment cows
					BullCowCount.Cows++;
				}
			}
			else
			{
				// do nothing
			}
					
		}
	}

It seems to work and very pleased with myself!

1 Like

Privacy & Terms