All right.
Let's talk about the mechanics and the program requirements for the Blackjack
game that you'll create. For those of you who are not familiar with the game of
Blackjack also known as 21,
I'm just going to spend a few minutes to go through the rules with you.
Blackjack is a game that's played using cards.
And the goal of the game is to add up your cards to the largest number without
going over 21. If the cards in your hand
add up two more than 21, then it's called a bust
and it means that you lose immediately.
And it doesn't matter how much you've gone over 21, as long as it's over 21,
then you lose. Now the way that the cause are counted
is that all the cards from 2 to 10 count as their face value.
So a six is a six and a nine is a nine, et cetera.
But the Jack, Queen and King each count as 10 and the other special card is the
Ace.
Now the Ace can either count as a one towards your total,
or it can count as an 11. And depending on whether,
if you've gone over 21 or whether if you're under 21,
you can decide which value you want your Ace to represent.
Let's play a sample game. Let's say that the dealer over here got
a 10 to begin with and you got a queen which also counts as a 10 to begin with.
So these
are the first cars that are dealt and both of these cards are revealed.
And then the dealer deals another card to each of you. Now the dealer's
second hand is concealed so you can't work out what their total is,
but you can see your own card.
So the moment we don't know what the dealer has,
it might be 10 plus anything,
but we know that our score is 13, 10 + 3.
At this point you might ask the dealer for another card.
So now you have three cards and luckily it adds up to 20 without going over 21.
But there is also a possibility that you might've gotten a card that would have
pushed your total over 21 at which point you now lose.
And it doesn't matter what the dealer has in their hand,
you've already lost because you've gone over 21.
Now let's say that we got lucky and our total adds up to 20.
Now at this point we say we don't want any more cards
and the dealer reveals their hand. If. like in this case,
they end up with 20 and we have 20,
then we end up in a draw.
So whenever your score equals the dealer score,
then you will draw rather than win or lose. Now,
if on the other hand, the dealer ended up with an Ace,
which we know can count as an 11 and they actually scored higher than us.
They have 21 and we have 20, well, in this case, we would lose.
Now the rules also state that if the dealer ends up with a hand that's smaller
than 17, so 16 or under,
then they must take another card.
Those are the basic rules of blackjack,
but I'd recommend that before you get started head over to the link that's in
the Blackjack starting file and have a few games of Blackjack
just so that you can see for yourself how it actually works and how you win and
how you lose.
And then head over to the final version of the completed project and play our
simplified version of Blackjack. This way
you'll see what the end result is that you're trying to create
and it will be easier when you're creating the code yourself. Now,
as I mentioned,
we're going to try and keep our version of Blackjack a little bit simpler,
and we're going to assume a couple of things.
The first thing is that the card's that we're starting with comes from this
list. You'll notice that I've got 2 through to 10,
all represented in the list.
And then I've got Jack, Queen and King represented as tens as well.
So this means that the 10 has four times the probability of occurring compared
to the other cards.
Now the Ace is going to start off being represented as 11,
and it's going to count as 11 until the user goes over 21.
Now finally, we're going to assume that we have an infinite deck.
So it means that when a card is drawn from the deck,
it's not removed from the deck. Whereas in a real casino,
they have maybe six or eight decks of cards. When a card is drawn,
then there's less probability of that same card occurring again.
And this is how professional card counters,
the people that the casinos hate the most,
actually go about trying to optimize and improve their chances.
But in order to keep things simple in our game,
we're not going to deal with things regarding probability or removing cards from
the deck.
We're going to assume that each of these cards in the list have equal chance of
occurring. If you head over to the App Brewery Blackjack
starting project,
you'll see each of these rules written out in more detail.
Take a look at it so that you're aware what our house rules dictate.
Now, if you scroll to the very top of the Blackjack project,
I've given you four tracks. So just as when you start a video game
you have the choice of normal, hard, extra hard or expert,
it's the same in this project. You can limit yourself to using only one
hint if you are at expert level in Python.
You can only use hint 1 and 2
if you want an extra hard challenge and maybe a little bit of a cry at the end,
there's also hard and normal. So I'll leave the choice up to you.
And if you scroll down, you'll find all the hints listed in here.
Now I recommend everybody, no matter your experience,
everybody should try out the Blackjack game and also look at how the final
project is supposed to work.
But then I've got other things such as a list where I've broken down the program
requirements. You know how we always say, when you have a big problem,
always try to break it down into smaller pieces.
Now you can of course create this list yourself by exploring the game,
exploring the final project,
and then writing your own to do list of things that need to be coded up.
Or alternatively,
you can look at the one that I've created inside hint 2. Inside hint 3
I've created a flowchart for you
which takes the to-do list and breaks it down into a flowchart where you can
look at the logic in more detail. Now, of course, as always,
it's a good idea to create your own flowchart
using a tool like draw.io or using a piece of pen and paper.
But if you need help,
it's there for you and you can download the PDF and read through it.
Now the rest of the hints
will go through how to solve this project in even smaller
bite-size chunks. Depending on your own level of Python at the moment,
choose your own difficulty level.
But I just want to say before you get started that this project is difficult and
I wanted to give you a bit of a challenge and to push yourself so that you get
stronger.
But it will inevitably be moments where you will have doubt and you will be
wondering, what am I doing? I don't understand anything. And in this moment,
I want you to look yourself in the mirror and tell yourself that you got this.
You can do it. And that remember that I'm here rooting for you.
I believe you can do it.
You've got everything that you've learned so far will enable you to do it.
There's nothing new in this challenge.
You just have to put all the pieces together.
You have to push through the difficult parts and maybe sleep on a problem and
think about it and then come back to it. But I believe you can do it. Once
you're ready, pause the video,
head over to the starting project and give it a go.
And once you're satisfied,
then head over to the next lesson and I'll walk through the solution with you.