Skip to content

Instantly share code, notes, and snippets.

Created June 9, 2017 20:58
Show Gist options
  • Save anonymous/fb7fd9b998946ffedf87603df3234abc to your computer and use it in GitHub Desktop.
Save anonymous/fb7fd9b998946ffedf87603df3234abc to your computer and use it in GitHub Desktop.
my code
FBullCowCount FBullCowGame::SubmitGuess(FString TheGuess)
{
//increment turn
MyCurrentTry++;
//setup return variable
FBullCowCount BULL_COW_COUNT;
//loop through all letters in players guess
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MyHiddenChar = 0; MyHiddenChar < HiddenWordLength; MyHiddenChar++)
{
for (int32 MyGuessChar = 0; MyGuessChar < TheGuess.length(); MyGuessChar++)
{
if (MyHiddenWord[MyHiddenChar] == TheGuess[MyGuessChar])
{
if (MyHiddenChar == MyGuessChar)
{
BULL_COW_COUNT.Bulls++;
}
else if (MyGuessChar == 5)
{
break;
}
else
{
BULL_COW_COUNT.Cows++;
}
}
else if ((MyHiddenChar == 5)||(MyGuessChar == 5))
{
break;
}
}
}
return BULL_COW_COUNT;
}
@SteveDr56
Copy link

HI, that's pretty much as my attempt - except I didn't add the trapdoors for overlength guesses :)
/* receives a VALID guess and increments try # and returns count */
FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
// increment try
MyCurrentTry++;

// set up return variable
FBullCowCount BullCowCount;

// loop through all the letters in the guess
int32 HiddenWordLength = MyHiddenWord.length();

for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++) 
{
	// compare letters against the hidden word
	for (int32 GuessChar = 0; GuessChar < HiddenWordLength; GuessChar++) 
	{
		// if a letter in guess is same as a letter in hidden word
		if (Guess[GuessChar] == MyHiddenWord[MHWChar]) 
		{
			// if the matching letter is in the same position then increment bulls
			if (GuessChar == MHWChar) 
			{ 
				BullCowCount.Bulls++; 
			}
			else // if not then increment cows
			{
				BullCowCount.Cows++;  
			}
		}
		else 
		{
			// ignore it as it doesn't match at all
		}
	}
}
return BullCowCount;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment