[feedback] guessLower and guessHigher not functioning as intended

So while watching this discussion, I realized that by introducing the Random.Range in NextGuess, it causes some guess to be lower that the previous guess while attempting to go higher.

For example, I pick 123, the computer starts at 321.

Lower: 89

Higher: 145

Lower: 53…lower than the first Lower 89, to which the response was higher.

Higher: 49

Higher: 66, still lower than the first guess that was too low, 89.

Higher: 52

Looking at the code, unless I’ve done something incredibly incorrect, the guessLower and guessHigher functions are doing the exact same thing by initializing the NextGuess function. The way this is written, you could link the Higher and Lower buttons to the same function or replace both buttons with a single guess button.

Should each guess not be logged as a string in a compare statement or is something like guess retention beyond the scope of this specific facet of the course?

The GuessLower() and GuessHigher() methods aren’t doing exactly the same thing, whilst it is true they both call the NextGuess() method, they are also individually setting variables which will determine the bounds of Random.Range() calculation.

When you wrote out those numbers, was that a presumed outcome or was this from testing?

Using your example but introducing the setting of the variables;

For example, I pick 123, the computer starts at 321.

max = 1000, min = 1, guess = 321

Lower: 89

max = 321, min = 1, guess = 89

Higher: 145

max = 321, min = 89, guess = 145

Lower: 53…lower than the first Lower 89, to which the response was higher.

This wouldn’t occur.

max = 145, min = 89, guess = n

n = Random.Range(min, max+1)/2;

which is currently saying;

n = Random.Range(89, (145+1))/2;

Odd. Those results were during testing and the issue was repeating across multiple tests.

I’d probably start by checking your buttons for higher amd lower and check that they are calling the correct methods and aren’t around the opposite way.

Updated Wed Jun 07 2017 21:22

Oooh… hang on… of course you could get a random number between 89 and 146, which, when divided by 2 equals 53… 106 example.

From memory the divide by two was only in the first version of the game, wgere max and min were added together then divided. You have also incorporated it into the random range approach, which isn’t required and is causing your problem.

Awesome, I must have missed that. I’m a stay at home dad of two kids two and under while I finish up my program(s). Gets pretty hectic around here during the day. Thanks for your time, I’m really enjoying your course.


1 Like

You are more than welcome and kudos on the stay at home dad role, your children will really appreciate all of that extra time they have with you :slight_smile:

Privacy & Terms