Number Wizard code bug

Hey guys,

I found this bug within Number Wizard UI section. There was a earlier post I found on this Code bug? Number Wizard UI and I wanted to see if anyone either fixed it or just left it.

In the post it, the person who answered it said they allowed the players to cheat, but I think that is not a great answer since we are here to learn and problem solving. This is what I came up with and it worked for me, but I thought if someone who was better at coding looked at this could come with something better. That they could comment as well.

        if (guess == max)
        {
            min = guess;
        }
        else 
        {
            min = guess + 1;
        }
        calculateGuess();

This is a simple if statement that checks to see if min is equal to the current max, if so it should not go over. This prevented the min to climb past 1000 (Click the link to the other guy’s post for picture).

2 Likes

This essentially works. Only issue is if the user then clicks “lower” after min and max are equal, the max becomes less creating a separate problem. Here’s the code I tried for the “OnPressLower” method to fix that:

if (min == max)
        {
            // just do nothing
        }
        else
        {
            max = guess - 1;
        }
        NextGuess();

This checks to see if min and max are equal (game is technically over), and if they are you leave max as is so as not to decrease max below min. Otherwise, decrease max as normal for no repeated guesses. Hopefully this helps to get rid of any issues.

1 Like

Privacy & Terms