Hey, and welcome back in this lesson, we're going to be fixing the playoffs, so in order to do that,
let's update and tweak the number of cards that we're going to be working with so we can easier throw
a tie game.
So we've got two and threes only.
So we're only dealing out eight cards, which makes it much more likely in order to get a tie.
So going down to our function where we're making the cards, we're going to fix this function and we're
going to shorten this one, because in order for the tiebreaker, we're going to have to run a lot of
the same code.
So updating this and we'll call this one deal around and we need some information that needs to be placed
in.
So this is the player list of players that we need to do the testing for, as well as what we're going
to pass in temp holders.
Let's the list of cards that we have to work with.
So that's all going to get passed into the function.
And this function is relatively going to do the same thing as we originally had the make cards do.
So I'm going to copy a little bit of this where we're going to keep temp holder in, make cards and
almost everything else we're taking out and we're going to drop in to our deal round function, including
the updater.
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
reusing.
So what do we want to pass in to that deal round?
Holder and we've got to think for replay ability.
So let's create an object, an array for we can call it player list and then we're going to loop through
this player list.
So letting X equal zero and while X is less than player's length, so this is getting all of the player,
we loop through this block of code and then in here we can take players X and we can update the inner
HTML.
So that will clear out that content there.
That's the cards that are being shown.
So this way when we're doing the tiebreakers, we're going to list out a whole bunch of cards and we're
also going to check to see.
This is also a good opportunity to check to see if the length of this is greater than zero.
So this is the deck of cards that each player has handed or their list of cards.
And if they are larger than zero, then we are going to push that player value into the player list
array.
So as we iterate through here, this will create a list of existing players and we might also want to
keep that one as is, and update only the value of the current ones that we're utilizing.
So now let's pass over into the function dll round.
We're going to pass over the player list as well as the temp holder.
And the reason we're doing this way is so that we can constantly loop through here and have as many
rounds of the playoffs as needed in order to determine a winner.
So going over to here, there's a few things that we do need to change.
So are coming in and we're setting our winner so that can work the same way and we're looping through.
And this time we're not looping through all the players, but we're looping through the players list
only.
And we also need to set a variable.
Instead of using X, we're going to have a value of player index or temp player index, and this will
be equal to the content coming from players list.
And remember, this is a value that we had set earlier, and this is also the value that we're going
to be passing in to this function.
So when we list a player list, you're going to see the listing of players that are available.
So now this one's not going to work.
But if we do through if we do get a match here, we see that the player lists that we're passing in
here is going to be a listing of all the available players that we have in play.
So we've got the two, three, two, and we're still always passing in all of the players so we can
use this index value.
So it's going to be zero one two.
And these are, of course, the players that we're utilizing.
And it's going to be a lot more self-explanatory why this happened.
When we loop through this function again, when we call deal round within DLL Round and we keep iterating
through, we can get rid of the clearing of the HTML because we don't want to do this anymore as we've
already doing it up here within that initial function where we're calling the deal round.
So the next thing that we want to do is we want to get back and return back checking to see if the player
has cards and the way that we can do that again, we can use the deals array and then now we've got
a new index value.
So this is coming from the player list.
So this is the list of players that are currently in play that we want to select.
And we're checking to see if the left or how many cards they have left.
So everything with deals is how many cards are left in.
And we're going to keep this within an array and we can loop through and this will return back all of
the player information.
So this is all where we're updating and we're getting cards and and so on.
And actually, this should also be included that we're pushing and we're showing the cards.
So if the player doesn't have any cards left, then we're not going to show any cards and they're automatically
not going to be included as a winner because obviously they don't have any cards left to play.
So they're automatically going to lose and they're going to be out of the game.
So that's what this condition is going to do.
So next thing that we want to do is we want to get the card and the card that we want to get instead
of X.
Now, it's going to be player index because we do have a separate index.
So originally when we have all three players in play, we're using zero one two.
So it's the same thing that we were doing with the player's list.
But now because we're selecting out that index, this might change.
So we might not have all the players in play because it might be only a few players that are within
the playoffs.
So we're getting the card now from Tampa Player Index.
And then this functionality is the same.
We don't need to get all of we only need the current player value.
So we don't need to pass in the card because we're not really utilizing that.
So let's grab that player value.
And instead of X, this value is going to be the player index value.
So that shortened that a little bit as well.
And instead of X over here, we're updating with the player index.
And then lastly, when we show the card, we're updating with the player index.
So we'll see how that works.
And right now, we're not going to see much of a difference because we haven't had had an opportunity
to add in our loop yet.
So this is where we initially planned to do the playoff and this is where we can apply conditions.
So I'm going to get rid of that functionality and we're going to apply our condition.
So we're checking to see if playoff length is greater than zero.
And if it is, that means that we do have a tie.
And if we don't, then we're OK to apply the updater function.
So if it is greater than zero, then what we're going to do is we're going to loop back into deal round.
We're going to pass in the current available players, which are going to be sitting in the playoff
array that we've built out.
So notice over here where we're adding those winners in.
So we're adding them in here.
And actually this function should be sitting outside.
So this will give us the opportunity to add multiple into the playoffs.
So if we have more than one in the playoff, we can continuously add them in.
So that was just a quick fix there.
So going by and we're adding in just the index value of the player.
So that's what we've got within playoff.
And so now when we're passing in playoff, it's going to be the same thing as the player list.
And we need to still keep temp holder because this is the amount of cards that are going to be one.
So ultimately, once we don't have any more ties, then we're going to run updater and we're going to
pass in the winning player and then also pass in the amount of cards that they've won.
So let's see how that works.
So we see that now over here, we see we've got a two, three, three.
So that was a tie.
And then player two ended up with another three and player three ended up with a two.
So they ended up losing and at the end, player two one five cards.
So they want all of those cards.
So now they're holding on to six cards.
And player one has to we can run the attack again.
And what happened here is that we have player two one eight one five more cards.
And so we ran the first round there.
So two, two, three, three.
And then player one ran out of cards and player two ended up with all the cards.
So this is where we've got our winning condition.
And the other thing here is that we should be clearing out that player three content because they don't
need to be showing that anymore.
So let's update this where we're setting the value as we're making the cards and that we're always clearing
that out because we're putting the lost anyway.
If the player doesn't have any cards left and we can adjust that if we want.
So we're not constantly outputting, lost, lost, lost.
Maybe if they're out of the game, then we want to have something more permanent so we can do that as
well.
So again, let's try that out and we can see that now.
Player two ends up with seven cards.
Player one has one.
And then lastly, player two ends up with eight cards and player one has now lost.
So we actually have an ending of the game where we've got the ability to run an end of the game and
both of the ones that end up with Lost are lost.
And this is the point where we can restart the game.
So when one player has.
All of the cards we can restart the game, so I know this was a fairly complex lesson, but do add this
in.
And then again, the reason that we pulled all of this functionality out is because we're reusing it
within that win condition when we're considering the tie game and we need it ability to send information
depending on who is within which players we should be looking at and which one should be drawing another
card.
And then we're also still comparing which one is the winner until we get a clear winner and until we
reach a point where we only have one winner, which is applied with the logic here.
And then that one winner that we're passing in here ends up with all of the cards.
So go ahead and update this in your project.
And coming up next, to reduce some tweaks and adjustments to the gameplay.