Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The bug in the video #3

Open
kristi-swat opened this issue Nov 19, 2019 · 1 comment
Open

The bug in the video #3

kristi-swat opened this issue Nov 19, 2019 · 1 comment

Comments

@kristi-swat
Copy link

Hi,

This is not really an issue, but I didn't know where to ask this question, for some reason can't join the discord chat.

I am trying to understand why setting the max to max+1 within Start fixed the bug? That value is supposed to be only within Start method right?

@kabeocho
Copy link

kabeocho commented Sep 22, 2021

Hi @kristi-swat,

The problem here is how the program convert into integer a non integer number.

When you reach the top margin you have max = 1000 and min = 999.

As the user tell the program that your number is higher, the program calculate the next guess with (1000+999) / 2 = 999,5, rounding it to 999 and setting it again as the min.

I would have fixed this problem using another approach.

When you ask the user if a numer is higher or lower than the suggested, there's no reason to put this number as a min or max in the new guess.

I didn't run any unit tests to tests the limits of this apporach, but I think is clearer.

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            min = guess + 1;
            NextGuess();
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            max = guess - 1;
            NextGuess();
        }

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

No branches or pull requests

2 participants