1
00:00:00,300 --> 00:00:05,370
Hey, and welcome back in this lesson, we're going to be fixing the playoffs, so in order to do that,

2
00:00:05,580 --> 00:00:12,210
let's update and tweak the number of cards that we're going to be working with so we can easier throw

3
00:00:12,210 --> 00:00:13,080
a tie game.

4
00:00:13,260 --> 00:00:15,870
So we've got two and threes only.

5
00:00:15,900 --> 00:00:20,690
So we're only dealing out eight cards, which makes it much more likely in order to get a tie.

6
00:00:20,910 --> 00:00:26,310
So going down to our function where we're making the cards, we're going to fix this function and we're

7
00:00:26,310 --> 00:00:31,050
going to shorten this one, because in order for the tiebreaker, we're going to have to run a lot of

8
00:00:31,080 --> 00:00:31,890
the same code.

9
00:00:32,310 --> 00:00:39,060
So updating this and we'll call this one deal around and we need some information that needs to be placed

10
00:00:39,060 --> 00:00:39,340
in.

11
00:00:39,480 --> 00:00:46,800
So this is the player list of players that we need to do the testing for, as well as what we're going

12
00:00:46,800 --> 00:00:48,410
to pass in temp holders.

13
00:00:48,430 --> 00:00:51,540
Let's the list of cards that we have to work with.

14
00:00:51,730 --> 00:00:54,210
So that's all going to get passed into the function.

15
00:00:54,390 --> 00:00:59,610
And this function is relatively going to do the same thing as we originally had the make cards do.

16
00:00:59,790 --> 00:01:04,890
So I'm going to copy a little bit of this where we're going to keep temp holder in, make cards and

17
00:01:04,890 --> 00:01:12,660
almost everything else we're taking out and we're going to drop in to our deal round function, including

18
00:01:12,660 --> 00:01:13,350
the updater.

19
00:01:13,350 --> 00:01:17,670
So let's grab that and we're going to pass that in here because a lot of the stuff we're going to be

20
00:01:17,670 --> 00:01:18,330
reusing.

21
00:01:18,570 --> 00:01:21,840
So what do we want to pass in to that deal round?

22
00:01:21,840 --> 00:01:24,690
Holder and we've got to think for replay ability.

23
00:01:24,990 --> 00:01:31,770
So let's create an object, an array for we can call it player list and then we're going to loop through

24
00:01:31,770 --> 00:01:33,150
this player list.

25
00:01:33,150 --> 00:01:41,640
So letting X equal zero and while X is less than player's length, so this is getting all of the player,

26
00:01:42,420 --> 00:01:49,290
we loop through this block of code and then in here we can take players X and we can update the inner

27
00:01:49,300 --> 00:01:50,000
HTML.

28
00:01:50,010 --> 00:01:52,830
So that will clear out that content there.

29
00:01:52,830 --> 00:01:54,830
That's the cards that are being shown.

30
00:01:55,230 --> 00:01:59,700
So this way when we're doing the tiebreakers, we're going to list out a whole bunch of cards and we're

31
00:01:59,700 --> 00:02:01,140
also going to check to see.

32
00:02:01,140 --> 00:02:08,030
This is also a good opportunity to check to see if the length of this is greater than zero.

33
00:02:08,220 --> 00:02:13,110
So this is the deck of cards that each player has handed or their list of cards.

34
00:02:13,410 --> 00:02:21,510
And if they are larger than zero, then we are going to push that player value into the player list

35
00:02:21,510 --> 00:02:21,950
array.

36
00:02:22,410 --> 00:02:29,430
So as we iterate through here, this will create a list of existing players and we might also want to

37
00:02:30,210 --> 00:02:36,750
keep that one as is, and update only the value of the current ones that we're utilizing.

38
00:02:37,050 --> 00:02:40,650
So now let's pass over into the function dll round.

39
00:02:40,860 --> 00:02:45,120
We're going to pass over the player list as well as the temp holder.

