Are now finally ready to start making games we're starting off fairly easy with this game so that we
can build our confidence when programming.
But the programs will start really picking up in complexity after this.
So do what I outlined in the first section which is to really understand the problem.
So let's go through this and it says create a program called Number guesser error be a secret number
that is set at the start of the program without any user input.
So right away this tells me that we need a variable
that stores the secret number right.
So what we're doing is really just making notes for now.
So in halves can we have something to work with in the future.
So the secret number should be picked from a certain range.
Sue does this mean.
So it doesn't say what the range is so I guess that means we could make it up ourselves.
So for our range Riskin to say it's from 0 to 100 so we're going to pick in a secret number from between
zero to 100.
The range should be output to the player and the player should be prompted to enter his guess that the
prompt should show how many guesses the player has left.
So again we need variable
that stores the number guesses.
Clare laughed.
The player will then enter his guess if the guess is too high then the game will output that the guess
is too high if the guess is too low then the game will output that the guess was too low.
So I think we will also want variable that oil Store Players guess right because we need to compare
it.
This is this is saying we need to compare it to the secret number
said the player player only has a certain number of guesses right here.
He knew this the number of guesses should be based on the range of the secret number.
So let's talk about that number range a little bit more.
So we have the range at zero to 100.
So what would be the optimal guessing strategy.
Well what you'd really want to do is just guess the middle every time.
Right.
So the middle from 0 to 100 let's say be 50 and then that way whatever the outcome Beav either cut the
range in half or we got the answer right.
So if he gets 50 and it was too high let's say then we cut out 51 through a 100.
So that's like half the range gone.
And then if we do that again say we'll guess 25 right.
That's from 0 to 49 right then that that'll cut out whatever the outcome is.
OK point five yeses.
That's half the range again right.
So how many yeses would we need given an upper bound.
Right.
This 100 here well it's actually the long base too.
So if you remember your math class.
Right.
So the long base to of a hundred is roughly kind of roughly six point six for something like this.
So we'll just kind of you know fudge it to be like the ceiling of that or something like seven say day
was kind of round up.
So the number of guesses will be the log base two of the upper range.
See how see why the understanding.
The problem is so important and this really gives us the information that we need to start.
So any wrong guess will we will document the number of guesses left.
OK.
And since the game ends by saying what the secret number was regardless of if the player guessed the
right number.
OK.
So we just have to output the secret number at the end.
So when the game is over the player should be prompted if you'd like to play again.
So is going to this is going to be very important in the next lecture.
And if yes the secret number should change.
Kate we don't know how to do that yet.
So in a rage How do we change secret number if it's not.
Remember we're not putting it from the user.
So and any input errors by the player should have proper handling.
OK.
So this is a good start for now and the next lecture we will actually start really solving the problem.