WEBVTT

00:00.890 --> 00:07.200
Are now finally ready to start making games we're starting off fairly easy with this game so that we

00:07.200 --> 00:10.110
can build our confidence when programming.

00:10.110 --> 00:16.850
But the programs will start really picking up in complexity after this.

00:16.850 --> 00:25.410
So do what I outlined in the first section which is to really understand the problem.

00:25.680 --> 00:34.140
So let's go through this and it says create a program called Number guesser error be a secret number

00:34.200 --> 00:38.520
that is set at the start of the program without any user input.

00:38.520 --> 00:44.820
So right away this tells me that we need a variable

00:48.070 --> 00:55.130
that stores the secret number right.

00:56.610 --> 01:00.540
So what we're doing is really just making notes for now.

01:00.990 --> 01:05.910
So in halves can we have something to work with in the future.

01:06.510 --> 01:10.260
So the secret number should be picked from a certain range.

01:10.260 --> 01:12.100
Sue does this mean.

01:12.180 --> 01:19.390
So it doesn't say what the range is so I guess that means we could make it up ourselves.

01:19.650 --> 01:28.200
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

01:28.200 --> 01:29.790
zero to 100.

01:32.630 --> 01:41.100
The range should be output to the player and the player should be prompted to enter his guess that the

01:41.870 --> 01:45.150
prompt should show how many guesses the player has left.

01:45.170 --> 01:50.420
So again we need variable

01:52.970 --> 01:59.210
that stores the number guesses.

01:59.580 --> 02:02.510
Clare laughed.

02:04.760 --> 02:12.290
The player will then enter his guess if the guess is too high then the game will output that the guess

02:12.290 --> 02:18.450
is too high if the guess is too low then the game will output that the guess was too low.

02:18.470 --> 02:34.120
So I think we will also want variable that oil Store Players guess right because we need to compare

02:34.120 --> 02:34.540
it.

02:34.570 --> 02:38.760
This is this is saying we need to compare it to the secret number

02:41.960 --> 02:47.010
said the player player only has a certain number of guesses right here.

02:47.030 --> 02:55.780
He knew this the number of guesses should be based on the range of the secret number.

02:55.780 --> 03:00.210
So let's talk about that number range a little bit more.

03:00.360 --> 03:04.690
So we have the range at zero to 100.

03:04.690 --> 03:08.090
So what would be the optimal guessing strategy.

03:08.830 --> 03:13.270
Well what you'd really want to do is just guess the middle every time.

03:13.270 --> 03:13.630
Right.

03:13.630 --> 03:24.980
So the middle from 0 to 100 let's say be 50 and then that way whatever the outcome Beav either cut the

03:24.980 --> 03:29.260
range in half or we got the answer right.

03:29.540 --> 03:40.140
So if he gets 50 and it was too high let's say then we cut out 51 through a 100.

03:40.160 --> 03:43.420
So that's like half the range gone.

03:43.760 --> 03:49.410
And then if we do that again say we'll guess 25 right.

03:49.410 --> 03:56.850
That's from 0 to 49 right then that that'll cut out whatever the outcome is.

03:57.230 --> 03:58.750
OK point five yeses.

03:58.760 --> 04:01.830
That's half the range again right.

04:01.880 --> 04:07.610
So how many yeses would we need given an upper bound.

04:07.610 --> 04:07.840
Right.

04:07.880 --> 04:12.970
This 100 here well it's actually the long base too.

04:12.980 --> 04:15.530
So if you remember your math class.

04:15.530 --> 04:16.160
Right.

04:16.490 --> 04:29.650
So the long base to of a hundred is roughly kind of roughly six point six for something like this.

04:29.840 --> 04:39.430
So we'll just kind of you know fudge it to be like the ceiling of that or something like seven say day

04:39.550 --> 04:42.700
was kind of round up.

04:43.080 --> 05:06.500
So the number of guesses will be the log base two of the upper range.

05:06.930 --> 05:12.820
See how see why the understanding.

05:12.830 --> 05:19.930
The problem is so important and this really gives us the information that we need to start.

05:20.100 --> 05:25.950
So any wrong guess will we will document the number of guesses left.

05:25.980 --> 05:26.430
OK.

05:26.500 --> 05:34.290
And since the game ends by saying what the secret number was regardless of if the player guessed the

05:34.290 --> 05:35.180
right number.

05:35.300 --> 05:36.110
OK.

05:36.160 --> 05:40.860
So we just have to output the secret number at the end.

05:40.980 --> 05:47.060
So when the game is over the player should be prompted if you'd like to play again.

05:47.070 --> 05:51.090
So is going to this is going to be very important in the next lecture.

05:51.390 --> 05:55.320
And if yes the secret number should change.

05:55.370 --> 05:57.710
Kate we don't know how to do that yet.

05:57.810 --> 06:11.490
So in a rage How do we change secret number if it's not.

06:11.550 --> 06:14.830
Remember we're not putting it from the user.

06:14.850 --> 06:21.780
So and any input errors by the player should have proper handling.

06:21.900 --> 06:22.530
OK.

06:23.550 --> 06:31.840
So this is a good start for now and the next lecture we will actually start really solving the problem.
