1. Texas Hold'em
The overall theme of Chapter 4 is poker, a game usually played with a standard 52-card deck of cards. In this lesson, we will focus on Texas Hold'em, a particular variant of poker.
2. Community Cards in Texas Hold'em
In Texas Hold'em, each player receives two cards. After some rounds of betting, five cards are placed face up in the middle of the table, and each player makes the best five-card hand that they can, using any combination of their own two cards and the five on the table.
In this example, the player has a king and a queen, and can combine those with the three cards shown to make what is known as a straight, which is five cards of consecutive denominations.
Right now, with three cards on the board, there are still two cards that will come in order to complete the set of all five that will ultimately be face up on the table. Our exercises will pertain to probabilities with two cards left to come, and also one step further in which four cards are on the board and there is just one card left to come.
3. Two cards left to come
The cards that will give us a win are known as outs.
With two cards to come, the easiest way to calculate the probability of winning is to use the complement rule, since calculating it directly would involve accounting for the situations in which one or both of the cards to come is one of our outs.
Suppose, that there are only 10 cards remaining in the deck and we have 3 outs. If there are two cards left to come, there are a total of 10 choose 2 combinations for which these two cards could occur. The probability that we lose is shown in the code as p underscore lose, where the numerator counts the number of ways in which the three outs do not come. We can subtract this from one to obtain the probability of winning.
4. Calculating for different outs simultaneously
We can also use the choose function on a vector. Suppose we want to know the probability of winning if we have 0, 1, 2, or 3 outs. We start by defining the outs variable as the vector containing these four values.
Then, we can use the choose function on the outs variable, which will produce a vector output where each value represents the probability of winning with the corresponding number of outs.
5. Expected values
Recall that the expected value is the theoretical mean or average of the quantity of interest. Its general equation is given on the slide here.
In R, we can leverage vector operations to calculate expected values.
Suppose you are wagering with a friend on a coin flip. If it lands on heads, you owe them 2 dollars, and if it lands on tails, they owe you 3 dollars. The probability of each outcome is 0 point 5, and the possible values of your profit are negative 2 and positive 3.
If we multiply the vectors together, we will get the product of each pair of profit values and probabilities.
To calculate your expected value on this wager, take the sum of this resulting vector. Under this setup, you can expect to win an average of 50 cents.
6. Let's do this!
Let's play some cards.