1
00:00:00,390 --> 00:00:02,940
Now let's move on to hint number 10.

2
00:00:03,660 --> 00:00:06,750
It says that if the game has not ended ask the user

3
00:00:06,750 --> 00:00:09,630
if they want to draw another card. If yes

4
00:00:09,660 --> 00:00:13,470
then use the deal card function to add another card to the user's card list.

5
00:00:13,830 --> 00:00:15,840
If no, then the game has again

6
00:00:15,900 --> 00:00:19,680
ended. Over here in the if statement

7
00:00:19,740 --> 00:00:24,540
we can add an else because if the game hasn't ended, as in

8
00:00:24,570 --> 00:00:27,840
they haven't gone over 21 or nobody's got a Blackjack,

9
00:00:28,140 --> 00:00:31,920
then we're going to ask the user if they want to get another card.

10
00:00:32,340 --> 00:00:34,410
I'm going to use a input

11
00:00:35,370 --> 00:00:38,700
and I'm going to ask the user to type 'y' to get another card,

12
00:00:39,120 --> 00:00:41,340
otherwise type 'n' to pass.

13
00:00:42,000 --> 00:00:45,360
And I'm going to save this input inside a variable, which I'll

14
00:00:45,410 --> 00:00:47,900
call user_should_deal.

15
00:00:49,340 --> 00:00:54,340
Now we can check to see if this variable is equal to 'y'. Well in that case,

16
00:00:57,410 --> 00:00:59,810
we're going to add another card to

17
00:00:59,810 --> 00:01:03,980
the user's card list by doing the same thing that we did in the beginning

18
00:01:04,069 --> 00:01:07,550
where we dealt two cards to each player by saying

19
00:01:07,580 --> 00:01:12,380
user_cards.append and inside the parentheses

20
00:01:12,400 --> 00:01:16,790
the thing that we want to append is the output from deal_card.

21
00:01:18,080 --> 00:01:22,730
So just a quick check to make sure you've got all the parentheses there and then

22
00:01:22,760 --> 00:01:26,990
we're ready to address the else. If they didn't type 'y',

23
00:01:27,140 --> 00:01:30,920
then that means they don't want another card. Well, then in this case,

24
00:01:30,950 --> 00:01:32,630
the game has again ended.

25
00:01:32,780 --> 00:01:35,960
So we can say is_game_over equals true.

26
00:01:38,210 --> 00:01:39,740
Let's test this out as well.

27
00:01:40,340 --> 00:01:44,600
We got 7 and 11 with the current score of 18.

28
00:01:45,140 --> 00:01:48,500
If we type 'y' hopefully we'll get another card.

29
00:01:49,520 --> 00:01:52,460
And we did see that prompt and we saw something happen,

30
00:01:52,820 --> 00:01:57,530
but our program then promptly ended. Let's take a look at the next step.

31
00:01:57,650 --> 00:02:00,110
How can we get our game to repeat itself?

32
00:02:00,830 --> 00:02:04,580
So hint number 11 tells us that the score will need to be rechecked with

33
00:02:04,580 --> 00:02:05,990
every new card drawn

34
00:02:06,470 --> 00:02:10,940
and the checks in hint 9 needs to be repeated until the game ends.

35
00:02:11,510 --> 00:02:15,890
Notice how we've got this flag, is_game_over, which is set to true

36
00:02:16,160 --> 00:02:19,880
whenever the game ends. It starts off being false

37
00:02:20,240 --> 00:02:23,900
and what this means is we can actually create a while loop

38
00:02:24,260 --> 00:02:27,260
which basically keeps on calculating the user_score

39
00:02:27,350 --> 00:02:30,590
and the computer_score, makes all of these checks

40
00:02:30,800 --> 00:02:32,390
which are in hint 9,

41
00:02:32,780 --> 00:02:36,050
and then repeats itself until the game ends.

