Question
Need Help with task 1 & 2. I can attach screentshots of conde if needed. Thank you! PROBABILITY IN POKER HOW LIKELY ARE YOU TO
Need Help with task 1 & 2. I can attach screentshots of conde if needed. Thank you!
PROBABILITY IN POKER HOW LIKELY ARE YOU TO WIN? Background
Texas hold em is one of the most popular variations of poker. At the start, each player is dealt two cards and, as the game progresses, an additional five community cards are dealt face-up. A players best 5-card hand is formed from the cards he is dealt along with the community cards. Due to the large number of different 5-card hands and the increasing complexity as more cards are dealt, we will only focus on the pre-flop portion of the game, i.e., before the community cards are dealt. This way, each player has two cards and we only need to be familiar with the following 2-card hands: one pair and high card. Hence, given a standard 52-card deck with 13 ranks,
2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace (listed from lowest rank to highest), and 4 suits,
Spades (), Clubs (), Hearts (), Diamonds (),
a pair is any 2-card hand where both cards are of equal rank. For our 2-card case, a high card is any non-pair hand. A pair is higher in rank than a high card. The strength of a pair is determined by the rank of the cards that compose that pair, for example QQ is better than 88. Similarly, the strength of a high card hand is determined by the highest ranked card in that hand, for example J2 is better than 109. It then follows that an ace high card (e.g., A7) is the strongest high card hand and can only be beaten by a pair.
Objectives
In this assignment, we will use combinatorics to count and analyze poker hands in the pre-flop stage of a Texas hold em game of poker. To simplify our analysis, we will only have two players in the game. Player 1s cards will be specified by the user. Then, the objective is to compute the probabilities of different hands for Player 2 based on the cards dealt to P1. These probabilities will be outputted in the form of a bar plot.
Procedure
You are given a file Texas_HoldEm.m with the following function inside of it:
function Texas_HoldEm(card1, card2)
The inputs card1 and card2 are strings that specify P1s starting (pre-flop) hand with the following format: '
>> Texas_HoldEm('JD', '2C') or
>> Texas_HoldEm('2C', 'JD') The function will parse these strings for you and format the chosen cards into a binary 4-by-13
matrix called CardMatrix: 'A' 'K' 'Q' 'J' '10' '9' '8' '7' '6' '5' '4' '3' '2'
'S' () 'D' () 'H' () 'C' ()
Note that there are 52 entries corresponding to the 52 different cards in the deck. If an entry contains a 1, then P1 has the card corresponding to that entry; otherwise, it contains a 0. In the example above, P1 has been dealt J2.
If we dont care about suits, we can collapse this matrix into an array by summing along the rows:
sum(CardMatrix)
'A' 'K' 'Q' 'J' '10' '9' '8' '7' '6' '5' '4' '3' '2'
If we dont care about card ranks, we can sum along the columns:
sum(CardMatrix, 2)
'S' () 'D' () 'H' () 'C' ()
This sort of formatting will allow us to count the various different hands that P2 can make based on P1s cards in an efficient manner, without the use of excessive conditional statements. (In fact, the implementation in the following tasks can easily be extended to more players when this sort of organization is used). Also note that since the order of the cards does not matter, only combinations along with the addition and multiplication principles are needed throughout this assignment (no permutations necessary).
Task 1: Compute the probability that P2 has a pair. As a warm-up, consider the following specific situation: P1 is dealt J2. Then, the total number of pairs that P2 can make in this situation is:
# of one pair for P2 = 11 (2/4) +2 (2/3) .
If P2 has a pair of Jacks, it must be formed from the 3 Jacks left in the deck since P1 already has a J. The same logic applies for a pair of 2. For the remaining card ranks, there are 4 available suits in each.
To generalize this calculation for any hand that P1 might have:
1. Create a variable numPairs to store the number of one pair hands that P2 can make. Initialize numPairs to 0.
2. Collapse CardMatrix as previously shown and iterate through each card rank using a for-loop.
3. For each card rank, count the number of possible pairs that P2 can make from a particular card rank using the nchoosek function and add the result to numPairs.
4. After counting the number of all possible pairs, divide this amount by the total amount of 2-card hands that P2 can make to find the probability that P2 has a pair, i.e.:
probability P2 has one pair = # of possible one pair for P2 . total # of possible 2-card hands
Note that at this point, 2 cards have been removed from the deck. Store the probability in a variable probPair.
Task 2: Compute the probability that P2 has an Ace high hand (i.e., a hand that contains an Ace and a non-Ace). Just like in Task 1, utilize CardMatrix along with the nchoosek function to count the number of different Ace high hands that P2 can form in a variable numAceHigh. Divide numAceHigh by the total number of hands P2 can make to find the desired probability and store it in a variable probAceHigh.
Task 3: Compute the probability that P2 has two cards of the same suit. This is very similar to Task 1, however this time we dont care about card ranks and so CardMatrix needs to be collapsed differently. Store this probability in a variable probSuited.
Task 4: Compute the probability that P2s hand is better than P1s hand. This task can be decomposed into two different problems using an if-statement as follows:
1. If P1 has a pair, then P2 must have a higher-ranked pair.
Collapse CardMatrix using the sum function as before in a manner relevant to
this analysis.
The find function can be used on the collapsed CardMatrix to determine the
rank of the pair.
Proceed as in Task 1, but this time only count the pairs that P2 can make which
are of higher rank than P1s.
d. Divide the result by the total number of hands P2 can make and store the result in a variable probBetter.
2. If P1 does not have a pair, then P2 must have either a pair or a higher-ranked high card.
In this case the number of possible pairs is already determined in Task 1.
In addition to this, count the number of higher-ranked high card hands that P2 can
have. Remember, weve already counted pairs in step 2.a.; be very careful not to
over-count.
Divide the sum of all possible pairs and higher-ranked high card hands by the
total number of hands P2 can make and store the result in a variable probBetter.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started