40
00:02:45,540 --> 00:02:52,350
And the reason we're doing this way is so that we can constantly loop through here and have as many

41
00:02:52,350 --> 00:02:56,950
rounds of the playoffs as needed in order to determine a winner.

42
00:02:57,240 --> 00:03:00,960
So going over to here, there's a few things that we do need to change.

43
00:03:01,140 --> 00:03:06,840
So are coming in and we're setting our winner so that can work the same way and we're looping through.

44
00:03:06,840 --> 00:03:11,790
And this time we're not looping through all the players, but we're looping through the players list

45
00:03:11,790 --> 00:03:12,270
only.

46
00:03:12,600 --> 00:03:14,460
And we also need to set a variable.

47
00:03:14,670 --> 00:03:21,540
Instead of using X, we're going to have a value of player index or temp player index, and this will

48
00:03:21,540 --> 00:03:24,720
be equal to the content coming from players list.

49
00:03:24,930 --> 00:03:29,850
And remember, this is a value that we had set earlier, and this is also the value that we're going

50
00:03:29,850 --> 00:03:32,110
to be passing in to this function.

51
00:03:32,130 --> 00:03:37,190
So when we list a player list, you're going to see the listing of players that are available.

52
00:03:37,380 --> 00:03:39,030
So now this one's not going to work.

53
00:03:39,240 --> 00:03:45,780
But if we do through if we do get a match here, we see that the player lists that we're passing in

54
00:03:45,780 --> 00:03:50,420
here is going to be a listing of all the available players that we have in play.

55
00:03:50,610 --> 00:03:56,820
So we've got the two, three, two, and we're still always passing in all of the players so we can

56
00:03:56,820 --> 00:03:58,890
use this index value.

57
00:03:59,010 --> 00:04:01,140
So it's going to be zero one two.

58
00:04:01,380 --> 00:04:04,590
And these are, of course, the players that we're utilizing.

59
00:04:04,740 --> 00:04:09,270
And it's going to be a lot more self-explanatory why this happened.

60
00:04:09,510 --> 00:04:15,180
When we loop through this function again, when we call deal round within DLL Round and we keep iterating

61
00:04:15,180 --> 00:04:20,940
through, we can get rid of the clearing of the HTML because we don't want to do this anymore as we've

62
00:04:20,940 --> 00:04:25,950
already doing it up here within that initial function where we're calling the deal round.

63
00:04:26,160 --> 00:04:34,860
So the next thing that we want to do is we want to get back and return back checking to see if the player

64
00:04:34,890 --> 00:04:41,730
has cards and the way that we can do that again, we can use the deals array and then now we've got

65
00:04:41,730 --> 00:04:43,040
a new index value.

66
00:04:43,080 --> 00:04:45,240
So this is coming from the player list.

67
00:04:45,480 --> 00:04:50,580
So this is the list of players that are currently in play that we want to select.

68
00:04:50,850 --> 00:04:55,650
And we're checking to see if the left or how many cards they have left.

69
00:04:55,650 --> 00:04:59,580
So everything with deals is how many cards are left in.

70
00:05:00,110 --> 00:05:05,810
And we're going to keep this within an array and we can loop through and this will return back all of

71
00:05:05,840 --> 00:05:06,980
the player information.

72
00:05:06,990 --> 00:05:12,110
So this is all where we're updating and we're getting cards and and so on.

73
00:05:12,320 --> 00:05:17,080
And actually, this should also be included that we're pushing and we're showing the cards.

74
00:05:17,360 --> 00:05:22,820
So if the player doesn't have any cards left, then we're not going to show any cards and they're automatically

75
00:05:22,820 --> 00:05:26,690
not going to be included as a winner because obviously they don't have any cards left to play.

76
00:05:26,900 --> 00:05:30,170
So they're automatically going to lose and they're going to be out of the game.

77
00:05:30,530 --> 00:05:32,520
So that's what this condition is going to do.