42
00:02:36,860 --> 00:02:40,370
Let's go ahead and do that. After all the initial setup,

43
00:02:40,520 --> 00:02:45,320
we're going to create a while loop and the while loop is going to be active

44
00:02:45,500 --> 00:02:48,560
until the game is over. So we can say

45
00:02:48,560 --> 00:02:50,900
while not is_game_over,

46
00:02:51,770 --> 00:02:55,460
then go ahead and carry out all of these instructions.

47
00:02:55,760 --> 00:02:59,060
So calculate the user_score, calculate the computer_score,

48
00:02:59,380 --> 00:03:03,670
check that nobody's gone over 21 and nobody's gotten a Blackjack.

49
00:03:04,090 --> 00:03:08,190
And if the user wants more cards than they should, if they don't then the

50
00:03:08,190 --> 00:03:12,040
the game is over. So let's run this and try it again.

51
00:03:14,160 --> 00:03:18,270
Our cards are 10 and 10 which probably means we shouldn't get another card

52
00:03:18,270 --> 00:03:22,320
cause we're already so close to 21, but I'm going to be daring and press

53
00:03:22,320 --> 00:03:26,730
'y' anyways. And it tells us that our cords are now 10,

54
00:03:26,760 --> 00:03:28,260
10 plus two.

55
00:03:28,590 --> 00:03:32,490
So we got an extra card and that takes up our score to 22.

56
00:03:33,030 --> 00:03:34,620
That worked perfectly.

57
00:03:35,310 --> 00:03:38,820
So now let's go back and tackle the next part. Hint

58
00:03:38,820 --> 00:03:42,960
number 12 says once the user is done, it's time to let the computer play.

59
00:03:43,410 --> 00:03:48,270
The computer should keep drawing cards as long as it has a score less than 17.

60
00:03:49,200 --> 00:03:53,940
So the while loop is responsible for dealing with when the user wants to keep

61
00:03:53,940 --> 00:03:56,880
drawing cards. But once that's done,

62
00:03:56,970 --> 00:03:59,280
then we can tackle hint number 12,

63
00:03:59,700 --> 00:04:04,110
which is how does the computer actually play? What is its strategy?

64
00:04:04,680 --> 00:04:08,010
Well, we know that the computer has to keep drawing cards

65
00:04:08,520 --> 00:04:13,020
as long as it has a score of less than 17. But, of course,

66
00:04:13,260 --> 00:04:17,370
0 which represents a Blackjack is also less than 17,

67
00:04:17,670 --> 00:04:21,420
but we don't want it to draw a card if it has a Blackjack.

68
00:04:22,230 --> 00:04:27,230
We can represent this logic using a while loop; while the computer_score is not

69
00:04:29,460 --> 00:04:34,460
equal to zero and the computer_score is less than 17,

70
00:04:37,380 --> 00:04:40,410
then in this case we want to keep drawing cards.

71
00:04:41,100 --> 00:04:43,350
We're going to take the computers cards

72
00:04:43,830 --> 00:04:48,830
and we're going to use the append to add a card by dealing another card to the

73
00:04:49,560 --> 00:04:50,393
computer.

74
00:04:51,120 --> 00:04:56,120
And then we're going to recalculate the computer_score so that it updates

75
00:04:56,760 --> 00:05:00,570
and this while loop is evaluated on the latest score.

76
00:05:01,260 --> 00:05:06,150
So the computer_score is going to equal calculate_score using the computer's

77
00:05:06,150 --> 00:05:06,983
cards.

78
00:05:07,740 --> 00:05:12,740
And that means that the updated computer_score is equal to the return value from

79
00:05:13,680 --> 00:05:18,600
calculate_score. So that's hint 12 complete. In the next step

80
00:05:18,660 --> 00:05:22,020
we're going to start comparing our player's hand with the dealer's hand.

81
00:05:22,350 --> 00:05:23,430
See you in the next lesson.

