Hey there,
We're almost done with coding solutions for determining the various hands in the card game of poker. In this article, you'll learn how to code the solution for the full house.
A full house is a hand that contains a pair of cards on one value (rank), and a three of a kind of another value.
You can check out the poker hands that have already been covered, using the links below:
Full House over Full House 10 minutes ago. Among other things, visitors will find a daily dose of articles with the latest poker news, live reporting from tournaments, exclusive videos.
- What makes a full house in poker? A Full House is any three cards of the same number or face value, plus any other two cards of the same number or face value. An example of a full house is, but is.
- What is a Full House in poker? A Full House is made out of five cards where three of them are of the same value, and the remaining two are of another matching value. It looks like Q-Q-Q-3-3.
- Multiplying 156 distinct full house hands times 24 possible suit combinations gives us 3,744 possible ways to draw a full house out of a 52-card deck. In Texas Hold'em, the world's most popular poker game, the probability of making a full house is 2.6% with all five community cards on the board. The Math Behind a Flush.
- Full house (you are here)
- Four of a kind
- Royal flush (an ace-high straight flush)
Setup
Continuing the trend in the series, yep, you guessed it, the code setup has not changed. 🙂
A brief summary of the setup is below. If you'd like to skip ahead of this section, click here. If you want to see the full details of the setup, check out this link.
Card Values Card Suits Card HandDesempate Poker Full House Game
A hand is an array of Card
objects:
Writing The Code To Identify A Full House
Although the full house is essentially a pair and a three of a kind combined into one hand, it's a little more of a challenge, especially when wild cards are involved.
Desempate Poker Full House Games
Just as with coding solutions for the other poker hands, first make sure the cards in your hand are sorted by descending value.
Also, we'll be using the utilities class, CardMatchUtils
. This is the class we've been building that contains common functionality used across all poker hands.
There are two specific functions that CardMatchUtils
will use:
CardMatchUtils.SortCardsByDescendingValue
– This function sorts the cards in the hand by descending value. This orders the cards from highest value to lowest.CardMatchUtils.DoCardsHaveSameValue
– This function determines if a certain number of cards of a specific value are found in the hand.
Now let's get into some pseudo code! 😎
The function takes one parameter, sortedHand
which a hand that has already been passed to CardMatchUtils.SortCardsByDescendingValue
Time slot for meeting email. , and the result being used as this parameter.
Writing out the main function for a full house looks like this:
When the cards are sorted by descending value, there are two possible combinations for a full house. The first one is if the three of a kind comes first, followed by a pair, and it looks like this:
The second combination is if the pair comes first, followed by the three of a kind:
And if you have a wild card with a two pair, that also forms a full house:
Also, because of those blasted wild cards (damn you, (: ), they can be used in either the three of a kind or the two pair, and we need to keep track of who many wild cards are left remaining, while the AreCardsFullHouse
function is running.
Desempate Poker Full House Plans
CardMatchUtils.DoCardsHaveSameValue
is a function that determines if a certain number of cards in the hand have the same value. The function takes three parameters:
sortedHand
– The hand, already assumed to be sorted in descending order by card rank.numToMatch
– The number of cards that must have the same value.wildsInfo
– An object that stores information about the wild cards.
The wildsInfo
parameter is used to save information for multiple calls to CardMatchUtils.DoCardsHaveSameValue
. First declare an empty object { }. The first time you call the function, you'd pass in this empty object. On subsequent calls to CardMatchUtils.DoCardsHaveSameValue
, you'd pass in the same object.
While CardMatchUtils.DoCardsHaveSameValue
is running, it creates two properties on the wildsInfo
object:
Although the full house is essentially a pair and a three of a kind combined into one hand, it's a little more of a challenge, especially when wild cards are involved.
Desempate Poker Full House Games
Just as with coding solutions for the other poker hands, first make sure the cards in your hand are sorted by descending value.
Also, we'll be using the utilities class, CardMatchUtils
. This is the class we've been building that contains common functionality used across all poker hands.
There are two specific functions that CardMatchUtils
will use:
CardMatchUtils.SortCardsByDescendingValue
– This function sorts the cards in the hand by descending value. This orders the cards from highest value to lowest.CardMatchUtils.DoCardsHaveSameValue
– This function determines if a certain number of cards of a specific value are found in the hand.
Now let's get into some pseudo code! 😎
The function takes one parameter, sortedHand
which a hand that has already been passed to CardMatchUtils.SortCardsByDescendingValue
Time slot for meeting email. , and the result being used as this parameter.
Writing out the main function for a full house looks like this:
When the cards are sorted by descending value, there are two possible combinations for a full house. The first one is if the three of a kind comes first, followed by a pair, and it looks like this:
The second combination is if the pair comes first, followed by the three of a kind:
And if you have a wild card with a two pair, that also forms a full house:
Also, because of those blasted wild cards (damn you, (: ), they can be used in either the three of a kind or the two pair, and we need to keep track of who many wild cards are left remaining, while the AreCardsFullHouse
function is running.
Desempate Poker Full House Plans
CardMatchUtils.DoCardsHaveSameValue
is a function that determines if a certain number of cards in the hand have the same value. The function takes three parameters:
sortedHand
– The hand, already assumed to be sorted in descending order by card rank.numToMatch
– The number of cards that must have the same value.wildsInfo
– An object that stores information about the wild cards.
The wildsInfo
parameter is used to save information for multiple calls to CardMatchUtils.DoCardsHaveSameValue
. First declare an empty object { }. The first time you call the function, you'd pass in this empty object. On subsequent calls to CardMatchUtils.DoCardsHaveSameValue
, you'd pass in the same object.
While CardMatchUtils.DoCardsHaveSameValue
is running, it creates two properties on the wildsInfo
object:
numWilds
– The number of wild cards available for use as substitutes.startIndex
– The index of thesortedHand
array on which DoCardsHaveSameValue starts when it checks each card in the hand.
These properties are modified and saved while CardMatchUtils.DoCardsHaveSameValue
runs. Each subsequent call to this function continues where the previous one left off. For example, if the hand contains one or more wild cards and at least one was used to, say, form a three of a kind, the numWilds
will be updated for use in the next call to CardMatchUtils.DoCardsHaveSameValue
.
The CardMatchUtils.DoCardsHaveSameValue
function is explained in detail here, and you can go back to review it if you want. It's a rather long one, but it does the brunt of the work of checking for a full house.
Build Your Own Hand
You can use the controls below to create your own hand to see if it is a full house. It will also recognize previous poker hands we've covered up to this point. Have fun playing around with it! ⭐
If you have any questions about recognizing a full house hand, the above interaction, or any of the other poker hands, please let me know at cartrell@gameplaycoder.com.
Finally, if you'd like to hire me to program an actual card game for you, please e-mail me, or use the contact form here.
That's all for this article. Thanks, and stay tuned as we are almost finished with this series! 💪🏾
Borgata roulette minimum rules. – C. out.