I have implemented 2 extra features in BullCows game

The first additional implementation is stipulating that the guess must be from the commonly used isogram list. Choosing words outside of the list will not elicit Bull or Cow counts , but will also not deduct a life. Surprisingly fun! Almost like playing two games at once. Sometimes tempted to consider employing a larger word list to work from.

The second additional implementation is to allow repeated entry of the same guess. Just in case the player entered by mistake.

void UBullCowCartridge::ProcessGuess(FString Guess)
{	
	if (Guess.Len() == HiddenWord.Len())
	{			
		if (IsAlphabet(Guess))	//checks that the Guess string only contain alphabet
		{
			//Guess.ToLowerInline();	// If the characters are valid? Then Convert all to lower case. // done in Terminal.cpp line 131 instead.
			//against the flow of logic though
			if (IsIsogram(Guess))	//checks that Guess contain no repeating characters.
			{
				if (Guess == HiddenWord)
				{
					EndGame();
					return;
				}
				else if (CommonIsogram(Guess))	// a counter measure against using non words to clue out Bulls and Cows
				{
					if (Guessed(Guess))
					{
						PrintLine(TEXT("You have already tried that."));
					}
					else
					{
						PrintLine(TEXT("You have entered one of the common isograms but the wrong one."));
						
						if (!(--lives))
						{
							EndGame();
						}						
					}
					PrintLine(TEXT("You have %i attempt(s) remaining."), lives);

					FBullCowCount BullCowCounts{ GetBullCows(Guess) };
					PrintLine(TEXT("BullCounts is: %i and CowCounts is: %i"), BullCowCounts.Bulls, BullCowCounts.Cows);					
				}
				else
				{
					PrintLine(TEXT("You have entered an esoterical isogram."));	// no penalty and no BullCowCount update.
					PrintLine(TEXT(" Try a more common and easier one."));
				}
			}
			else
			{
				PrintLine(TEXT("An isogram contains no repeating letters. Retry."));
			}				
		}
		else
		{
			PrintLine(TEXT("Illegal character detected."));
			PrintLine(TEXT("Please enter a valid English isogram. "));
		}
	}
	else	// error checks the correct length of the guess
	{
		PrintLine(TEXT("Hidden isogram has %i characters. "), HiddenWord.Len());
	}
}
type or paste code here
1 Like

Privacy & Terms