Poker,detect different hands;help!!!
Fajlajp
Member Posts: 666
Hi everybody:)
I'm designing a poker gam at the moment. I'e sucessufully managed to deal the cards,shuffle the cards. Raise,bet,call,fold etc. But I've got stucked at one stage. How to detect diiferent hands like par,two pairs,full house,flush,straight etc.
//Fajlajp
I'm designing a poker gam at the moment. I'e sucessufully managed to deal the cards,shuffle the cards. Raise,bet,call,fold etc. But I've got stucked at one stage. How to detect diiferent hands like par,two pairs,full house,flush,straight etc.
//Fajlajp
Comments
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
I got a tip of tatiang saying this.
"Each time a card is dealt, update a table cell with the value of the card. You could use two table cells (suit + number) but there's probably a better way to do it, especially if you can take advantage of the new string evaluation behaviors (e.g. first letter of word) in the nightly builds. Then have an algorithm that loops through the "hand" (table cells) and figures out what the hand is. If you see the same number (e.g. 4 of diamonds and 4 of hearts), it's a pair. If all five "cards" have the same suit, it's a flush."
But I don´t know how to check the numbers and suit. Is it possible and how?
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
- There are 40 possible straight flushes, including the 4 royal flushes
- There are 624 possible hands including four of a kind
- There are 3,744 possible full houses
- There are 5,148 possible flushes, of which 40 are also straight flushes
- There are 54,912 possible three of a kind hands that are not also full houses or four of a kind
- There are 123,552 possible two pair hands that are not also three of a kind hands or higher hands
- There are 1,098,240 possible one pair hands
So its a given you need to make a dynamic system that can calculate these out comes as you play.
You need to have atleast 3 values to check from
Card type (spades,hearts,diamonds,clover)
Card Value (1,2,3,4,5,6,7,8,9,10,11,12,13)
Combined hand value.
Then you need to plot down the rules of each possible hand
You need to combine those values and reference it to the cards dealt onto the table.
And then have and Global attribute looking at the combined highest value.
But making a poker game without understanding poker is even more challenging.
But as @fryingBaconStudios said. Its more then a big task to make this happen with Gamesalad.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
I think I've came up with a solution thanks to tatiang,socks and fryingbaconstudios. But thank you for helping me out.
Ps. How did you get 1.098.240 possible one hand pairs. That's not possible.
There are 13 choices for the rank of the pair, and 6 choices for a pair of the chosen rank. There are 220 choices for the ranks of the other 3 cards and 4 choices for each of these 3 cards. We have 13 x 6 x 220 x 4^3 = 1.098.240 hands with a pair.
Do you have a link to his game?
Cool idea!
- Thomas
http://gamesalad.com/blog/gamesalad-debuts-games-and-publishing-arm-ice-cap-games
Do you know any from this forum that has been involved making the poker app.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@wingmanapps and @FryingBaconStudios are correct in that this would be a daunting, if not near impossible task to accomplish if one attempts to create rules for 1,098,240 possible one pair hands.
While the above poker math is certainly true, it seems to me that folks may be, understandably, overthinking this somewhat.
Having said that, I make this post knowing that I may either be doing this exact same thing, or, on the flip side, not thinking through the problem nearly enough.
(So, side note: feel free to completely blast me if this post makes no sense whatsoever. It's just stream of consciousness, and even if it was the sum total of my very limited brain power, I can still take it.)
While I am working on the art design for this particular project with Fajlajp, I am certainly a novice with GameSalad, so take this idea for whatever it's worth. However, it seems to me that the easiest way to work around this problem is to assign numerical values to each of the card rankings and not worry about trying to program rules for every single card combination - which is obviously in the million plus range.
Before I explain, I should preface my idea by noting that a poker hand has the same hand ranking regardless of the order in which it is arranged by the deal, by a description, or by a picture. So a hand arranged as:
10s 8d 10d 6c 10c -- is ranked the same as-- 10c 10d 10s 8d 6c,
even though in the first hand the three of a kind is not immediately obvious.
Additionally, in terms of starting hands, there are only 169 different combinations, if you assume for example, Qh Qd is the same as Qc Qs - treating all suites as equal in numerical rank.
Having said that, I would think that it's possible to use something like the so-called "Bill Chen Formula," which he writes about in "The Mathematics of Poker."
Developed by Bill Chen, a two-time WSOP bracelet winner (at the time of it's development), and founder of billchenpoker.com, he basically developed a mathematical formula to determine if a starting hand is playable by assigning the cards certain numerical values. I think that this idea can be easily converted to GameSalad's logic, to not only use for basic rules programming, but to also create some sort of rudimentary, if not totally easy to beat A.I (see bottom of post).
Briefly described, the key to Chen's formula is determining one's highest card and scoring it as follows, using the lower card for gap and suited analysis.
Ace = 10 points
King = 8 points
Queen = 7 points
Jack = 6 points
10 through 2 = half of face value (i.e. 10 = 5, 9 = 4.5)
Pairs, multiply score by 2 (i.e. KK = 16), minimum score for a pair is 5 (so pairs of 2 through 4 get a 5 score)
Suited cards, add two points to highest card score
Connectors add 1 point (i.e. KQ)
One gap, subtract 1 point (i.e. T8)
Two gap, subtract 2 points (i.e. AJ)
Three gap, subtract 4 points (i.e. J7)
Four or more gap, subtract 5 points (i.e. A4)
Sample scores
AA = 20 points
98suited = 7.5 points
K9suited = 6 points
Of course, I'm just throwing stuff against the wall here, but it seems to me that using either tables, or assigning an invisible actor with a numerical value to each card, as well as an additional modifier for each suit, such as HEARTS = A, DIAMONDS = B, CLUBS = C, SPADES = D, would make determining the winner of a hand much easier.
*EDIT - The next logical step would be to apply this same principle to the community cards as well, to determine an overall mathematical score.
As @wingmanapps said:
"You need to have at least 3 values to check from:
Card type (spades,hearts,diamonds,clover (sic))
Card Value (1,2,3,4,5,6,7,8,9,10,11,12,13)
Combined hand value"*
With seven possible cards total in Texas Hold-em, the math should be fairly easy.
Ah Ac vs Ks Kh = 10 + 10 (20) vs 8 + 8 (16) would be the clear winner mathematically pre-flop, however on this particular board ...
9s 10s Ad / 2s / Qs ...
The Cowboy hand (K K) takes the pot with 5 spades, or 5 cards with the suit modifier "D" (for spades as described above). *EDIT: On a board with no possible flush, the numerical math would determine the winner.
This idea needs to be fleshed out more of course, because there situations where a bit more creative thinking may be needed. Such as, if the board is:
7s 8s Ac 9s 7h,
a player holding 5s 6s has the nut hand, a 9-high straight flush of spades, this player cannot lose, even though another player maybe holding an Ace high flush - the As Ks, which is numerically higher in the above formula. So, there needs to be an additional (I'm a calling it) "Modifier" for situations such as straight flushes.
On the same board, the hand 7c 7d would be the second-nut hand, four of a kind sevens; the third-nut hand would be any pair of the remaining three aces, making a full house, aces full of sevens.
That being said, in situations where two or more players hold non-straight (or Royal) flushes and higher than Wheel/Bicycle (A-5) straights, the highest numerical "kicker" card, whether it be an A, K, Q, etc. would take the pot. The same would go in situations where two or more players hold full houses, sets or two pairs. The cards with the highest value, i.e. 3 Aces vs 3 Kings, or Queens over 10s, vs Jacks over 10s, would be the winner.
There may need to be a special rule set for situations where one player has an A-5 straight, so that it will always lose to players with straights 2-6 or higher.
In terms of programming an A.I., the information below (though not strictly from the Chen formula) can be used as a general rule of thumb to determine when an A.I. might come in for a raise. This can be used a staring point for determining player styles using a combination of Loose/Tight, Passive/Aggressive. I personally use Wilson Turbo Software, which uses a system based on this, and I believe it to be the best Poker A.I. currently available. (Although, it does occur to me that I haven't researched similar new products in quite some time.) For general poker knowledge, these numbers are worth mentioning, as they are often seen in conjunction with the Chen formula in many places around the web.
Early Position
Raise = Score is 9 or higher
Call = Score is 8 or higher
Fold = Score is lower than 8
Middle Position
Raise = Score is 9 or higher
Call = Score is 7 or higher
Fold = Score is lower than 7
Late Position
Raise = Score is 9 or higher
Call = Score is 6 or higher
Fold = Score is lower than 6
This was very interesting. But I think I have come I solution.
And great to hear about the art
Like this post if you would want this template.
That would be great!!! It would help me a lot.
(check your inbox)
Everybody: Like CodeMonkey´s post so we get a poker logic template.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS