If I wanted the game to show every input correction guide (instead of just one of them), how should I fix the code?

urc_s02_design_a_helper_function

#1

Hello,

I think one might be frustrated if the game only gives one feedback to fix the user’s input, while he or she have made two or more errors.

For example, let us assume that the hidden word is “cow”, while a player puts “Google” as a guess. This is a case where the guess is (1)not all lowercase, (2)not an isogram, and (3)wrong number of letters. How can I make the game to point out all three errors at once?


#2

I am just trying to help, but not really sure of what I am saying…

I THINK the source of your “problem” is that, in the very definition of
EGuessStatus FBullCowGameClass::CheckGuessValidity(FString Guess),
what is returned is a single, simple value of the ‘EGuessStatus’ (enumerator) type.
ONLY ‘Not_Isogram’, or ONLY ‘Not_Lowercase’, or ONLY ‘Wrong_Length’ is returned when CheckGuessValidity(FString Guess) is run.

So you could do something like maybe instead of having

“EGuessStatus” //FBullCowGameClass::CheckGuessValidity(FString Guess)

use some TMap that stores all errors that Guess generates.

For instance,
TMap <FString,bool> ErrorsMap; //similar to the ‘TMap <char, bool> LetterSeen;’ we already have in the game

Then on the main.cpp Switch/case part, each case would not output any cout"text", but change second column of the map (the bool) to TRUE,

and finally, right after the Switch, you could output cout"error1", cout “error2”, cout “error3” according to a for loop checking all the bools inside the TMap?

I am really too sleepy to try this myself now. But please, reply with your code if this works. Or if you find any other solution, as it is an interesting question.


#3

I was slightly frustrated that Ben talked about this problem in the lecture in terms of implicit dependencies, but did not offer a solution to it. I was about to ask the same question as you.

I’m gonna give it go sometime and @berickphilip summed up how I intend to do it.
The only thing I’ll do differently is not to use TMAP, but maybe an array or some other data structure that doesn’t rely on items being indexed by a string. A string as the index doesn’t make sense to me in this case.


#4

Hi,

As a first port of call I would suggest removing, or commenting out, the "break;"s in the Switch case found in main.cpp’s “GetValidGuess()” method. This is a good first port of call to show you what happens and how the messages will display when printed.
I might then suggest that you break out the error code returns from FBullCowGame.cpp’s “CheckGuessValidity()” method into separate functions - you might even try having these be returned from the functions which check the conditions of a Guess, such as “IsLowerCase()”. You would then need to call these new methods (or the original methods) in the “GetValidGuess” Switch case - you would no longer need the “Status” variable in this code as you would be calling various methods directly.
In fact, as you are looking to execute 1) selectively and 2) potentially several items at once, I would suggest converting the Switch to string of “if” statements. If you leave it as a Switch then if it reads (roughly):
switch (Status)
case: wrong length {}
case: not isogram {}
case: not lower {}

… then it will execute the error you incurred and all code below it (as there is no “break;” to tell it to stop), regardless of these other errors are incurred. An “if” statement should allow you to “select” the relevant code as it is required.

I did not test this myself but please do comment if you find this to work as I am interested in finding out (even if I am not apparently prepared to go and do it myself right now).

Thanks,

Sam