Ace-Five (A-5) High Five – Ace (High) + 5 = High Five. A little clever, and perfect on that 2-3-4 flop. Play it cool, though, no real-life high-fives during the hand. Ace-Four (A-4) Stu Ungar – Named after the poker legend and Hall of Famer. Stuey won three WSOP Main Event titles and used A-4 to win his final championship in 1997 after. P(ace, 2,3,4,5) = BUT—this only gives you the probability of this one particular sequence of drawing the cards. You would also get a straight if you drew these cards in any other order.
Simply Scheme:Introducing Computer Science 2/e Copyright (C) 1999 MIT
|
The idea of this project is to invent a procedure poker-value
that works like this:
As you can see, we are representing cards and hands just as in theBridge project, except that poker hands have only fivecards.[1]
Here are the various kinds of poker hands, in decreasing order of value:
• | Royal flush: ten, jack, queen, king, and ace, all of the same suit |
---|
• | Straight flush: five cards of sequential rank, all of the same suit |
---|
• | Four of a kind: four cards of the same rank |
---|
• | Full house: three cards of the same rank, and two of a second rank |
---|
• | Flush: five cards of the same suit, not sequential rank |
---|
• | Straight: five cards of sequential rank, not all of the same suit |
---|
• | Three of a kind: three cards of the same rank, no other matches |
---|
• | Two pair: two pairs of cards, of two different ranks |
---|
• | Pair: two cards of the same rank, no other matches |
---|
• | Nothing: none of the above |
---|
An ace can be the lowest card of a straight (ace, 2, 3, 4, 5) orthe highest card of a straight (ten, jack, queen, king, ace), but a straightcan't 'wrap around'; a hand with queen, king, ace, 2, 3 would be worthless(unless it's a flush).
Notice that most of the hand categories are either entirely about the ranksof the cards (pairs, straight, full house, etc.) or entirely about thesuits (flush). It's a good idea to begin your program by separating therank information and the suit information. To check for a straight flush orroyal flush, you'll have to consider both kinds of information.
In what form do you want the suit information? Really, all you need is atrue or false value indicating whether or not the hand is a flush, becausethere aren't any poker categories like 'three of one suit and two ofanother.'
What about ranks? There are two kinds of hand categories involving ranks: the ones about equal ranks (pairs, full house) and the ones about sequentialranks (straight). You might therefore want the rank information in twoforms. A sentence containing all of the ranks in the hand, in sorted order,will make it easier to find a straight. (You still have to be careful aboutaces.)
For the equal-rank categories, what you want is some data structure thatwill let you ask questions like 'are there three cards of the same rankin this hand?' We ended up using a representation like this:
One slightly tricky aspect of this solution is that we spelledout the numbers of cards, one
to four
, instead of using the moreobvious (1 Q 2 3 2 4)
. The reason, as you can probably tell just bylooking at the latter version, is that it would lead to confusion betweenthe names of the ranks, most of which are digits, and the numbers ofoccurrences, which are also digits. More specifically, by spelling out thenumbers of occurrences, we can use member?
to ask easily if there isa three-of-a-kind rank in the hand.
You may find it easier to begin by writing a version that returns only thename of a category, such as three of a kind
, and only after you getthat to work, revise it to give more specific results such as threesixes
.
In some versions of poker, each player gets seven cards and can choose anyfive of the seven to make a hand. How would it change your program if theargument were a sentence of seven cards? (For example, in five-card pokerthere is only one possible category for a hand, but in seven-card you haveto pick the best category that can be made from your cards.) Fix yourprogram so that it works for both five-card and seven-card hands.
Another possible modification to the program is to allow for playing with'wild' cards. If you play with 'threes wild,' it means that if there isa three in your hand you're allowed to pretend it's whatever card you like.For this modification, your program will require a second argument indicatingwhich cards are wild. (When you play with wild cards, there's thepossibility of having five of a kind. This beats a straight flush.)
[1] Later on we'll think about seven-card variants of poker.BACKchapter thread NEXT
Brian Harvey,bh@cs.berkeley.edu
The most fundamental of poker concern the hand rankings, because the hand rankings determine the winner. While betting is extremely important to the game, players are wagering on whether they have won, therefore a complete understanding of hand rankings must come first. These hand rankings do not apply to games played 'low', such as lowball or razz; see the section on 'low hands' below.
The cards are ranked thus, from low to high: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace. An ace is the highest card, but it can also function as the lowest in completing a straight. The two is usually called a 'deuce', and the three is sometimes called a 'trey'. Ten, Jack, Queen, King, and Ace are often abbreviated T, J, Q, K, and A, respectively, so that each card name has a single number or letter associated with it. This is commonly used in describing hands, for example, A-2-3-4-5 is a hand with an ace, a two ('deuce'), a three, a four, and a five — not necessarily in that order, but presenting them in that order makes it clear that the hand is a straight. A hand may also be written, say, A-A-x-x-x, where 'x' means any other card that does not form a better hand.
Rank name | Also called | Cards needed | Example | Names for example |
---|---|---|---|---|
High card | No pair, nothing | (Anything) | A-x-x-x-x | Ace high |
Pair | Two cards of same rank | A-A-x-x-x | Aces; pair of aces | |
Two pair | Two pairs | A-A-K-K-x | Aces up; aces and kings; aces over kings | |
Three of a kind | Trips, a set | Three cards of same rank | A-A-A-x-x | Three aces; set of aces |
Straight | Five cards in sequence | 10-J-Q-K-A | Ace-high straight | |
Flush | All five cards same suit | A♣10♣7♣6♣4♣ | Ace-high flush | |
Full house | Boat, full boat | Three of a kind plus a pair | A-A-A-K-K | Aces full; aces full of kings |
Four of a kind | Quads | Four cards of same rank | A-A-A-A-x | Quad aces; four aces |
Straight flush | Five cards forming straight and a flush | 210♠J♠Q♠K♠A♠ | Ace-high straight flush (Also called a Royal Flush) |
A-2-3-4-5 is considered a five-high straight, and it is called a wheel or bicycle; this is the only time an ace plays as a low card. An ace-high straight flush is called a royal flush and it cannot be beaten. The only time it ties is when all 5 cards to the royal flush, i.e. A♥K♥Q♥J♥10♥, are on the community board. Higher cards always beat lower cards, for example, a pair of aces beats a pair of kings, and a flush with a king beats a flush whose highest card is a Queen. If two players have the same pair, a kicker is used to break the tie if possible (more about them soon). When two players have two pair, the highest pairs are considered, for example, aces up always beats kings up, no matter the other pairs. If, for example, two players both have aces up, then the higher of the smaller pairs wins: aces over kings beats aces over queens. If, for example, both players have aces over kings, then the kicker card is considered. Kickers also come into play when more than one player has the same three or four of a kind (possible only in community card games or wildcard games). If players have the same straight, flush, full house, or straight flush, it is always a tie and the players split the pot. There is no suit superiority or trump suit; a spade flush with A-10-9-6-4 does not beat a club flush with the same values.
A kicker is any card that you hold in your hand that does not make part of it, that is, an otherwise useless card. A hand can have more than one kicker; A pair for instance has three kickers and a three-of-a-kind has two, and they are considered in rank order highest-first. When two players hold the same pair, two pair, three of a kind, or four of a kind, the highest kicker wins, for example, A-A-K-x-x beats A-A-Q-x-x, A-A-K-Q-x beats A-A-K-J-x, and A-A-K-Q-J beats A-A-K-Q-T. A kicker can be higher than the rest of the hand, for example, K-K-A-x-x beats K-K-J-x-x, so an ace usually makes the best kicker. If the first kicker ties and there is a second or third, they are compared in rank order; A-A-K-J-x loses to A-A-K-Q-x. If the hands are totally equivalent, the pot is split.
Some games have a high-low split, and some games such as lowball or razz are played low-only. In a high-low split game, typically a low hand must not have any cards ranked higher than eight and no cards must be paired, or it does not count as a low hand. In low-only games, any cards can be used. Many forms of poker do not use low hands, so you need not concern yourself with these until you intend to play games that do.
There are three common ways of ranking low hands, ace-to-five low, ace-to-six low, and deuce-to-seven low, named after the best possible hands in the respective systems. In all systems, paired cards are bad and cannot be used to beat any hand that does not have a pair. Likewise, a pair beats three of a kind, three of a kind beats a full house, and a full house beats four of a kind. The most common hand ranking system for low hands is ace-to-five, used almost universally in high-low split games and very common in other games. This means A-2-3-4-5 (called a wheel or bicycle, just as it is as a high hand) is the best possible low hand, and the ace is the lowest card. For a high-low split game, it also forms a high hand: a five-high straight. In order to avoid confusion, we will discuss only ace-to-five low at the moment.
When pairs and any other 'bad' hands are not present, then the winner is the one whose highest card is lowest. For this reason, a low hand is usually described highest card first, to make it easier to tell which is lower. In ace-to-five, 8-4-3-2-A loses to 7-6-5-4-3 because the highest card in the first hand (eight) is higher than the highest card in the second hand (seven), even though all the other cards in the second hand are lower. If the highest cards are the same, then the next-highest cards are considered, and so on: 8-7-6-3-A loses to 8-7-5-4-2 because the second hand goes lower first.
In ace-to-six low, straights and flushes count for high (that is, they're bad), and the best possible hand is A-2-3-4-6 unsuited, since it's the lowest possible card combination that avoids pairing, straights, and flushes. Deuce-to-seven is identical except the ace is the highest card, so the best possible hand is 2-3-4-5-7 unsuited. Therefore, in deuce-to-seven low, the hand that would make the worst possible high hand in traditional poker is the best possible low hand, and vice versa: a royal flush is the worst possible hand.