78
00:05:32,900 --> 00:05:39,290
So next thing that we want to do is we want to get the card and the card that we want to get instead

79
00:05:39,290 --> 00:05:39,880
of X.

80
00:05:39,890 --> 00:05:43,880
Now, it's going to be player index because we do have a separate index.

81
00:05:44,090 --> 00:05:49,110
So originally when we have all three players in play, we're using zero one two.

82
00:05:49,280 --> 00:05:52,670
So it's the same thing that we were doing with the player's list.

83
00:05:52,880 --> 00:05:56,530
But now because we're selecting out that index, this might change.

84
00:05:56,540 --> 00:06:01,250
So we might not have all the players in play because it might be only a few players that are within

85
00:06:01,250 --> 00:06:01,870
the playoffs.

86
00:06:02,660 --> 00:06:05,840
So we're getting the card now from Tampa Player Index.

87
00:06:06,020 --> 00:06:08,240
And then this functionality is the same.

88
00:06:08,510 --> 00:06:13,760
We don't need to get all of we only need the current player value.

89
00:06:13,760 --> 00:06:16,910
So we don't need to pass in the card because we're not really utilizing that.

90
00:06:17,180 --> 00:06:19,400
So let's grab that player value.

91
00:06:19,400 --> 00:06:24,320
And instead of X, this value is going to be the player index value.

92
00:06:25,040 --> 00:06:27,800
So that shortened that a little bit as well.

93
00:06:27,800 --> 00:06:31,880
And instead of X over here, we're updating with the player index.

94
00:06:32,090 --> 00:06:36,200
And then lastly, when we show the card, we're updating with the player index.

95
00:06:36,500 --> 00:06:37,580
So we'll see how that works.

96
00:06:37,850 --> 00:06:43,960
And right now, we're not going to see much of a difference because we haven't had had an opportunity

97
00:06:43,960 --> 00:06:45,220
to add in our loop yet.

98
00:06:45,530 --> 00:06:50,750
So this is where we initially planned to do the playoff and this is where we can apply conditions.

99
00:06:50,750 --> 00:06:55,010
So I'm going to get rid of that functionality and we're going to apply our condition.

100
00:06:55,190 --> 00:07:01,370
So we're checking to see if playoff length is greater than zero.

101
00:07:01,640 --> 00:07:03,920
And if it is, that means that we do have a tie.

102
00:07:04,190 --> 00:07:08,440
And if we don't, then we're OK to apply the updater function.

103
00:07:08,720 --> 00:07:16,490
So if it is greater than zero, then what we're going to do is we're going to loop back into deal round.

104
00:07:16,730 --> 00:07:23,450
We're going to pass in the current available players, which are going to be sitting in the playoff

105
00:07:23,450 --> 00:07:24,760
array that we've built out.

106
00:07:24,950 --> 00:07:29,510
So notice over here where we're adding those winners in.

107
00:07:29,510 --> 00:07:31,190
So we're adding them in here.

108
00:07:31,190 --> 00:07:34,250
And actually this function should be sitting outside.

109
00:07:34,260 --> 00:07:37,940
So this will give us the opportunity to add multiple into the playoffs.

110
00:07:37,950 --> 00:07:41,590
So if we have more than one in the playoff, we can continuously add them in.

111
00:07:41,720 --> 00:07:43,150
So that was just a quick fix there.

112
00:07:43,760 --> 00:07:49,190
So going by and we're adding in just the index value of the player.

113
00:07:49,200 --> 00:07:50,950
So that's what we've got within playoff.

114
00:07:51,110 --> 00:07:55,940
And so now when we're passing in playoff, it's going to be the same thing as the player list.

115
00:07:56,210 --> 00:08:01,400
And we need to still keep temp holder because this is the amount of cards that are going to be one.

116
00:08:02,240 --> 00:08:10,220
So ultimately, once we don't have any more ties, then we're going to run updater and we're going to

117
00:08:10,220 --> 00:08:15,830
pass in the winning player and then also pass in the amount of cards that they've won.

