Poker Hands List
Last Updated on January 1, 2018
- Get this hand and it could certainly charge up your night at the tables. Teepees – The hand earns this name for the points in the “A” that make them look similar to a type of American Indian-style tent. Needles – The A is pointy like a needle. Stick it to your opponents. King-King (K-K) The second-best hand in poker with plenty of pseudonyms.
- The strongest poker hand is the royal flush. It consists of Ten, Jack, Queen, King,.
I recently took a Hackerrank challenge for a job application that involved poker. I'm not a poker player, so I had a brief moment of panic as I read over the problem the description. In this article I want to do some reflection on how I approached the problem.
Poker Hand Rankings: Best to Worst 1. Three of a Kind. When you’re playing any of the three flop games at Bovada Poker (Texas Hold’em, Omaha and Omaha Hi/Lo).
The hackerrank question asked me to write a program that would determine the best poker hand possible in five-card draw poker. We are given 10 cards, the first 5 are the current hand, and the second 5 are the next five cards in the deck. We assume that we can see the next five cards (they are not hidden). We want to exchange any n
number of cards (where n <= 5
) in our hand for the next n
cards in the deck. For example, we can take out any combination of 2 cards from the hand we are given, but we must replace these two cards with the next two cards from the deck (we can't pick any two cards from the deck).
Suit and value make up the value of playing cards. For example, you can have a 3 of clubs. 3 is the value, clubs is the suit. We can represent this as 3C
.
Suits
Clubs CSpades SHeart HDiamonds D
Value (Rank)
2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace
Hands
Here are the hands of poker
Royal flush (the problem didn't ask me to consider Royal Flush)
A, K, Q, J, 10, all the same suit.
Straight flush
Five cards in a sequence, all in the same suit. Ace can either come before 2 or come after King.
Four of a kind
All four cards of the same rank.
Full house
Three of a kind with a pair.
Flush
Any five cards of the same suit, but not in a sequence.
Straight
Five cards in a sequence, but not of the same suit.
Three of a kind
Three cards of the same rank.
Two pair
Two different pairs.
Pair
Two cards of the same rank.
High Card
When you haven't made any of the hands above, the highest card plays.In the example below, the jack plays as the highest card.
Evaluating a hand of cards
A hand is five cards. The first thing I did was write out functions to evaluate if a group of 5 cards satisfies the conditions of one of the ten hands.
Here's a sample hand:
To write functions, I reached for using 2 important python features: set
and defaultdict
.
Here's an example of a simple function to detect a flush, a hand with cards of all the same suit:
Checking a flush
This function creates a list of the suits in our hand, and then counts the unique elements in that list by making it a set. If the length of the set is 1, then all the cards in the hand must be of the same suit.
But wait, what if we have a straight flush? Also, a hand that satisfies a flush could also be described as a two pair hand. The problem asked me to find the highest possible hand for a given set of cards, so I tried to keep things simple by writing a check_hand()
function that checks each hand starting from straight flush down to high card. As soon as a condition for a hand was satisfied, I returned a number that corresponded to the strength of the hand (1 for high card up to 10 for straight flush). The problem didn't include Royal flush, so I will not include that here.
Here's the check_hand
function:
This function starts checking the most valuable hands. After it checks the second to lowest hand (pair), it returns a value of 1. This value of 1 corresponds to the 'highest card' hand. Since I'm not comparing the relative value of hands, it doesn't matter what the highest card is, so the number just represents the type of hand that is the strongest.
Other hands
Here are the all of the functions I used to detect hands:
defaultdict
is a great built-in that is good to use when you don't know what elements will be in your dictionary, but you know what the initial values of any key that could be added should be. We don't need it here, but the alternative would be to write a very long dictionary where keys are the possible card values and the values of each key is 0.
It would certainly be cleaner and more efficient to write out the above functions into one large function, but I wanted to keep things simple as I was under time constraints.
The next step in the problem is to determine the best possible hand we can get given the hand we are dealt and the 5 cards on top of the deck. I decided to first solve this problem with brute force. Here was my logic for this part: use itertools
to get all combinations of groups of 0, 1, 2, 3, 4 and 5 cards from my hand and add the first 5 - n
cards from the deck so we get a five card deck. For each combination of cards we can run check_hand()
and keep track of the highest rank hand, and then return that hand as the best hand. Here's the code I wrote for this part of the problem:
Lastly, I need to check each hand and print out the best hand possible. Here's the loop I wrote to do this:
This will accept one round of cards per line:
and it will output the following:
This was an interesting problem to deal with as the solution contained several parts that worked together. While solving the problem I aimed worked through to the end leaving some parts to come back to that I felt confident in solving. Instead of writing each function to check differnt hands at the beginning, I filled most of these functions with pass
and moved on to write the next part that involves checking each different combination of cards. Recently having worked through python's itertools
exercises on Hackerrank, the combinations
functions was fresh in my mind.
While I was able to arrive at a solution that satisfied the test cases, I did not have time to think about the efficiency or Big O analysis of the problem.
There is obviously some refactoring that I could do to make things cleaner. With more time I would take an object oriented approach by making classes for cards and hands, and adding class methods to evaluate the hands.
For each round, we have to run check_hand()
on each hand combination. Let's think about how many hands we have to evaluate:
We have to consider combinations of cards formed by taking out groups of 0, 1, 2, 3, 4 and 5 cards and adding the next number of cards in the deck that bring the total card count to 5, which means we have to do 5C0 + 5C1 + 5C2 + 5C3 + 5C4 + 5C5 calls to check_hand()
. So the sum of total calls is 1 + 5 + 10 + 10 + 5 + 1 = 32.
For each of these 32 calls that happen when we run play()
, check_hands()
runs through each of the check_
functions starting with the highest value hand. As soon as it finds a 'match', check_hands()
returns a number value (hand_value
) corresponding to straight flush, four of a kind, etc. This value is then compared with the highest value that has been previously found (best_hand
) and replaces that value if the current hand's hand rank has a higher value.
I'm not sure if there is faster way to find the best hand than the brute force method I implemented.
A No-Nonsense Guide to Poker Hands
A Quick Note
We won’t bore you with a long intro today. After all, this is a no-nonsense guide, so why don’t we get right to it:
Please note the following card references:
(h) Hearts (d) Diamonds (c) Clubs (s) Spades
1. Royal Flush
At the top of the pile is a set of five suited consecutive cards with an ace as its highest card. No other hand can beat it, and if two or more active players have it, the pot is split evenly among them. Example: As Ks Qs Js 10s
2. Straight Flush
It’s practically the same as a royal flush but it uses a king or lower as its highest card.
If two or more active players have it, the player with the highest high card wins. The pot gets split evenly between players with the same highest cards. Example: Qc Jc 10c 9c 8c
3. Four of a Kind
This poker hand is made up of four cards of the same value and a random fifth card to complete the set.
In case there’s a tie, the fifth kicker card is used to determine a winner. If the fifth card on the table is higher than the highest kicker card any active player is holding, however, the pot is split evenly among all tied players. Example: 2d 2h 2s 2c Kh
4. Full House
This hand consists of a set of three cards of the same value (also known as a trip) and another set of two cards of the same value (also known as a pair).
If there’s a tie, the trips are compared. If the trips are of the same value, then the pairs are compared. If they’re still tied, then the pot is split evenly among all tied players. Example: 7h 7s 7c 3d 3h
5. Flush
This hand is made up of any five suited cards.
To break ties, the highest high card of each player gets compared. If they’re the same, then the second highest card is checked. The process continues until either one player comes out on top or the pot gets split evenly among players holding flushes of the exact same value. Example: Qd 10d 7d 4d 2d
6. Straight
Five non-suited consecutive cards make up this hand.
Ties, in this case, are broken just like you would with flushes. Example: Jd 10c 9s 8h 7d
7. Three of a Kind
This hand is simply a trip plus two random cards.
In the event of a tie, the trip with the highest value wins. A fourth or fifth kicker card is used to determine a winner in case the trips are of the same value. Example: 5d 5h 5c Kd 9s
8. Two Pair
As the name implies, this hand is just a pair of pairs plus a random fifth card to complete the set.
The high pair is compared in case of a tie. If they’re of the same value, then the low pair is checked. If they’re still tied, then the fifth kicker card is used to determine a winner. Example: Kd Kh 7d 7s 3c
9. Pair
As you may have guessed, this hand only has one pair instead of two so it comes with three other random cards to complete the set.
Ties are broken by first comparing the pair and then moving on to the next three kicker cards in case the pairs are of the same value. Example: 9s 9c 6d 4s 2h
10. High Card
This hand is just five random cards.
Ties are broken in pretty much the same way as with flushes and straights. Example: 9h 6c 5s 3d 2d
Knowing This Poker Hand List is Only the Beginning
These poker hand rankings are fixed for most standard five-card poker games like Texas Holdem. Interestingly, though, having a strong poker hand (except for a royal flush) doesn’t necessarily guarantee that you’ll win. Professional players employ a host of strategies throughout the different stages of the game to outsmart and even force their opponents to fold prematurely. They also have the ability to gauge whether or not their starting hands could later on translate to winning poker hands based on how their opponents are acting and what cards are being revealed on the table.
Of course, all of these things come with experience. Professional players have achieved pro status by playing hundreds of games and doing hours of research, always trying to learn new things, improve their skills and just develop an overall better understanding of the game.
Poker Hands List
The good news is that we can help you do just that because when you sign up for a www.safeclub.com account, you’ll not only get to enjoy real money poker action online, you’ll also get access to more a whole lot more of these poker guides, tips and tricks!