118
00:08:16,190 --> 00:08:17,370
So let's see how that works.

119
00:08:17,390 --> 00:08:22,970
So we see that now over here, we see we've got a two, three, three.

120
00:08:22,970 --> 00:08:23,960
So that was a tie.

121
00:08:24,170 --> 00:08:28,100
And then player two ended up with another three and player three ended up with a two.

122
00:08:28,100 --> 00:08:32,930
So they ended up losing and at the end, player two one five cards.

123
00:08:32,930 --> 00:08:34,460
So they want all of those cards.

124
00:08:34,610 --> 00:08:36,560
So now they're holding on to six cards.

125
00:08:36,710 --> 00:08:39,920
And player one has to we can run the attack again.

126
00:08:40,070 --> 00:08:48,710
And what happened here is that we have player two one eight one five more cards.

127
00:08:49,010 --> 00:08:50,900
And so we ran the first round there.

128
00:08:50,900 --> 00:08:52,820
So two, two, three, three.

129
00:08:52,940 --> 00:08:57,230
And then player one ran out of cards and player two ended up with all the cards.

130
00:08:57,620 --> 00:09:00,170
So this is where we've got our winning condition.

131
00:09:00,380 --> 00:09:05,870
And the other thing here is that we should be clearing out that player three content because they don't

132
00:09:05,870 --> 00:09:07,850
need to be showing that anymore.

133
00:09:08,090 --> 00:09:16,400
So let's update this where we're setting the value as we're making the cards and that we're always clearing

134
00:09:16,400 --> 00:09:19,040
that out because we're putting the lost anyway.

135
00:09:19,280 --> 00:09:23,810
If the player doesn't have any cards left and we can adjust that if we want.

136
00:09:24,260 --> 00:09:27,590
So we're not constantly outputting, lost, lost, lost.

137
00:09:28,370 --> 00:09:32,300
Maybe if they're out of the game, then we want to have something more permanent so we can do that as

138
00:09:32,300 --> 00:09:32,570
well.

139
00:09:32,720 --> 00:09:36,200
So again, let's try that out and we can see that now.

140
00:09:36,320 --> 00:09:38,630
Player two ends up with seven cards.

141
00:09:38,630 --> 00:09:39,740
Player one has one.

142
00:09:40,070 --> 00:09:44,960
And then lastly, player two ends up with eight cards and player one has now lost.

143
00:09:45,230 --> 00:09:52,280
So we actually have an ending of the game where we've got the ability to run an end of the game and

144
00:09:52,280 --> 00:09:54,860
both of the ones that end up with Lost are lost.

145
00:09:55,520 --> 00:09:57,950
And this is the point where we can restart the game.

146
00:09:57,950 --> 00:09:59,060
So when one player has.

147
00:09:59,210 --> 00:10:05,330
All of the cards we can restart the game, so I know this was a fairly complex lesson, but do add this

148
00:10:05,330 --> 00:10:05,630
in.

149
00:10:05,630 --> 00:10:11,360
And then again, the reason that we pulled all of this functionality out is because we're reusing it

150
00:10:11,360 --> 00:10:19,490
within that win condition when we're considering the tie game and we need it ability to send information

151
00:10:19,790 --> 00:10:25,670
depending on who is within which players we should be looking at and which one should be drawing another

152
00:10:25,670 --> 00:10:26,120
card.

153
00:10:26,240 --> 00:10:32,840
And then we're also still comparing which one is the winner until we get a clear winner and until we

154
00:10:32,840 --> 00:10:38,270
reach a point where we only have one winner, which is applied with the logic here.

155
00:10:38,390 --> 00:10:43,250
And then that one winner that we're passing in here ends up with all of the cards.

156
00:10:43,610 --> 00:10:45,440
So go ahead and update this in your project.

157
00:10:45,620 --> 00:10:49,250
And coming up next, to reduce some tweaks and adjustments to the gameplay.
